lsp: Honor dynamic LSP document selectors#59243
Open
aviatesk wants to merge 1 commit into
Open
Conversation
Previously, Zed ignored the `documentSelector` of a dynamically registered `textDocument` capability and treated every such capability as global to all buffers opened in the server. As a result, Zed could route a request to a server for a document outside the registration's selector -- for example, a URI whose language matches the selector but whose scheme the server never registered for (and is thus unknown to it). I do not think Zed exhibits this in practice today, but it is possible in principle and violates the LSP specification. Track `textDocument` dynamic registrations by method and registration id so Zed can keep each registration's `documentSelector` instead of treating dynamically registered capabilities as global for every open buffer. Use the stored selectors when routing local LSP requests, including single-server requests, multi-server requests, completion-specific routing, capability checks, and range-formatting availability. Static initialize-time capabilities continue to apply to every buffer attached to the server, while dynamically registered `textDocument` features now require a matching selector. The initial matching support covers language and URI scheme, with pattern matching intentionally left fail-open. Update completion trigger management to derive triggers from static capabilities plus matching dynamic completion registrations, and recalculate triggers when completion registrations change. Also make pull diagnostic requests require an advertised diagnostic provider so selector-aware routing can correctly gate dynamic diagnostic registrations. Add an integration test covering dynamic completion registrations whose selectors do and do not match the current file buffer, asserting both request routing and completion trigger updates.
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.
Previously, Zed ignored the
documentSelectorof a dynamically registeredtextDocumentcapability and treated every such capability as global to all buffers opened in the server. As a result, Zed could route a request to a server for a document outside the registration's selector -- for example, a URI whose language matches the selector but whose scheme the server never registered for (and is thus unknown to it). I do not think Zed exhibits this in practice today, but it is possible in principle and violates the LSP specification.Track
textDocumentdynamic registrations by method and registration id so Zed can keep each registration'sdocumentSelectorinstead of treating dynamically registered capabilities as global for every open buffer.Use the stored selectors when routing local LSP requests, including single-server requests, multi-server requests, completion-specific routing, capability checks, and range-formatting availability. Static initialize-time capabilities continue to apply to every buffer attached to the server, while dynamically registered
textDocumentfeatures now require a matching selector. The initial matching support covers language and URI scheme, with pattern matching intentionally left fail-open.Update completion trigger management to derive triggers from static capabilities plus matching dynamic completion registrations, and recalculate triggers when completion registrations change. Also make pull diagnostic requests require an advertised diagnostic provider so selector-aware routing can correctly gate dynamic diagnostic registrations.
Add an integration test covering dynamic completion registrations whose selectors do and do not match the current file buffer, asserting both request routing and completion trigger updates.
Objective
Solution
Testing
Self-Review Checklist:
Showcase
While a showcase should aim to be brief and digestible, you can use a toggleable section to save space on longer showcases:
Click to view showcase
My super cool demos here
Release Notes: