Wire mforth into Helix¶
Goal: get tree-sitter syntactic highlighting and
mforth lspdiagnostics for.fsfiles in Helix.Prerequisites:
- Helix with
hx --grammarsupport (any recent release).- The tree-sitter CLI (
npm install -g tree-sitter-cliorcargo install tree-sitter-cli).- This repository checked out at a stable absolute path.
mforthon$PATH(e.g.pip install -e .from the repo root) if you want LSP wiring; tree-sitter highlighting works without it.
Steps¶
-
Build the tree-sitter parser. From this repo's root:
cd tree-sitter-mforth tree-sitter generate # emits src/parser.c from grammar.js tree-sitter test # verify the corpus tests passsrc/parser.cis a build artifact (not committed) — regenerate it on each pull whenevergrammar.jschanges. -
Append the Helix fragment. Open
~/.config/helix/languages.toml(create it if missing) and append the contents ofeditor/helix/languages.tomlfrom this repo. Replace the placeholder source path with the absolute path to your localtree-sitter-mforthdirectory:[[language]] name = "mforth" scope = "source.mforth" file-types = ["fs"] roots = [".world.toml", "pyproject.toml"] comment-token = "\\" indent = { tab-width = 2, unit = " " } language-servers = ["mforth-lsp"] [[grammar]] name = "mforth" source = { path = "/absolute/path/to/tree-sitter-mforth" } [language-server.mforth-lsp] command = "mforth" args = ["lsp"] -
Let Helix build the grammar. From the shell:
(Or from inside Helix:
:grammar fetchthen:grammar build.) -
Verify the wiring. Open any
.fsfile (e.g.examples/blink.fs) and confirm:- Comments dim, keywords bold, numbers and strings distinct, definition names highlighted as functions.
- Inside the buffer,
:langreportsmforth. - If
mforthis on$PATH, the LSP attaches on buffer open — parse / stack-balance / undefined-word diagnostics surface inline, hover shows stack effects, and completion offers built-ins and user-defined words in scope.
What the LSP gives you¶
The language-server.mforth-lsp block above launches mforth lsp for
.fs buffers. The capabilities the server ships today are catalogued
in the Reference; the surface is:
- parse / stack-balance / undefined-word / sidecar-link diagnostics,
- hover (stack effects for built-ins and inferred effects for user words),
- completion (built-ins and user-defined words in scope),
- semantic tokens that refine tree-sitter's static highlighting.
If mforth is not on $PATH, Helix logs a "command not found"
warning and falls back to tree-sitter highlighting only.
Troubleshooting¶
- Tree-sitter says "no language found". Helix looks for grammars
under its config directory's
runtime/grammars/. Re-runhx --grammar buildand read the output for compile errors. Thesource = { path = ... }must point at the directory containinggrammar.js, not at the generatedsrc/parser.c. - No highlighting at all. Inside a
.fsbuffer,:langshould saymforth. If it saystext, thefile-types = ["fs"]line isn't being read — check that yourlanguages.tomlis well-formed. - LSP errors on every buffer. Confirm
mforth lspruns from your shell (mforth lsp --helpshould print usage). Ifmforthis not installed, comment out thelanguage-servers = ["mforth-lsp"]line until you install it — tree-sitter highlights work without the LSP. - Re-link the grammar after a pull. Run
tree-sitter generateandhx --grammar buildagain whenevergrammar.jschanges.
What to read next¶
- Tutorials — a guided walkthrough now that your editor is wired up.
- Use with Neovim — the same wiring for nvim-treesitter and nvim-lspconfig.
- Reference — the catalogue of every mforth surface, including the LSP capabilities listed above.