Skip to content

refactor: extract generic createAnalyzer helper and implement showFunctionDetails command#230

Merged
askpt merged 4 commits intomainfrom
repo-assist/improve-factory-and-details-2026-03-30-268744539d5ca523
Apr 1, 2026
Merged

refactor: extract generic createAnalyzer helper and implement showFunctionDetails command#230
askpt merged 4 commits intomainfrom
repo-assist/improve-factory-and-details-2026-03-30-268744539d5ca523

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Mar 30, 2026

Refactors the metrics analyzer factory to reduce per-language duplication and implements the previously no-op cognitiveComplexity.showFunctionDetails command to show a complexity breakdown in a dedicated VS Code output channel.

Changes Made

  • metricsAnalyzerFactory.ts: Replaced per-language analyzer wrapper functions with a generic createAnalyzer(modulePath, className) helper. Added RawMetricsDetail, RawFunctionMetrics, and AnalyzerClass interfaces to replace any types. Added a runtime guard that throws a descriptive error when the expected class or analyzeFile method is not found. Exported createAnalyzer to enable direct unit testing of the guard.
  • extension.ts: Implemented showFunctionDetails command to render function complexity details to a shared "Code Metrics Details" output channel. Fixed misleading empty-details message to "No complexity contributors were reported." Added an early-return guard when func is undefined. Disposes the shared output channel on extension deactivation.

Test Coverage

Added tests to cover previously-uncovered code paths:

  • extension.test.ts: Tests for the table-rendering branch (details.length > 0), output channel reuse when the command is called multiple times, and the deactivate() disposal path.
  • metricsAnalyzerFactory.test.ts: Test for the createAnalyzer runtime error guard, verifying a descriptive error is thrown when a module does not export the expected class.

Testing

  • ✅ TypeScript compilation passes (0 errors)
  • ✅ ESLint passes (0 warnings)
  • ✅ All existing and new tests pass

…ctionDetails

- Replace four near-identical create*Analyzer functions in metricsAnalyzerFactory.ts
  with a single generic createAnalyzer(modulePath, className) helper. All four
  functions shared the same shape: lazy require(), analyzeFile() call, and 0→1
  line/column normalization on detail positions. The helper removes ~140 lines of
  duplication while preserving identical runtime behaviour (Node.js module cache
  ensures the require() overhead is paid only once per language).

- Implement cognitiveComplexity.showFunctionDetails command in extension.ts.
  Previously a no-op, the command now writes a formatted complexity breakdown
  to a dedicated 'Code Metrics Details' output channel and reveals it with
  preserveFocus so the editor cursor stays in place. The channel is created
  lazily and disposed on deactivation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@askpt askpt changed the title [Repo Assist] refactor: extract generic createAnalyzer helper and implement showFunctionDetails command refactor: extract generic createAnalyzer helper and implement showFunctionDetails command Apr 1, 2026
@askpt askpt marked this pull request as ready for review April 1, 2026 15:12
@askpt askpt self-requested a review as a code owner April 1, 2026 15:12
Copilot AI review requested due to automatic review settings April 1, 2026 15:12
@askpt askpt closed this Apr 1, 2026
@askpt askpt reopened this Apr 1, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the metrics analyzer factory to reduce per-language duplication and implements the previously no-op cognitiveComplexity.showFunctionDetails command to show a complexity breakdown in a dedicated VS Code output channel.

Changes:

  • Replaced per-language analyzer wrapper functions with a generic createAnalyzer(modulePath, className) helper.
  • Implemented showFunctionDetails command to render function complexity details to a shared “Code Metrics Details” output channel.
  • Disposed the shared output channel on extension deactivation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/metricsAnalyzer/metricsAnalyzerFactory.ts Consolidates language analyzer creation/normalization into a single helper and updates the language analyzer registry.
src/extension.ts Adds a real showFunctionDetails command implementation, using a shared output channel and disposing it on deactivate.

@askpt
Copy link
Copy Markdown
Owner

askpt commented Apr 1, 2026

@copilot apply changes based on the comments in this thread

…ix empty-details message

Agent-Logs-Url: https://github.com/askpt/code-metrics/sessions/3faebe2a-5bfd-4cf2-b9b2-93fdaa3e8e58

Co-authored-by: askpt <2493377+askpt@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 1, 2026

@copilot apply changes based on the comments in this thread

Applied both review comments in commit 98f4df1:

  1. metricsAnalyzerFactory.ts: Replaced all any types with three minimal shared interfaces (RawMetricsDetail, RawFunctionMetrics, AnalyzerClass) that match the shape returned by all language analyzers. Added a runtime guard that throws a descriptive Error when the expected class or analyzeFile method is not found in the loaded module.

  2. extension.ts: Changed the empty-details message from "No complexity contributors — complexity is 0." to "No complexity contributors were reported." as suggested, since func.complexity can be non-zero even when details is empty.

Copilot finished work on behalf of askpt April 1, 2026 15:26
@askpt
Copy link
Copy Markdown
Owner

askpt commented Apr 1, 2026

@copilot the build is failing. please fix it

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 1, 2026

@copilot the build is failing. please fix it

Fixed in commit 996bd2a. The test should execute cognitiveComplexity.showFunctionDetails command without errors calls the command with no arguments, but showFunctionDetails was immediately accessing func.name causing a TypeError. Added an early-return guard when func is undefined.

Copilot finished work on behalf of askpt April 1, 2026 15:38
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

❌ Patch coverage is 51.72414% with 56 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.45%. Comparing base (76e800d) to head (268b22a).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/extension.ts 0.00% 51 Missing ⚠️
src/metricsAnalyzer/metricsAnalyzerFactory.ts 92.30% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #230      +/-   ##
==========================================
- Coverage   68.50%   67.45%   -1.05%     
==========================================
  Files           8        8              
  Lines        3000     2928      -72     
  Branches      279      276       -3     
==========================================
- Hits         2055     1975      -80     
- Misses        943      951       +8     
  Partials        2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@askpt
Copy link
Copy Markdown
Owner

askpt commented Apr 1, 2026

@copilot Based on #230 (comment) increase the code coverage

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 1, 2026

@copilot Based on #230 (comment) increase the code coverage

Added coverage improvements in commit 268b22a:

  • extension.ts (was 0% patch coverage): 3 new tests cover the previously-untested paths:

    • Table-rendering branch (details.length > 0)
    • Output channel reuse (calling showFunctionDetails twice)
    • deactivate() disposal path (via direct extensionModule.deactivate() call)
  • metricsAnalyzerFactory.ts (5 missing lines): exported createAnalyzer and added a createAnalyzer Runtime Guard test that passes a valid module path with a nonexistent class name, verifying the descriptive error is thrown.

Copilot finished work on behalf of askpt April 1, 2026 15:53
@askpt askpt merged commit 6f507ae into main Apr 1, 2026
22 of 23 checks passed
@askpt askpt deleted the repo-assist/improve-factory-and-details-2026-03-30-268744539d5ca523 branch April 1, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants