# Editor support for Rex Everything here talks to the compiler itself, so what you see in the editor is exactly what `rex run` would tell you. | You get | How | |---------|-----| | Syntax colours | a grammar file (VS Code, Neovim, Vim) | | Errors underlined as you type | the language server, `rex lsp` | | Format the file (and on save) | the same server, using `rex fmt` | | Outline, go to definition, hover, completion, parameter hints | the same server (reads the file's names; no type checking) | First put the `rex` program on your `PATH`: ```text cargo build --release cp target/release/rex ~/.local/bin/ # or anywhere on your PATH ``` ## VS Code The extension is in `editors/vscode/`. ```text cd editors/vscode npm install # downloads the small language-client library npx @vscode/vsce package # makes rex-0.1.0.vsix code --install-extension rex-0.1.0.vsix ``` To try it without installing, open the `editors/vscode` folder in VS Code and press **F5**. If `rex` is not on your `PATH`, set **Rex: Server Path** in the settings to the full path. Format-on-save and 4-space indents are switched on for `.rex` files by default. ## Neovim Put the `vim/` folder on your runtime path to get file detection and colours, for example (with a plugin manager that takes a local path), or copy the two files: ```text mkdir -p ~/.config/nvim/syntax ~/.config/nvim/ftdetect cp vim/syntax/rex.vim ~/.config/nvim/syntax/ cp vim/ftdetect/rex.vim ~/.config/nvim/ftdetect/ ``` Then in `init.lua` (Neovim 0.8 or newer): ```lua vim.api.nvim_create_autocmd("FileType", { pattern = "rex", callback = function(args) vim.lsp.start({ name = "rex", cmd = { "rex", "lsp" }, root_dir = vim.fs.dirname(args.file), }) vim.bo.shiftwidth = 4 vim.bo.expandtab = true end, }) -- format when saving vim.api.nvim_create_autocmd("BufWritePre", { pattern = "*.rex", callback = function() vim.lsp.buf.format({ async = false }) end, }) ``` Plain Vim gets the colours from the same two files (no language server). ## Helix Add this to `~/.config/helix/languages.toml`: ```toml [language-server.rex] command = "rex" args = ["lsp"] [[language]] name = "rex" scope = "source.rex" file-types = ["rex"] comment-token = "//" indent = { tab-width = 4, unit = " " } language-servers = ["rex"] auto-format = true ``` ## Any other editor Anything that can run a language server works: start `rex lsp` (it speaks the standard protocol over stdin/stdout) for files ending in `.rex`. It supports diagnostics and whole-file formatting. The grammar for colours is the TextMate file `vscode/syntaxes/rex.tmLanguage.json`, which Sublime Text, Zed and many others can read. ## What the server does (and doesn't) do yet - Checks the file every time you type, including the files it imports (from disk, or from unsaved changes in other open files). The compiler stops at the first error, so you see one underline at a time. - An error inside an imported file is shown at the top of the file that imports it. - Formats the whole file; a file that doesn't parse is left alone. - Not yet: hover, go to definition, completion, rename. ## Opcode Opcode (the C++ editor in `~/Desktop/Porn/Linux/Clean/opcode`) knows Rex out of the box: colours, `//` comments, snippets, the outline, format with `rex fmt -`, and the language server (`rex lsp`) for errors, go to definition, hover, completion and parameter hints. It only needs `rex` on your `PATH` (see the top of this page).