VSCode extension
The easy way in: Macaulay2 LSP comes with the language server inside, so installing it is the whole setup. Works on Linux, macOS and Windows, and you don’t need Rust or even Macaulay2 installed.
Search for Macaulay2 LSP in the Extensions view, or:
code --install-extension AlexanderGolys.macaulay2-language-server
Open a .m2 file and you’re done.
What you get
All the usual VS Code moves now work on M2:
| Hover | docs of builtins and your own functions, plus the inferred type |
| F12 / Shift+F12 | go to definition / find references |
| F2 | rename, across files |
| Ctrl+. | quick fixes and refactors on the line |
| Ctrl+Space | completion: package names, option keys, symbols |
| Ctrl+Shift+O / Ctrl+T | symbols in the file / in everything loaded |
| Format Document | the formatter (Shift+Alt+F, Ctrl+Shift+I on Linux) |
| Problems panel | everything the linter and type checker found |
Plus folding, highlighting of the symbol under the cursor, comment toggling with -- and
-* … *-, and auto-closing brackets (including <| |>).
Highlighting comes from the server, not a regex grammar, so it knows what a name is: a function, a type, a local, an option. Colours show up a moment after the file opens.
Type hints are there but hidden, so they don’t clutter the code: hold Ctrl+Alt to see them.
Running code from the editor isn’t there yet; that’s Neovim-only for now.
Settings
Everything is under Macaulay2 in the Settings UI, or macaulay2.* in settings.json.
Changes apply right away, except server.*, which needs a window reload.
Diagnostics
| Setting | Default | |
|---|---|---|
macaulay2.diagnostics.enabled | true | all diagnostics on/off |
macaulay2.diagnostics.disabled | [] | rules to hide, by name or code |
The Settings UI offers every rule with a short explanation, so you don’t need to remember
that S06 is ring-variable-naming.
Formatting
| Setting | Default | |
|---|---|---|
macaulay2.formatting.indentWidth | editor’s | spaces per level |
macaulay2.formatting.useTabs | editor’s | indent with tabs |
macaulay2.formatting.softLineWidth | 100 | width it prefers to wrap at, 0 = off |
macaulay2.formatting.hardLineWidth | 100 | width it always wraps at, 0 = off |
macaulay2.formatting.controlFlowLayout | multilineCompactElse | compact, multiline or multilineCompactElse |
macaulay2.formatting.compactFactorOperators | false | 2*x instead of 2 * x |
macaulay2.formatting.breakAfterSemicolon | true | new line after ; |
Inlay hints
| Setting | Default | |
|---|---|---|
macaulay2.inlayHints.expressionTypes | false | also types of arguments, subexpressions and call results |
macaulay2.inlayHints.allKnownTypes | false | even the obvious ones, like the type of a number literal |
Server
| Setting | Default | |
|---|---|---|
macaulay2.server.path | bundled | your own m2-ls build |
macaulay2.server.arguments | [] | extra arguments for it |
macaulay2.trace.server | off | log LSP traffic (messages, verbose) in the Output panel |
A nice setup
{
"[macaulay2]": {
"editor.formatOnSave": true,
"editor.inlayHints.enabled": "on" // always show types
},
"macaulay2.diagnostics.disabled": ["ring-variable-naming"],
"macaulay2.formatting.hardLineWidth": 90
}
Something’s off?
Set macaulay2.trace.server to messages, reproduce it, and grab the log from
Output → Macaulay2 Language Server for the bug report.