📚 Encyclopedia

Tools & Workflow · updated 2026-11-30

Editor support for your own language as a VS Code extension

vscodeextensiontextmatelanguage-serverlspdiagnosticstaskscompilers

A new programming language gets a usable IDE fastest as a VS Code extension, not a custom editor: VS Code already provides the editing, terminals, tasks and Problems panel, and the extension only has to describe the language and call its compiler. It can be built in layers, each useful on its own. Justin's H language (~/dev/h, compiler hc) got layers 1 and 2 in one evening on 2026-10-31, as a dependency-free extension in ~/dev/h/ide.

The layers

  1. Grammar + language configuration: syntax highlighting, comments, brackets, indentation. Pure JSON, no code.
  2. Errors and Run by calling the compiler: a small extension.js pipes the buffer to the compiler and turns its error lines into diagnostics; a Run command compiles and runs in a terminal.
  3. Language server (LSP): hover types, go-to-definition, rename, completion. Best written in the compiler's own language reusing its lexer, parser and checker, and it then works in any LSP editor, not only VS Code. Start it only once the parser has stopped changing shape.
  4. Debugger (DAP): only once the compiler emits debug info (e.g. DWARF line tables).

Layer 1: package.json contributions

Layer 2: errors as you type

Layer 2: Run

Packaging and installing

npx @vscode/vsce package --skip-license --allow-missing-repository --out lang.vsix
code --install-extension lang.vsix     # then Developer: Reload Window

No marketplace account is needed for a local install. Keep *.vsix in .gitignore and list dev-only files in .vscodeignore. Bump version in package.json for each reinstall.

From a shell with no Node on PATH (a headless session): VS Code is itself a Node runtime, so ELECTRON_RUN_AS_NODE=1 /usr/share/code/code script.js runs a test script, and packaging works by putting an nvm-installed Node's bin directory on PATH and using npx --offline @vscode/vsce package .... code --install-extension lang.vsix --force installs over the same version.

Keeping the grammar up with the language

A hand-written TextMate grammar knows nothing the compiler knows, so every new keyword, built-in and member has to be added by hand, in the same change as the language feature or soon after. - Contextual words: match a word as a keyword only in the position where it is one (emit only when a value follows, type only before Name {), so a variable with that name stays a variable. - A convention can stand in for semantics: treating capitalized names as types highlights record types correctly without a symbol table. - A catch-all such as "any name after a single | is a pipeline stage" covers user-defined stages. - What a grammar cannot do (module prefixes, telling < in a definition's options from a comparison) is the argument for the language-server layer. - Check the invalid-token rules whenever number syntax changes; 1_000 was being flagged as an error.

Testing without opening VS Code

Gotchas

See also

Linked from

Sources: h memory (ide-vscode-extension), ~/dev/h/ide (commits 7317392, 215b8f2), 2026-10-31, h memory (ide 0.3.0..0.4.1), tldr post #1920