Editor support: trine lsp (32a-d, 33a-b)
trine lsp is a language server on stdin/stdout (LSP, full-document sync). It gives:
- Diagnostics as you type: the first error and every lint warning, with the same codes and messages as
trine check --json(one source of truth: the server parses that JSON back). Errors inside an imported file are shown on line 1, naming the file and position. - Hover: the inferred type of the variable under the cursor (the nearest
let/var/forbinding above it), of a function (fn area : (Shape) -> Float), or what a constructor builds. - Inlay hints:
: Typeafter every unannotatedlet/var/forname, and the full signature at the end of every function header that leaves a type out.
- Go to definition for functions, types, constructors and traits (including the ones in imported modules, opened at their file and line), local variables (the binding above the cursor) and parameters.
Hover, hints and definitions use the last version of the buffer that type-checked, so they don't flicker away while a line is half-typed.
Neovim (0.10+)
vim.filetype.add({ extension = { tr = "trine" } })
vim.api.nvim_create_autocmd("FileType", { pattern = "trine", callback = function()
vim.lsp.start({ name = "trine", cmd = { "trine", "lsp" }, root_dir = vim.fn.getcwd() })
vim.lsp.inlay_hint.enable(true)
end })
VS Code
Any generic LSP client extension works; point it at the command trine lsp for *.tr files.
Helix (languages.toml)
[[language]]
name = "trine"
file-types = ["tr"]
language-servers = ["trine"]
[language-server.trine]
command = "trine"
args = ["lsp"]
Incremental (32d)
The server keeps its work between keystrokes: each file's parse is kept by its content, and while the imported modules haven't changed (their paths and texts are fingerprinted at every check) their functions' types are reused instead of their bodies being checked again (a module can't see the file that imports it, so its types can't depend on it). Only the open file is linted, and a burst of changes is checked once, at its end. A module edited on disk is picked up at the next keystroke.
python3 tools/lsp_bench.py types into a generated 5,000-line project (a main file and four modules) and reports the time from each keystroke to its diagnostics and inlay hints; a test holds the 95th percentile under 100 ms (on the development machine: ~3 ms typical, ~20 ms at worst, against ~50 ms for a full check). TRINE_LSP_TIMING=1 prints the phases to stderr.
Ownership, copy and check hints (33b)
Once the buffer has been still for 300 ms the server runs trine hints on it in another process (the same pipeline native code is compiled with: borrow inference, drop-reuse, the bounds verifier) and asks the editor to refresh its inlay hints:
borrowed/ownedafter a heap-valued parameter: the function borrows it (no reference counting) or takes it over;sharewhere a use takes another reference to a heap value: from there two owners hold it, so updating either one copies it;may copyat an update (xs[i] = v,push) of a value shared earlier in the function;bounds checkwhere an index check is still done at run time (trine hints --overflowadds overflow checks).
Each hint's tooltip says why. trine hints f.tr prints them on the command line.