refactor: pass resolved config into createCodeLens to avoid redundant getConfiguration calls#285
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
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>
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.