CompMD Developer's Guide. Written for the @compmd packages at 0.14.0, and following them as they change. Download the book as PDF

23. Helix

Helix has no plugins: a language is an entry in its languages.toml and its query files, and that is how CompMD comes to it, with the language server (chapter 24) and CompMD's grammars. This chapter is that entry for a developer: setting it up, against a release or your own build of the server, what it does in a project of yours, and its configuration. Writing in Helix is the Author's Guide's chapter 22.

Quick setup#

  1. The server: npm install -g @compmd/lsp, cargo install compmd-lsp, or a release's binary, on the PATH.
  2. The entry, drafted in the repository's editors/helix/ for a pull request to Helix: languages.toml's entries into ~/.config/helix/languages.toml (the [[grammar]] entries' rev a commit of comp-markdown/compmd-grammars), and queries/compmd/ and queries/compmd-inline/ into ~/.config/helix/runtime/queries/.
  3. The grammars: hx --grammar fetch and hx --grammar build.

hx --health compmd says what Helix found.

Your own build of the server: name it as the server's command, in your languages.toml or a project's .helix/languages.toml:

[language-server.compmd-lsp]
command = "/home/you/src/compmd/target/debug/compmd-lsp"
args = ["--stdio"]

How to use#

What the entry is#

File What it adds
languages.toml the languages compmd (.comp.md files) and compmd-inline, the server compmd-lsp, also for markdown after Helix's own servers (Marksman, markdown-oxide), and the two grammars
queries/compmd/ highlights (on Helix's Markdown ones), injections and text objects
queries/compmd-inline/ the same for the inline grammar

An expression's CEL is Helix's own cel language. Helix has no folding, so there are no fold queries; a component is a type for text objects (mat, ]t), a param an argument (maa, ]a). Helix draws nothing in place: it declares no drawing, so the server sends it no plan, and a table is aligned in the text by formatting (:format; Helix has no on-type formatting). The preview opens from the code action Open preview, since Helix has no command of a plugin's own.

In a project of yours#

The server reads a document's project as your app does (chapter 24), from the workspace Helix gives it. The scenarios are Neovim's (chapter 21), by the protocol's features: diagnostics, completion, hover (space k), code actions (space a), go to definition (gd), references (gr), rename (space r), symbols (space s), and values as inlay hints.

Checking it#

In comp-markdown/compmd, cargo make helix-check builds the server and the two parsers and runs a real Helix in a tmux session of its own, with the drafts as its config and runtime, reading its screen: the languages, their parsers and queries (every query compiled), the highlights of each grammar, injected ones included, the server's diagnostics, Open preview and the page served. cargo make helix-interactive [file] opens Helix with the drafts in place of your config.

Configuration#

The server's settings go in the server's config, in languages.toml or a project's .helix/languages.toml:

[language-server.compmd-lsp]
config = { packs = { suggest = ["@acme"], network = true }, preview = { browser = "firefox" }, markdown = { enabled = true, wikiLinks = true }, trace = "verbose" }

Chapter 24 has every setting; the drawing's do nothing in Helix. Values beside expressions need display-inlay-hints = true under [editor.lsp] in config.toml. hx -v and :log-open show the messages between Helix and the server.

Upstream. The entry and its queries are opened as a pull request to Helix once the server and tree-sitter-compmd are released; until then they are copied by hand.

Next: the language server and its protocol.