CompMD in VS Code

A week ago CompMD came to Neovim, Emacs and Helix, and VS Code was next. It's here now: CompMD for VS Code is on the VS Code Marketplace, and on Open VSX for the editors built on VS Code that install from there, such as VSCodium and Cursor. You get what the other editors have, like tables drawn in place and the live preview. And there is more: the language server now has templates for components, formatting and refactorings, in every editor.

Getting started

Open the Extensions view (Ctrl+Shift+X, or Cmd+Shift+X on a Mac), search for CompMD, and click Install. VSCodium, Cursor and the other editors that install from Open VSX find it the same way.

Figure 1. CompMD in VS Code's Extensions view.

Figure 1. CompMD in VS Code's Extensions view.

code --install-extension comp-markdown.compmd     # VS Code
codium --install-extension comp-markdown.compmd   # VSCodium

That's all: just open a .comp.md file, or any Markdown file, and the extension is ready to go. It brings the language server with it, so there is nothing else to install.

What you get

Highlighting, for every part

Component lines, params, interpolation and expressions each have their colour, from CompMD's TextMate grammar, and the frontmatter, a JSON param and an expression's CEL are coloured as the languages they are. A code block a pack draws is coloured by the grammar the pack ships: with the Mermaid pack imported, a ```mermaid block is highlighted as Mermaid.

The document, drawn in place

As in Neovim and Emacs, your document looks much like the page it will become, and the file stays exactly as you wrote it: headings with their level and colour, bullets and checkboxes as glyphs, quotes and alerts with their bars, tables with their borders and their cells padded, a container's lines with a gutter, a component's params set back. The line the cursor is on shows its plain text again.

Figure 2. VS Code: the frontmatter, headings, a table and a container drawn in place, with the preview beside it.

Figure 2. VS Code: the frontmatter, headings, a table and a container drawn in place, with the preview beside it.

The colours come from your theme, so it fits right in, and if you'd rather see the plain text, one setting turns the drawing off.

Templates, and the documentation as you go

Type :: at the start of a line, and the completion offers templates as well as names: a container with its required params as tab stops and its closer already written, a leaf, a slot, a row of two boxes, a component definition. They come from the components your document can use, your own included. And you don't need to look anything up: each component's documentation shows right in the completion list, and again when you hover over it.

Figure 3. Templates, completion and documentation in VS Code.

Figure 3. Templates, completion and documentation in VS Code.

Refactorings and formatting

Select some text, and a refactoring turns it into a component of its own; a component can be renamed everywhere it is used. Format Document tidies your component lines and aligns your tables, and leaves the rest as you wrote it.

The preview

The preview button in the editor's title bar opens the page in your browser, as a site renders it, and it keeps up as you type. Its Host style menu shows the page in the look of a few typical sites.

Markdown files too

Plain .md files get the drawing, tables aligned as you type, links and headings across the project, and the preview, beside VS Code's own Markdown support. Add md.version: 1 to a file's frontmatter (the Read as CompMD code action does it for you), and it gets everything a .comp.md file does.

Not only VS Code

Templates, formatting and refactorings are the language server's, so Neovim, Emacs and Helix have them too, with CompMD 0.16.0. CompMD for Zed is ready as well, and waiting for its listing in Zed's extensions; it will get a post of its own when you can install it from there.

What's next

Please try it and tell me what you think, in the comments below or in an issue on GitHub. What's missing, what's annoying, and what you'd want next all help us decide where to go from here.

Until next time...

Hakan Serce