Skip to content

Add eslint rule for ServicesAccessor after await#307263

Merged
roblourens merged 1 commit into
mainfrom
roblou/embarrassing-bonobo
Apr 1, 2026
Merged

Add eslint rule for ServicesAccessor after await#307263
roblourens merged 1 commit into
mainfrom
roblou/embarrassing-bonobo

Conversation

@roblourens
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings April 1, 2026 21:25
@roblourens roblourens enabled auto-merge (squash) April 1, 2026 21:25
@roblourens roblourens self-assigned this Apr 1, 2026
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

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) in eslint.config.js.
  • Introduce .eslint-plugin-local/code-no-accessor-after-await.ts to detect invalid accessor usage after await (including within invokeFunction callbacks and ServicesAccessor-typed functions).
  • Update a few workbench/chat/search call sites to avoid using ServicesAccessor after 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, sawAwait is reset to beforeTry before walking the catch block. This means accessor usage inside catch won’t be flagged even when the try block contains an await before 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

  • walkChildren doesn’t traverse VariableDeclarator.id patterns (only decl.init). This will miss accessor usages that appear in destructuring patterns (e.g. default values inside object/array patterns) after an await, reducing the effectiveness of the rule. Consider visiting decl.id as well and handling pattern node types as needed.
		case 'VariableDeclaration':
			node.declarations.forEach(decl => {
				if (decl.init) { visit(decl.init); }
			});
			break;

Comment thread .eslint-plugin-local/code-no-accessor-after-await.ts
@roblourens roblourens merged commit 3f2c82d into main Apr 1, 2026
23 checks passed
@roblourens roblourens deleted the roblou/embarrassing-bonobo branch April 1, 2026 22:02
@vs-code-engineering vs-code-engineering Bot added this to the 1.115.0 milestone Apr 1, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators May 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants