Language Extensions
Language extensions add support for programming languages in Zed. A complete language extension includes:- Language metadata: File extensions, comment syntax, indentation
- Tree-sitter grammar: Syntax parsing
- Tree-sitter queries: Highlighting, brackets, outline, indentation
- Language server: IDE features (autocomplete, diagnostics, go-to-definition)
Language Metadata
Each language requires a configuration directory underlanguages/ in your extension:
config.toml
Theconfig.toml file defines language properties:
name: Human-readable name shown in the language selectorgrammar: Name of the Tree-sitter grammar (defined inextension.toml)
path_suffixes: File extensions (without dots). Use settings for glob patternsline_comments: Array of line comment prefixesblock_comment: Start and end strings for block commentsstart: Opening delimiterend: Closing delimiterprefix: Prefix for middle lines (optional)tab_size: Additional indentation for middle lines
tab_size: Spaces per indentation level (default: 4)hard_tabs: Use tab characters instead of spaces (default: false)first_line_pattern: Regex to match files by first line (e.g., shebangs)brackets: Custom bracket pairs (for auto-closing)debuggers: Array of debug adapter names (for launch UI ordering)
Tree-sitter Grammar
Tree-sitter provides fast, incremental parsing. Register grammars inextension.toml:
repository: Git repository URL (HTTPS orfile://for local development)commit(orrev): Git commit SHA to usepath: Subdirectory if grammar is not at repository root (optional)
[grammars.name] sections.
Tree-sitter Queries
Tree-sitter queries enable language features by matching patterns in the syntax tree. All queries use Tree-sitter query syntax.Syntax Highlighting (highlights.scm)
Thehighlights.scm file defines syntax highlighting rules.
Example:
| Capture | Usage |
|---|---|
@attribute | Attributes and decorators |
@boolean | Boolean literals |
@comment | Comments |
@comment.doc | Documentation comments |
@constant | Constants |
@constant.builtin | Built-in constants |
@constructor | Constructor calls |
@embedded | Embedded code |
@emphasis | Italic text |
@emphasis.strong | Bold text |
@enum | Enum names |
@function | Function names and calls |
@keyword | Language keywords |
@label | Labels and symbols |
@link_uri | URLs |
@number | Numeric literals |
@operator | Operators |
@property | Object properties and fields |
@punctuation | General punctuation |
@punctuation.bracket | Brackets: (), [], {} |
@punctuation.delimiter | Delimiters: ,, ;, : |
@string | String literals |
@string.escape | Escape sequences |
@string.regex | Regular expressions |
@string.special | Special string types |
@tag | XML/HTML tags |
@title | Headings and titles |
@type | Type names |
@type.builtin | Built-in types |
@variable | Variables |
@variable.special | Special variables (e.g., self, this) |
@variable.parameter | Function parameters |
Bracket Matching (brackets.scm)
Thebrackets.scm file defines matching bracket pairs.
Example:
- Rainbow bracket coloring (each nested pair gets a different color)
- Highlighting matching brackets when cursor is between them
- Bracket-aware navigation
Code Outline (outline.scm)
Theoutline.scm file defines the document outline structure.
Example:
@name: The symbol name (shown in outline)@item: The entire declaration (for navigation)@context: Additional context for the item@context.extra: Secondary context information@annotation: Decorators, doc comments (used by AI for code generation)
Auto-indentation (indents.scm)
Theindents.scm file defines indentation rules.
Example:
@indent: Increase indentation for content inside@outdent: Decrease indentation@end: Mark the closing bracket for proper alignment
Code Injections (injections.scm)
Theinjections.scm file enables embedded languages (e.g., SQL in Python strings).
Example: Markdown with code blocks
@injection.language: Language identifier for the embedded content@injection.content: The embedded code to parse
Syntax Overrides (overrides.scm)
Theoverrides.scm file defines scopes where editor settings change.
Example: Different word characters in strings
config.toml:
-.
Runnables (runnables.scm)
Therunnables.scm file marks code that can be executed (e.g., unit tests).
Example:
Language Server
Language servers provide IDE features via the Language Server Protocol.Declaring Language Servers
Register language servers inextension.toml:
Providing Language Server Command
Implement thelanguage_server_command method:
Downloading Language Servers
From GitHub Releases:Language Server Configuration
Initialization Options:settings.json:
