refactor: pass resolved config into createCodeLens to avoid redundant getConfiguration calls#285
Merged
askpt merged 2 commits intoMay 12, 2026
Conversation
… getConfiguration calls When rendering CodeLens items for a document with many functions, each call to createCodeLens previously triggered a fresh vscode.workspace.getConfiguration() lookup via getComplexityStatus(complexity, document.uri). The config was already resolved once per document in provideCodeLenses, so the per-function re-fetch was wasteful. Changes: - ConfigurationManager.getComplexityStatus now accepts either a vscode.Uri (existing callers unchanged) or an already-fetched CodeMetricsConfig, avoiding the re-fetch. - createCodeLens now receives the resolved CodeMetricsConfig from createCodeLenses and passes it directly to getComplexityStatus. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ugh-20260505-e3c83a9f55762562
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #285 +/- ##
==========================================
- Coverage 66.34% 66.24% -0.11%
==========================================
Files 9 9
Lines 2600 2604 +4
Branches 224 224
==========================================
Hits 1725 1725
- Misses 874 878 +4
Partials 1 1 ☔ 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 refactors CodeLens rendering to avoid repeated configuration lookups by passing a document-resolved CodeMetricsConfig down into createCodeLens, eliminating per-function vscode.workspace.getConfiguration() calls during provideCodeLenses.
Changes:
- Updated
ConfigurationManager.getComplexityStatusto accept either avscode.Urior an already-resolvedCodeMetricsConfig. - Passed the resolved
CodeMetricsConfigfromprovideCodeLenses→createCodeLenses→createCodeLens, and used it when determining complexity status.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/configuration.ts | Allows getComplexityStatus to reuse a pre-fetched config (or fall back to resolving from a URI). |
| src/providers/codeLensProvider.ts | Threads resolved config through CodeLens creation to avoid redundant configuration fetches per function. |
3 tasks
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
When rendering CodeLens items for a document with many functions,
createCodeLenswas callingConfigurationManager.getComplexityStatus(complexity, document.uri)— which in turn callsvscode.workspace.getConfiguration()— once per function. The configuration was already fully resolved once per document inprovideCodeLenses, making each per-function re-fetch redundant.Changes
src/configuration.tsgetComplexityStatusnow acceptsvscode.Uri | CodeMetricsConfig— existing callers with a URI are unaffected; callers with a pre-fetched config skip the re-fetchsrc/providers/codeLensProvider.tscreateCodeLensnow receives the already-resolvedCodeMetricsConfigfromcreateCodeLensesand passes it directlyRationale
vscode.workspace.getConfiguration()is synchronous but non-trivial — it performs a workspace lookup on every call. For a file with 20 functions all above the threshold, this PR eliminates 20 redundant lookups perprovideCodeLensescall. The improvement is most noticeable on large files or when the user scrolls frequently.The
getComplexityStatussignature change is backward-compatible: the parameter type widens fromvscode.Uri | undefinedtovscode.Uri | CodeMetricsConfig | undefined, and the runtime check (instanceof vscode.Uri) preserves existing behaviour for all current callers.Test Status
npm run compile— no errorsnpm run lint— no warningsnpm test(vscode-test) — requires VS Code download; not available in this sandboxed environment (known infrastructure limitation)Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
releaseassets.githubusercontent.comSee Network Configuration for more information.