Editors / Language server
The language server, in your browser
This is rakupp --lsp, the server behind the
VS Code extension and Emacs and Neovim support,
compiled to WebAssembly and running in this page. Edit the program and watch
every message the editor and the server send each other.
- Hover a name for its documentation
- Type . $ @ or press Ctrl+Space to complete
- ⌘/Ctrl+click or F12 to go to a definition
- Make a mistake to see it underlined
What you are looking at
The Language Server
Protocol is JSON-RPC: the editor and the server exchange JSON messages, each
preceded by a Content-Length header. A request carries an
id and gets a response with the same id; a
notification has no id and no answer. In an editor the server is
a separate process and the messages go over its standard input and output. Here the
server is a Web Worker and the messages go through postMessage, but they
are the same messages: click any line to see one in full.
The session starts with initialize, where the server says what it can do,
and textDocument/didOpen, which hands it the file. After that every edit is
a didChange with the whole text, and the server answers each one with
publishDiagnostics, the underlines. Hover, completion and go-to-definition
are requests. The diagnostics are the same checks as rakupp --lint: the
parser, the lint rules and the undeclared-variable check.
Two things differ from VS Code. This page waits for a quarter-second pause in your
typing before it sends didChange, where VS Code sends one per edit. And the
colours do not come through the protocol: the server does not offer semantic tokens
yet, so the page calls the same highlighter as rakupp --highlight directly.
To use the server in your own editor, see Editors. The source is src/Lsp.cpp and src/LspIndex.cpp.