Add eslint rule for ServicesAccessor after await#307263
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new repo-wide custom ESLint rule to prevent ServicesAccessor usage after an await, and updates a few call sites to comply with the new rule’s intended pattern (extract services before await / use IInstantiationService.invokeFunction).
Changes:
- Enable
local/code-no-accessor-after-await(warn) ineslint.config.js. - Introduce
.eslint-plugin-local/code-no-accessor-after-await.tsto detect invalid accessor usage afterawait(including withininvokeFunctioncallbacks andServicesAccessor-typed functions). - Update a few workbench/chat/search call sites to avoid using
ServicesAccessorafter async boundaries by pre-fetching services or re-entering an instantiation context.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/contrib/search/browser/searchActionsRemoveReplace.ts | Refactors replace flow to avoid using a ServicesAccessor after awaited operations by using IInstantiationService.invokeFunction. |
| src/vs/workbench/contrib/chat/browser/promptSyntax/pickers/askForPromptSourceFolder.ts | Avoids passing a potentially-invalid ServicesAccessor across async boundaries by invoking the dialog helper via IInstantiationService.invokeFunction. |
| src/vs/workbench/contrib/chat/browser/aiCustomization/aiCustomizationManagement.contribution.ts | Extracts services earlier in run to avoid post-await accessor access. |
| eslint.config.js | Enables the new local lint rule as a warning. |
| .eslint-plugin-local/code-no-accessor-after-await.ts | Adds the new custom rule implementation for detecting accessor usage after await. |
Comments suppressed due to low confidence (2)
.eslint-plugin-local/code-no-accessor-after-await.ts:226
- In the TryStatement handling,
sawAwaitis reset tobeforeTrybefore walking the catch block. This means accessor usage insidecatchwon’t be flagged even when thetryblock contains anawaitbefore the exception is thrown (a reachable path where the accessor is invalidated). Consider propagating the await state into the catch walk (e.g. treat catch as potentially running after any await in the try block) to avoid false negatives.
// Catch: an exception may have been thrown before or after an await
// in the try block, so we conservatively use the before-try state.
sawAwait = beforeTry;
if (node.handler) { walk(node.handler.body); }
.eslint-plugin-local/code-no-accessor-after-await.ts:310
walkChildrendoesn’t traverseVariableDeclarator.idpatterns (onlydecl.init). This will miss accessor usages that appear in destructuring patterns (e.g. default values inside object/array patterns) after anawait, reducing the effectiveness of the rule. Consider visitingdecl.idas well and handling pattern node types as needed.
case 'VariableDeclaration':
node.declarations.forEach(decl => {
if (decl.init) { visit(decl.init); }
});
break;
bhavyaus
approved these changes
Apr 1, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
No description provided.