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

22. Writing in Helix

Helix gives a CompMD document what a language server gives: its components and params coloured, what is wrong as you type, completion of a component's name and its params, the value of each {{…}} beside it, tables aligned when you format, and the preview in your browser. It doesn't draw the document in place, as Neovim and Emacs do: Helix has no plugins to draw with. This chapter sets Helix up for CompMD, then goes through writing there, then its settings.

Quick setup#

Helix needs no plugin: CompMD is an entry in its languages.toml and a few query files, which are on their way into Helix itself. Until then, they come from CompMD's repository.

1. The language server. What reads your document is CompMD's language server, compmd-lsp: a program Helix starts beside it, which reads the document as a site does and tells the editor what it found. Install it once, with whichever you have:

npm install -g @compmd/lsp   # with Node.js
cargo install compmd-lsp     # with Rust

or download its file for your computer from the latest release and put it on your PATH.

2. The languages. From editors/helix/, copy languages.toml's entries into your ~/.config/helix/languages.toml, and the queries/ folders into ~/.config/helix/runtime/queries/.

3. The grammars, once (they need git and a C compiler):

hx --grammar fetch
hx --grammar build

4. Open a .comp.md file. hx --health compmd says whether Helix found the grammar, the queries and the server.

How to use#

Fixing a mistake#

A mistake is underlined where it is, with the diagnostic's code and message: a component that isn't imported, a param it doesn't take, a value of the wrong type. ]d and [d go from one to the next, space d lists them all. When there is a fix, space a (the code actions) offers it at the mistake: import the pack that has a component, add a registry. The diagnostics and their fixes has every code.

Adding a component#

Type :: and completion offers the components your document can use, from your project's folder and its installed packs; picking one from a pack adds its import to the frontmatter for you. Inside {…}, it offers the component's params and then their values; in an expression, md. paths and the functions you can call. space k on a component shows its signature, the params it takes and their types (chapter 15).

A component is a text object of its own: mat selects the one the cursor is in, ]t goes to the next; a param is an argument, maa and ]a.

Values#

The value of each interpolation and expression shows beside it, as the last render computed it, once inlay hints are on (below): # {{md.doc.title}} with = Harbour notes after it.

Tables#

:format pads a table's cells so its pipes line up in the file (Helix aligns them only when you format, not as you type). space a on a table offers to insert, delete or move a row or a column, or change a column's alignment.

gd on a link goes to its file or heading; gr on a heading lists every link to it; space r on a heading renames it, and every link to it follows, in every file of the project. A link to a file or a heading that isn't there is warned about. space s lists the document's headings, containers and definitions.

The preview#

The code action Open preview, in space a, opens the document in your browser, as a site renders it, and follows as you type.

Markdown files#

compmd-lsp serves .md files too, after Helix's own Markdown servers. A .md file is CompMD when its frontmatter has an md key (chapter 1), and gets all of the above; otherwise it is plain Markdown, and gets tables aligned by formatting, their code actions and the preview. The code action Read as CompMD adds the key.

What it adds#

Without it, a .comp.md file is Markdown to Helix: its components are plain text, and a typo in a param shows only when the page is built. With it, Helix knows what the site will make of the document as you type: what is wrong and how to fix it, what a component takes, and what a value comes to.

Configuration#

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

[language-server.compmd-lsp]
config = { tables = { alignOnFormat = true }, markdown = { enabled = true, wikiLinks = false } }

The drawing's settings have nothing to do in Helix, which doesn't draw; the Developer's Guide's chapter 24 lists every setting.

Values beside expressions are inlay hints, which Helix shows once asked to, in config.toml:

[editor.lsp]
display-inlay-hints = true

Markdown files. To keep compmd-lsp out of .md files, leave it out of markdown's language-servers in your languages.toml, or set config = { markdown = { enabled = false } }.

Next: the appendices, starting with the syntax at a glance, everything a writer types in one place.