moat docs ยท language 1
GitHub

Running Editors

Editors diagnostics, completion and formatting as you type.

moat lsp is a language server on standard input and output: errors and warnings as you type, formatting, completion, quick fixes, hover on fields, keywords and names, document symbols, go to definition, find references and rename.

Completion

Suggestions depend on where the cursor is, and there are none inside a comment. Typing . asks for them too, so tcp. lists the TCP fields.

WhereSuggests
start of a lineversion, default, const, set, var, use, rule
after defaultpass, drop
after usethe std modules
after set NAMEprefixes, addresses, from
in a rule, before whenwhen
in a conditionprotocols, fields, payload, not and true/false variables
after insets and constants
after ==, < and the other comparisonsnumber variables and constants
after payload or payload[OFF:LEN]contains, not
after tcp.flagshas
in { after hasthe flag names
after then, a comma or exceedpass, drop, add, limit
after add or perip.src, ip.dst
after toaddresses sets
in a limitper, burst, on, exceed

Quick fixes

When moat check suggests a fix, the editor offers to apply it and replaces the text:

DiagnosticQuick fix
unknown field 'tcp.dprot' (did you mean 'tcp.dport'?)Change to tcp.dport
10.0.0.1/8 has host bits set; did you mean 10.0.0.0/8?Change to 10.0.0.0/8

In VS Code it shows as the lightbulb, or with Ctrl+. on the squiggle.

References and rename

Find references and rename work on declared sets, constants, variables and rules; in VS Code, Shift+F12 lists the references and F2 renames. A rename changes the declaration and every use. It is refused when the new name is already declared, is a field, a protocol or a flag, or is not a name moat accepts, such as a reserved word.

VS Code

moat-vscode is an extension that starts moat lsp, so it gets all of the above, and adds syntax highlighting. It runs moat from the path, or the one the moat.path setting names.

Neovim, Helix, Zed

tree-sitter-moat is a tree-sitter grammar with highlight queries. Point the editor's language server setting for .moat files at moat lsp.