Skip to content

perf: check cancellation token before analysis and clarify code#354

Open
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/improve-perf-and-clarity-20260601-a783ac406f21291f
Open

perf: check cancellation token before analysis and clarify code#354
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/improve-perf-and-clarity-20260601-a783ac406f21291f

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented Jun 1, 2026

🤖 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

provideCodeLenses now checks token.isCancellationRequested before 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 before document.getText() / analyzeFile.

Task 5 — Coding improvement: cleaner createCodeLenses and richer details panel

createCodeLenses refactor: Replaced the imperative forEach + push loop with a filter().map().filter() pipeline. The intent — keep only functions with complexity > 0 and produce one CodeLens per function — is now expressed declaratively.

showFunctionDetails improvement: 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 — ✅ passes
  • npm run lint — ✅ passes
  • Unit tests (103 tests) — ✅ all pass
  • VS Code integration tests — ⚠️ require VS Code download (expected in CI sandboxes)

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • releaseassets.githubusercontent.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "releaseassets.githubusercontent.com"

See Network Configuration for more information.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

Add this agentic workflows to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@dcdf09723d42ef9b6c75335e4612fd145d4ccdaa

…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>
@askpt askpt changed the title [repo-assist] perf: check cancellation token before analysis and clarify code perf: check cancellation token before analysis and clarify code Jun 1, 2026
@askpt askpt marked this pull request as ready for review June 1, 2026 09:20
@askpt askpt self-requested a review as a code owner June 1, 2026 09:20
Copilot AI review requested due to automatic review settings June 1, 2026 09:20
@askpt askpt closed this Jun 1, 2026
@askpt askpt reopened this Jun 1, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 1, 2026

Codecov Report

❌ Patch coverage is 0% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.53%. Comparing base (641a453) to head (86432f2).

Files with missing lines Patch % Lines
src/providers/codeLensProvider.ts 0.00% 11 Missing ⚠️
src/extension.ts 0.00% 8 Missing ⚠️
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.
📢 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.

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

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 CancellationToken check in provideCodeLenses to skip analysis work for cancelled CodeLens requests.
  • Refactored createCodeLenses into 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);
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.

2 participants