-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Description
Problem
Zed extensions cannot override tree-sitter grammar query files, forcing grammar maintainers to choose between supporting Zed or other editors like Neovim, which contradicts tree-sitter's goal of unified grammar definitions.
Current Behavior
When an extension specifies a grammar via repository + rev in extension.toml:
- Zed clones the grammar repository
- Zed loads queries only from the cloned grammar's queries/ directory
- Zed completely ignores any query files the extension provides in languages/LANG/*.scm
This means extensions cannot provide editor-specific customizations, even though the extension API suggests they should be able to.
Expected Behavior
Extensions should be able to provide override query files that take precedence over the grammar's defaults.
For example, if an extension provides languages/quarto/highlights.scm, Zed should load that file instead of the grammar's queries/highlights.scm.
Precedence order should be:
- Extension-provided queries (languages/quarto/*.scm)
- Grammar-provided queries (queries/*.scm)
- Grammar-provided editor-specific queries (queries/zed/*.scm)
Real-World Impact
This limitation has concrete consequences:
-
Grammar fragmentation: Grammar authors must create editor-specific forks or branches, defeating the purpose of tree-sitter as a unified parsing solution.
-
Scope incompatibility: Zed themes use legacy scope names (@text.title, @emphasis.strong) while nvim-treesitter uses modern conventions (@markup.heading, @markup.bold). Without extension overrides, grammars must choose one editor to support well.
-
Maintenance burden: Query files must be duplicated across grammar repositories and extension repositories, as noted in discussion ❓ Why does Zed encourage fragmentation of Tree Sitter queries between editors? #16860.
-
Tree-sitter design contradiction: Tree-sitter documentation states "all files needed to highlight a given language are normally included in the same git repository as the Tree-sitter grammar," yet Zed's current architecture encourages the opposite.
Example Case
The zed-quarto-extension needs to use tree-sitter-quarto but cannot because:
- tree-sitter-quarto uses nvim-treesitter scopes (@markup.*) in its default queries/highlights.scm
- Zed themes only recognize legacy scopes (@text.*, @emphasis.strong)
- The extension provides Zed-compatible queries in languages/quarto/highlights.scm
- Zed ignores the extension's queries and loads the grammar's incompatible queries
- Result: No syntax highlighting in Zed
Workaround: Fork the grammar or maintain a separate branch with Zed-specific queries, creating exactly the fragmentation tree-sitter was designed to prevent.
Precedent from Other Editors
- Neovim: Extensions/plugins can override grammar queries using runtime paths
- VSCode: Language extensions can provide custom TextMate grammars
- Helix: Query override via configuration is supported
Related
- Discussion ❓ Why does Zed encourage fragmentation of Tree Sitter queries between editors? #16860: "Why does Zed encourage fragmentation of Tree Sitter queries between editors?"
- This discussion has been unanswered since it was posted
Implementation Notes
One approach could be to check for query files in this order:
- Extension's languages/LANG/highlights.scm
- Grammar's queries/highlights.scm
- Fall back to grammar's queries/zed/highlights.scm if present
This would allow extensions to provide editor-specific customizations while still using upstream grammars, maintaining the tree-sitter philosophy of grammar reuse across editors.