Developing
lnk-link-code is Link Code: an MCP server over stdio that asks a
project's language servers for diagnostics, definitions and
references, each server in a sandbox. How to use it: Link
Code.
Build and test
From tools/, in the public workspace:
cargo build -p link-plugin-link-code
# rust-analyzer under lnk-sandbox: skips, saying why, without either
cargo test -p link-plugin-link-codeHow it's put together
serve --files <folder> --programs-path <PATH> --timeout <duration> --servers <json> [--unavailable <language>=<why>]... -- <sandbox>... is the
tool. With no sandbox after -- it refuses to start.
What Link gives it
Link gives it everything at a start: the spec's [tool.code.servers]
as JSON, each language whose server the sandbox file's [commands]
doesn't allow or this machine doesn't have with why, the call's timeout
a tenth less, and the sandbox, lnk sandbox run with the flags the
sandbox file makes, no network, [commands]' programs.
src/lsp.rs
The client: one server, <sandbox> -- <server> in its project's root,
in a process group of its own that dies with the tool
(PR_SET_PDEATHSIG) and is killed when it stops.
Its messages
A thread reads its messages, framed by Content-Length: replies,
published diagnostics, $/progress and experimental/serverStatus,
and the few requests a server makes of a client, answered as one
offering nothing (no settings, no edits).
A file and its diagnostics
A file is opened on the first call about it and changed and saved when it changed on disk since. Diagnostics wait until the server has no work in progress and has been quiet half a second, and, for a file, has published past what it had or stayed quiet three seconds.
A symbol
A symbol is found with workspace/symbol, exact names only, and its
name's own position in its declaration, for references.
src/lib.rs
It refuses a file outside the files folder (links resolved), picks the server by extension, and turns positions both ways: the model's characters, the server's UTF-16 units. A line is read only from a file in the files folder.
Its tests
tests/protocol.rs (harness = false) runs itself again as a fake
server (--fake-lsp). The diagnostics-waiting case reports work and
publishes past the client's half-second quiet period. Other requests
publish immediately. The fake also crashes on CRASH and names a file
outside the files folder. tests/servers.rs runs rust-analyzer on a
small crate with an error under lnk-sandbox.