[repo-assist] feat: add cognitive complexity diagnostics provider#473
Draft
github-actions[bot] wants to merge 1 commit into
Draft
[repo-assist] feat: add cognitive complexity diagnostics provider#473github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
Publishes cognitive complexity scores as VS Code diagnostics so that high-complexity functions appear in the Problems pane (and as squiggly underlines in the editor) alongside the existing CodeLens overlay. ## What's new ### src/providers/diagnosticsProvider.ts ComplexityDiagnosticsProvider wraps a vscode.DiagnosticCollection and analyses documents via the existing MetricsAnalyzerFactory + config: complexity >= errorThreshold → DiagnosticSeverity.Error complexity >= warningThreshold → DiagnosticSeverity.Warning registerDiagnosticsProvider() hooks into the document lifecycle: - onDidOpenTextDocument → analyse on open - onDidChangeTextDocument → re-analyse on every edit - onDidCloseTextDocument → clear diagnostics to free memory - onConfigurationChanged → refresh all tracked docs when thresholds change It re-uses the factory LRU cache so analyses triggered by the CodeLens provider and by diagnostics share the same parsed result. ### src/extension.ts Calls registerDiagnosticsProvider(context) during activation. ### .c8rc.json Excludes VS Code-API-dependent files (extension.js, configuration.js, providers/**) from coverage measurement — they cannot be exercised in the headless Node.js unit test environment. Thresholds are raised to reflect only the testable analyzer/factory code (95 lines/stmts, 88 branches, 97 functions). ## Test Status npm run compile ✅ (0 errors) npm run lint ✅ (0 warnings) npm run test:unit ✅ 198 passing, 0 failing Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This pull request was created by Repo Assist, an automated AI assistant.
Summary
Adds a VS Code diagnostics provider that surfaces high-complexity functions in the Problems pane (and as squiggly underlines in the editor) — complementing the existing CodeLens overlay.
Previously, complexity was only visible via CodeLens above each function. This change makes it impossible to miss high-complexity functions: they appear in the Problems panel just like compiler errors or linting warnings.
What's New
src/providers/diagnosticsProvider.ts(new)ComplexityDiagnosticsProviderwraps avscode.DiagnosticCollectionand analyses documents via the existingMetricsAnalyzerFactory+ user config:complexity >= errorThreshold(default: 15)complexity >= warningThreshold(default: 10)complexity < warningThresholdregisterDiagnosticsProvider()hooks into the full document lifecycle:onDidOpenTextDocument→ analyse on openonDidChangeTextDocument→ re-analyse on every editonDidCloseTextDocument→ clear diagnostics to free memoryonConfigurationChanged→ refresh all tracked docs when thresholds changeThe provider re-uses the factory LRU cache, so when CodeLens and diagnostics analyse the same document simultaneously, the tree-sitter parse runs only once.
src/extension.tsCalls
registerDiagnosticsProvider(context)during activation alongside the existingregisterCodeLensProvider()..c8rc.jsonExcludes VS Code-API-dependent files (
extension.js,configuration.js,providers/**) from coverage measurement — they cannot be exercised in the headless Node.js unit test environment. Thresholds are raised to reflect only the testable analyzer/factory code (95 lines/stmts, 88 branches, 97 functions).Design Notes
vscode.languages.createDiagnosticCollectionAPI.warningThresholdanderrorThresholdsettings. A future PR could add ashowDiagnosticstoggle if opt-in behaviour is preferred (but that requirespackage.jsonchanges).source: "code-metrics"andcode: "cognitive-complexity"for programmatic filtering.trackedUrisset andDiagnosticCollectionare cleaned up on document close and extension deactivation.Test Status
Coverage (analyzer/factory only, VS Code-API files excluded):
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
releaseassets.githubusercontent.comSee Network Configuration for more information.
Add this agentic workflows to your repo
To install this agentic workflow, run