Files
Shuhei Kadowaki cb593458e1 project: Match document filter patterns in dynamic registrations (#65252)
## Summary

Follow-up to #59243, which made dynamically registered capabilities
honor the `language` and `scheme` of their document selectors, but left
`pattern` matching fail-open. A registration such as `{ "language":
"toml", "pattern": "**/Project.toml" }` therefore still applied to every
TOML document the server had opened, and a pattern-only filter applied
to every document.

This matches `pattern` against the document's path:

- String patterns are matched against the absolute path. As in the LSP
glob syntax, `*` and `?` do not match path separators.
- Relative patterns are matched against the path relative to their base
URI, and Zed now advertises the
`textDocument.filters.relativePatternSupport` client capability.
- Documents without a file system path never match a `pattern` filter.
Contexts that stand for a whole language, like the semantic token legend
lookup, and guest buffers whose path is unknown keep not evaluating
patterns.
- Registrations whose patterns are not valid globs are rejected when
they are registered.

LSP 3.18 changed `TextDocumentFilter.pattern` from a string to a
`GlobPattern`, so that it can also be a relative pattern. ~~This PR
depends on zed-industries/lsp-types#16, which updates the type and adds
the client capability. I'd like to merge this together with that
upstream change: `Cargo.toml` currently points at the commit of
zed-industries/lsp-types#16 on my fork, and I will switch it to the
`zed-industries/lsp-types` revision once that PR is merged.~~

**Update:** zed-industries/lsp-types#16 has been merged, and
`Cargo.toml` now points at its `zed-industries/lsp-types` revision
(zed-industries/lsp-types@82d7fc66eb).

## Testing

- Added unit tests for matching string patterns, wildcards across path
separators, and relative patterns.
- Added an integration test that a pattern-scoped completion
registration only applies to matching buffers, and that a registration
with an invalid pattern is rejected.
- Updated
`test_dynamic_formatting_registration_with_pattern_only_selector`, which
asserted the fail-open behavior left by #59243.

## Self-review

- [x] I've reviewed my diff for quality, security, reliability, and
performance.
- [x] UI changes follow the
[checklist](https://zed.dev/docs/development/ui-checklist).
- [x] Tests cover the new or changed behavior.

Release Notes:

- Fixed language servers' dynamically registered capabilities applying
to files outside of the `pattern` of their document selector.

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 17:41:09 +00:00
..