Editors
cuarzo lsp is a language server: it speaks the Language Server Protocol
3.17, so any editor with a client for it can show Cuarzo's errors and
warnings as you type, complete names, show what a name is and where it is
declared, rename, lay out code, and more.
cuarzo lsp over standard input and output
cuarzo lsp --socket=<port> over a TCP socket the editor listens onWhat it does
- Errors and warnings as you type, pushed after each change and pulled
when the editor asks: the errors of Diagnostics, with
their codes and links to them, and the warnings of
cuarzo lint. - Quick fixes from them: a misspelled name, a conversion, a
matchmissing members, an import a name needs, and the fixes of the warnings. Organize imports puts the imports in order. - Completion after a
.(fields, methods, enum members, a module's names) and of the names visible where you type, with their documentation. - Hover, signature help, go to definition, declaration, and type definition, references, and highlights of a name in its file.
- Rename, which says why not when the new name would clash.
- Document symbols (outline) and workspace symbols.
- Formatting of documents, of ranges, and as you type, as
cuarzo fmtlays code out. - Folding, selection ranges, semantic highlighting, inlay hints (types of loop variables and of function values' parameters, names of parameters before literal arguments), and the call hierarchy.
- Code lenses to run the program (
cuarzo.run) and each test of a test file (cuarzo.runTest), and links from imports to their files.
Each change is checked again only where it matters, so a change to a function's code in a program of 50,000 lines is checked in under 100 ms. A check stops when you type again, and the next one takes both changes in.
Grammars for coloring code without the server, TextMate's and
tree-sitter's, are in editors/. Debugging is
cuarzo dap's; see Debugging.
The program it checks
A document is checked as part of a program. The program's main file is the
one the editor's settings name (initializationOptions.main, relative to
the workspace folder); in a project, the program or library
of cuarzo.toml that starts in the first document opened, or else its
first program; or the folder's main.cz; or else the first document
opened. A document outside that program is checked on its own.
In a project, the constants of the debug profile apply, as for cuarzo check, and what is wrong with cuarzo.toml is reported on it. When the
editor says the manifest changed (workspace/didChangeWatchedFiles), it is
read again and the program checked again.
Settings, as initializationOptions or under cuarzo in
workspace/didChangeConfiguration:
| Setting | Default | |
|---|---|---|
main |
the program's main file | |
lint |
true |
the warnings of cuarzo lint |
Setting it up
Visual Studio Code
With an extension that runs language servers, such as a generic LSP client,
point it at cuarzo lsp for .cz files. A minimal extension's
package.json declares the language and starts the server:
"contributes": {
"languages": [{"id": "cuarzo", "extensions": [".cz"]}]
}const server = {command: "cuarzo", args: ["lsp"]};
new LanguageClient("cuarzo", "Cuarzo", server, {documentSelector: [{language: "cuarzo"}]}).start();Neovim
vim.filetype.add({extension = {cz = "cuarzo"}})
vim.api.nvim_create_autocmd("FileType", {
pattern = "cuarzo",
callback = function()
vim.lsp.start({name = "cuarzo", cmd = {"cuarzo", "lsp"}, root_dir = vim.fn.getcwd()})
end,
})Helix
In languages.toml:
[[language]]
name = "cuarzo"
scope = "source.cuarzo"
file-types = ["cz"]
language-servers = ["cuarzo"]
[language-server.cuarzo]
command = "cuarzo"
args = ["lsp"]Emacs
With Eglot:
(define-derived-mode cuarzo-mode prog-mode "Cuarzo")
(add-to-list 'auto-mode-alist '("\\.cz\\'" . cuarzo-mode))
(add-to-list 'eglot-server-programs '(cuarzo-mode "cuarzo" "lsp"))Sublime Text
With the LSP package, in its settings:
"clients": {
"cuarzo": {
"enabled": true,
"command": ["cuarzo", "lsp"],
"selector": "source.cuarzo"
}
}