Language server¶
lsp/ is the stone-lsp crate, built on lsp-server and lsp-types. It is a separate crate so
that stone itself keeps a single dependency.
cargo test -p stone-lsp # unit, in-memory server, and stdio tests
cargo install --path lsp # install stone-lsp into ~/.cargo/bin
How it works¶
On every change to an open document, the server reruns stone::driver::analyze and answers
requests from the resulting checker::Analysis: its diagnostics, the type of every expression,
and every symbol with all its references. analyze recovers from syntax errors statement by
statement, so features keep working around a typo, and it hides type errors until the syntax
errors are fixed.
file |
role |
|---|---|
|
the initialize handshake, open documents, diagnostics, and request dispatch |
|
one pure function per request over a |
|
converts stone’s 1-based char positions to LSP’s UTF-16 or UTF-8 positions |
To add a feature, write it in features.rs with unit tests in lsp/src/features/tests.rs, then
wire it into Server::handle_request and capabilities.
The VS Code extension¶
editors/vscode/ holds the extension. To work on it:
Install a server with
cargo install --path lsp, or build one withcargo build -p stone-lspand setstone.server.pathto the absolute path oftarget/debug/stone-lsp.Install its dependencies with
npm installineditors/vscode.Open
editors/vscodein VS Code and press F5 to launch a window with the extension loaded, or package and install it:npx @vscode/vsce package code --install-extension stone-0.1.0.vsix
npm test runs the extension’s tests, which cover how server.js picks a server: the
stone.server.path setting, then a bundled server/stone-lsp, then stone-lsp on PATH.