Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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:

Hoverdocs of builtins and your own functions, plus the inferred type
F12 / Shift+F12go to definition / find references
F2rename, across files
Ctrl+.quick fixes and refactors on the line
Ctrl+Spacecompletion: package names, option keys, symbols
Ctrl+Shift+O / Ctrl+Tsymbols in the file / in everything loaded
Format Documentthe formatter (Shift+Alt+F, Ctrl+Shift+I on Linux)
Problems paneleverything 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

SettingDefault
macaulay2.diagnostics.enabledtrueall 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

SettingDefault
macaulay2.formatting.indentWidtheditor’sspaces per level
macaulay2.formatting.useTabseditor’sindent with tabs
macaulay2.formatting.softLineWidth100width it prefers to wrap at, 0 = off
macaulay2.formatting.hardLineWidth100width it always wraps at, 0 = off
macaulay2.formatting.controlFlowLayoutmultilineCompactElsecompact, multiline or multilineCompactElse
macaulay2.formatting.compactFactorOperatorsfalse2*x instead of 2 * x
macaulay2.formatting.breakAfterSemicolontruenew line after ;

Inlay hints

SettingDefault
macaulay2.inlayHints.expressionTypesfalsealso types of arguments, subexpressions and call results
macaulay2.inlayHints.allKnownTypesfalseeven the obvious ones, like the type of a number literal

Server

SettingDefault
macaulay2.server.pathbundledyour own m2-ls build
macaulay2.server.arguments[]extra arguments for it
macaulay2.trace.serverofflog 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.

Marketplace · Repository