CompMD for VS Code
vscode-compmd, the VS Code extension for CompMD, Markdown with
components (editor support, decision 6):
- The language CompMD for
.comp.md files, coloured by CompMD's TextMate grammar (@compmd/textmate, from
comp-markdown/compmd-grammars). YAML and TOML frontmatter, JSON
params and an expression's CEL are coloured as their languages.
- The language server,
compmd-lsp: diagnostics, completion, hover, signature help, go to definition, rename,
symbols, folding, formatting, semantic tokens and code actions, the refactorings among them.
- A pack's own grammars: a block a pack renders (a
```mermaid block, with @comp-markdown/mermaid) is
coloured by the grammar the pack ships (compmd.languages, content languages),
merged into the server's semantic tokens.
- The preview in the browser: the button in the editor's title bar, or CompMD: Open Preview in the Browser.
- The document drawn in place (a document drawn in the editor), below.
- Markdown files too, below.
The drawing
The language server plans how a document is drawn, and the extension draws the plan with VS Code's decorations: a
heading's #s as its level's marker and the line in its colour, list bullets and checkboxes as glyphs, quotes and
alerts with their bars, tables with their borders and their cells padded, code blocks' fences set back, a container's
lines with a │ gutter, a component's name in its colour and its params set back, the frontmatter set back. The line
the cursor is on shows its text as written (compmd.render.reveal: line, element or off).
VS Code has no way to draw a line of its own, so nothing is drawn on one: a code block's language goes on its fence
instead. Hiding text (a heading's #s, a bullet replaced by its glyph) is done with CSS in a decoration, which VS Code
doesn't document and may change in a release; compmd.render.vscodeHiding (on) turns it off, and the drawing then
only colours and adds text.
Each style is a theme colour, compmd.heading1 to compmd.heading6, compmd.component, compmd.param and the
rest (the Contributions list in the extensions view), which a theme or your workbench.colorCustomizations
changes. compmd.render.enabled turns the drawing off, and the server's render settings turn each element on or
off (its README).
Markdown files
The server serves .md files as well as .comp.md ones, beside VS Code's own Markdown support, whose highlighting
and preview stay (a document drawn in the editor, decision 13). It reads a .md
file as the spec does: with an md key in its frontmatter it is CompMD, and gets everything a .comp.md file does.
Without one it is CommonMark and GFM, where :::, {…} and {{…}} stay text, and it gets Markdown's features: the
drawing, tables aligned as they are typed and their code actions, links and headings, the preview in the browser, and
Read as CompMD, which adds md.version: 1 to its frontmatter.
What VS Code's own Markdown support does too, so you may turn one of the two off:
| Ours |
VS Code's own |
To keep one |
| completion of link paths and headings |
the same |
compmd.links.enabled: false, or markdown.suggest.paths.enabled: false |
| go to definition and references for links and headings, rename of headings and files |
the same |
compmd.links.enabled: false, or VS Code's stay beside ours |
| broken-link warnings |
markdown.validate.enabled (off by default) |
leave VS Code's off, or compmd.links.enabled: false |
| folding and the outline |
the same |
both stay; they agree |
| the preview in the browser |
its preview beside the text |
both stay |
compmd.markdown.enabled: false turns .md files off altogether, and compmd.render.markdownFiles: false only their
drawing, for another extension's.
The language server
The extension runs compmd-lsp --stdio: the one its setting compmd.server.path names, else the binary it ships for
your platform (each platform's package has its own), else compmd-lsp on your PATH (npm i -g @compmd/lsp, or
cargo install compmd-lsp).
Check
cargo make vscode-check, in comp-markdown/compmd: builds compmd-lsp and the extension, then runs
test/check.ts in your VS Code (macOS's place, or cargo make vscode-check <VS Code's executable>),
with a profile and extensions folder of its own, on a temporary workspace: the language, the server's semantic tokens,
a Mermaid block coloured by its pack's grammar, the preview's command, and the drawing (a heading's #s hidden and
its marker drawn, a bullet's glyph, a container's gutter). It opens a VS Code window for a few seconds,
and isn't part of cargo make ci.
Try it
cargo make vscode-interactive builds compmd-lsp and the extension and opens VS Code
(test/interactive.ts) with the extension from this folder and a profile of its own, on a
temporary workspace with the Mermaid pack and a sample document, notes.comp.md.
Development
pnpm --dir editors/vscode build # dist/extension.cjs, dist/onig.wasm and syntaxes/compmd.tmLanguage.json
pnpm --dir editors/vscode test # the server's command, the token types, the block grammars, the tokens' merge, the drawing's decorations and colours
pnpm --dir editors/vscode lint # the type check
Publishing
One package per platform, with that platform's compmd-lsp in it, which the Marketplace and Open VSX take per
platform (editor-support.md, decision 9): node scripts/package.ts <target> <compmd-lsp binary>, after the build,
writes the .vsix. The extension is developed here; comp-markdown/vscode-compmd is this folder's history split out,
pushed with the maintainer's go. Publishing to the Marketplace and Open VSX is the maintainer's step.
License
Apache License 2.0.