Language server¶
rainbow-fmt lsp is a Language Server Protocol
server for document formatting, over standard input and output. Any
editor with an LSP client can run it; the VS Code extension
does.
What it does¶
initializeanswers withdocumentFormattingProviderand full document synchronization (the client sends the whole text on each change).textDocument/formattingformats the open document with the configuration that applies to its path, exactly asrainbow-fmt formatwould, verification included, and answers with one edit replacing the whole document — or no edit when nothing changes.- A document that cannot be formatted (a syntax error, a verification failure, an invalid configuration, a file type rainbow-fmt does not know) is answered with a JSON-RPC error carrying the same message the command line prints; editors show it.
shutdownthenexitends the server with exit code 0; anexitwithoutshutdown, or the end of the input, with 1.
The server has no dependencies beyond rainbow-fmt. It does not watch
configuration files: a changed rainbow.toml applies to the next format
request, since the configuration is read per request.
Other editors¶
Point the client at rainbow-fmt lsp for the file types the packs
format (json, jsonc, css, python, javascript, typescript,
html, svelte). For example, in Neovim with nvim-lspconfig:
vim.lsp.config("rainbow_fmt", {
cmd = { "rainbow-fmt", "lsp" },
filetypes = { "json", "jsonc", "css", "python", "javascript", "typescript", "html", "svelte" },
root_markers = { "rainbow.toml", "pyproject.toml", "package.json", ".git" },
})
vim.lsp.enable("rainbow_fmt")
Then vim.lsp.buf.format() formats the buffer.