Add onDidChangeSemanticTokens support to DocumentRangeSemanticTokensProvider#268148
Merged
Add onDidChangeSemanticTokens support to DocumentRangeSemanticTokensProvider#268148
onDidChangeSemanticTokens support to DocumentRangeSemanticTokensProvider#268148Conversation
…rovider Co-authored-by: aeschli <[email protected]>
Co-authored-by: aeschli <[email protected]>
Copilot
AI
changed the title
[WIP]
Add Sep 24, 2025
DocumentRangeSemanticTokensProvider has no support for onDidChangeSemanticTokensonDidChangeSemanticTokens support to DocumentRangeSemanticTokensProvider
aeschli
approved these changes
Sep 29, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds onDidChangeSemanticTokens event support to DocumentRangeSemanticTokensProvider to provide API parity with DocumentSemanticTokensProvider, enabling extensions to notify VS Code when range-specific semantic tokens need refreshing.
Key changes:
- Added optional
onDidChangeevent property to theDocumentRangeSemanticTokensProviderinterface - Updated registration and protocol methods to handle event subscriptions with proper cleanup
- Enhanced main thread provider to accept and forward events across the extension host boundary
Reviewed Changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/vs/editor/common/languages.ts | Added optional onDidChange event property to DocumentRangeSemanticTokensProvider interface |
| src/vs/workbench/api/common/extHost.protocol.ts | Updated protocol methods to support event handles for range semantic tokens |
| src/vs/workbench/api/common/extHostLanguageFeatures.ts | Enhanced registration logic to handle optional event subscriptions and forward events to main thread |
| src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts | Added event emission handling and updated provider constructor to accept event parameter |
| const handle = this._addNewAdapter(new DocumentRangeSemanticTokensAdapter(this._documents, provider), extension); | ||
| this._proxy.$registerDocumentRangeSemanticTokensProvider(handle, this._transformDocumentSelector(selector, extension), legend); | ||
| return this._createDisposable(handle); | ||
| const eventHandle = (typeof provider.onDidChangeSemanticTokens === 'function' ? this._nextHandle() : undefined); |
There was a problem hiding this comment.
The type check should verify if provider.onDidChangeSemanticTokens is an Event object, not a function. Events in VS Code are objects with subscription methods, not functions themselves. Consider checking typeof provider.onDidChangeSemanticTokens !== 'undefined' instead.
mjbvz
approved these changes
Oct 7, 2025
alexr00
approved these changes
Oct 8, 2025
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.
Fixes missing
onDidChangeSemanticTokensevent support inDocumentRangeSemanticTokensProviderto provide API parity withDocumentSemanticTokensProvider.Problem
The
DocumentRangeSemanticTokensProviderinterface lacked theonDidChangeSemanticTokensevent that is available inDocumentSemanticTokensProvider. This prevented extensions from notifying VS Code when range-specific semantic tokens needed to be refreshed, forcing unnecessary re-computation and limiting performance optimizations.This was originally reported against the Language Server Protocol via the C# team (microsoft/vscode-languageserver-node#1672).
Solution
Added optional
onDidChangeSemanticTokens?: Event<void>property toDocumentRangeSemanticTokensProviderfollowing the same pattern as the document provider:Implementation
onDidChangeevent property to maintain backward compatibilityMainThreadDocumentRangeSemanticTokensProviderto accept and handle event emitters$emitDocumentRangeSemanticTokensEventmethod for cross-process communicationUsage
Extensions can now implement event-driven semantic token refreshing:
Testing
Added comprehensive tests verifying both scenarios:
onDidChangeSemanticTokensevent work correctlyThe changes are fully backward compatible - existing range semantic token providers continue to work unchanged, while new providers can opt into event-driven refreshing for better performance.
Fixes #268140
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.