Skip to main content

Language capabilities

Every language goes through the same contract, whether built in or contributed by an extension. Nothing in the editor is specific to Rust or TypeScript.

Identification​

The LanguageRegistry maps exact file names and extensions to a LanguageDefinition:

FieldMeaning
id, namee.g. rust, "Rust"
extensions, file_namese.g. rs; Cargo.lock
grammarBuilt-in Tree-sitter grammar, if any
serverLanguage server command, if any
sourceBuilt-in or the contributing extension

Detection looks only at the path, never at contents, and falls back to plain text. Registrations that would steal an existing extension or id are rejected, so an extension cannot silently take over .rs.

Built in: Rust (rs), TypeScript (ts, mts, cts), TypeScript JSX (tsx), JavaScript (js, mjs, cjs, jsx) and plain text.

The capability contract​

enum Capability { SyntaxHighlighting, Diagnostics, Completion, Hover, Definition,
References, Rename, Formatting, CodeActions }
enum ProviderKind { Syntax, Semantic }

DocumentCapabilities lists what a document can do right now, split by provider kind. Syntax providers are in process and fast; semantic providers are language servers, gated by trust and profile. When both offer a capability, the semantic provider wins. The status bar shows both separately.

CapabilityMVP status
Syntax highlightingImplemented (Tree-sitter)
DiagnosticsImplemented (LSP)
Go to definitionImplemented (LSP)
Completion, hover, references, rename, formatting, code actionsReported when a server advertises them; no UI yet

Syntax analysis​

  • Grammars are compiled into the binary. A grammar's highlight query is compiled the first time a file of that language opens, then cached.
  • Each document owns a syntax tree. Edits are applied with Tree::edit and the document is re-parsed incrementally, reading straight from the rope.
  • Highlights are queried only for the byte range being drawn and reduced to non-overlapping spans of theme-independent classes (keyword, function, type, string, …). Themes map classes to colours.
  • Limits protect responsiveness and memory; see lazy loading and resources.

Adding a language​

  • Declaratively (no code): an extension can map file extensions to a new language id and reuse a built-in grammar. See extensions.
  • With a new grammar: add the grammar crate to ide-languages, a GrammarId variant and a registry entry. Grammars are C code; review licence and maintenance first.
  • With a language server: set server in the definition and, if needed, allow it in a profile.