Editors
Cresset helps you while you type in two ways: a VS Code extension, and a language server that any editor with Language Server Protocol support can use.
Both give you the same things, powered by the same checker that runs your programs:
- Errors as you type, underlined with the same message and suggestion
cresset checkgives - Completion: your own functions, records and enums, package members, methods after a dot, permission names after
needs, types in signatures - Hover: the signature of anything, and the doc comment above it; built-in functions too
- Signature help: while you type the arguments of a call, the parameters of that function with the current one marked (defaults shown as
b = ...) - Go to definition, including into the packages you import
- An outline of functions, records, methods and tests
- Formatting with the standard style
All of it keeps working while the file is half-typed.
VS Code
The extension lives in editors/vscode in the project. It has no dependencies. To try it, open that folder in VS Code and press F5, or copy it into your extensions folder. If it can't find Cresset on its own, set the cresset.path setting to the project folder (the one containing src/cresset.js).
Any other editor: the language server
Start it with:
cresset lsp
It talks over standard input and output, the way language servers do, and needs nothing installed beyond Cresset itself. Tell your editor three things: that files ending in .crs are Cresset, that comments start with #, and that the server command is cresset lsp.
Neovim (0.8 or newer)
vim.filetype.add({ extension = { crs = 'cresset' } })
vim.api.nvim_create_autocmd('FileType', {
pattern = 'cresset',
callback = function()
vim.lsp.start({ name = 'cresset', cmd = { 'cresset', 'lsp' }, root_dir = vim.fn.getcwd() })
end,
})
Helix
In languages.toml:
[language-server.cresset]
command = "cresset"
args = ["lsp"]
[[language]]
name = "cresset"
scope = "source.cresset"
file-types = ["crs"]
comment-token = "#"
indent = { tab-width = 4, unit = " " }
language-servers = ["cresset"]
Emacs (eglot)
(define-derived-mode cresset-mode prog-mode "Cresset"
(setq-local comment-start "# "))
(add-to-list 'auto-mode-alist '("\\.crs\\'" . cresset-mode))
(with-eval-after-load 'eglot
(add-to-list 'eglot-server-programs '(cresset-mode . ("cresset" "lsp"))))
Then M-x eglot in a .crs file.
Anything else
Editors such as Zed and Sublime Text (with the LSP package) take the same three facts: the file extension .crs, the command cresset lsp, and # for comments.
An honest note on testing
The language server is tested in the project's own test suite by speaking the real protocol to it: opening a file, getting errors back, asking for completion, hover, definitions, symbols and formatting. The configuration snippets above follow each editor's documented way of adding a server, but they have not yet been tried by hand in every one of those editors. If one doesn't work for you, the command cresset lsp is the part to double-check first.
What it doesn't do yet
- It does not rename symbols or offer code actions.
- It checks one file at a time, plus the packages that file imports.
- It sends the whole file on each change, which is fine for the file sizes Cresset programs have.
Next
Check and format from the terminal: Getting started.