# Editors

> moat lsp brings diagnostics, completion, quick fixes, hover, go to definition, find references and rename to VS Code, Neovim, Helix and Zed.

Source: https://moatfw.dev/docs/editors

`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.

| Where | Suggests |
|-------|----------|
| start of a line | `version`, `default`, `const`, `set`, `var`, `use`, `rule` |
| after `default` | `pass`, `drop` |
| after `use` | the `std` modules |
| after `set NAME` | `prefixes`, `addresses`, `from` |
| in a rule, before `when` | `when` |
| in a condition | protocols, fields, `payload`, `not` and true/false variables |
| after `in` | sets and constants |
| after `==`, `<` and the other comparisons | number variables and constants |
| after `payload` or `payload[OFF:LEN]` | `contains`, `not` |
| after `tcp.flags` | `has` |
| in `{` after `has` | the flag names |
| after `then`, a comma or `exceed` | `pass`, `drop`, `add`, `limit` |
| after `add` or `per` | `ip.src`, `ip.dst` |
| after `to` | addresses sets |
| in a `limit` | `per`, `burst`, `on`, `exceed` |

## Quick fixes

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

| Diagnostic | Quick 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](https://github.com/moatfw/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](https://github.com/moatfw/tree-sitter-moat) is a tree-sitter grammar with highlight
queries. Point the editor's language server setting for `.moat` files at
`moat lsp`.
