perf: check cancellation token before analysis and clarify code#354
Open
github-actions[bot] wants to merge 1 commit into
Open
perf: check cancellation token before analysis and clarify code#354github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
…nses Task 8 - Performance: - Add token.isCancellationRequested check in provideCodeLenses before the potentially expensive tree-sitter parse. When VS Code cancels a request (e.g. the user typed another character), the analysis is skipped entirely rather than completing and having VS Code discard the result. Task 5 - Coding improvements: - Refactor createCodeLenses to use filter().map().filter() pipeline instead of imperative forEach+push, making the intent clearer. - showFunctionDetails in extension.ts now shows the complexity status level (e.g. '🔴 High Complexity') alongside the numeric score, giving users immediate context without needing to know the configured thresholds. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #354 +/- ##
==========================================
- Coverage 74.57% 74.53% -0.04%
==========================================
Files 13 13
Lines 4086 4088 +2
Branches 434 434
==========================================
Hits 3047 3047
- Misses 1037 1039 +2
Partials 2 2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes the VS Code CodeLens provider to reduce wasted work on cancelled requests and improves the function details output to show the complexity severity (icon + label) alongside the numeric score.
Changes:
- Added an early
CancellationTokencheck inprovideCodeLensesto skip analysis work for cancelled CodeLens requests. - Refactored
createCodeLensesinto a more declarative pipeline. - Enhanced the details output panel to include complexity status (icon + label) derived from current configuration.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/providers/codeLensProvider.ts |
Adds early cancellation guard and refactors CodeLens creation logic. |
src/extension.ts |
Enriches the output channel details view with complexity status derived from config. |
Comment on lines
+149
to
153
| } | ||
|
|
||
| try { | ||
| const analysisKey = `${document.uri.toString()}#${document.languageId}#${document.version}`; | ||
| let functions = this.analysisCache.get(analysisKey); |
Comment on lines
+213
to
+216
| return functions | ||
| .filter((func) => func.complexity > 0) | ||
| .map((func) => this.createCodeLens(func, document, config)) | ||
| .filter((lens): lens is vscode.CodeLens => lens !== undefined); |
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 PR was created by Repo Assist, an automated AI assistant.
Summary
Two targeted improvements: a performance optimisation (Task 8) and a code clarity improvement (Task 5).
Changes
Task 8 — Performance: early cancellation check
provideCodeLensesnow checkstoken.isCancellationRequestedbefore performing the tree-sitter parse. VS Code issues a new CodeLens request every time the document changes; without this guard, an in-flight analysis whose result will be discarded runs to completion unnecessarily. For large files (thousands of lines), this avoids measurable wasted CPU on every keystroke.Location:
src/providers/codeLensProvider.ts, after the exclusion check and beforedocument.getText()/analyzeFile.Task 5 — Coding improvement: cleaner
createCodeLensesand richer details panelcreateCodeLensesrefactor: Replaced the imperativeforEach+pushloop with afilter().map().filter()pipeline. The intent — keep only functions with complexity > 0 and produce one CodeLens per function — is now expressed declaratively.showFunctionDetailsimprovement: The output panel now shows the complexity status icon and label alongside the score (e.g.Cognitive Complexity: 18 🔴 High Complexity), so users see the severity immediately without needing to know the configured thresholds.Test Status
npm run compile— ✅ passesnpm run lint— ✅ passesWarning
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