add-lsp-adapter
Skill4 starsChanged 4 months agoMITView on GitHub
Add or validate a language-server adapter in plumb — the base.Adapter shape, the promotion hazard, the conformance and error-contract harnesses, and the experimental-to-validated promotion rule. Use when adding a language or debugging an adapter's diagnostics round-trip.
In this repository3 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- add-mcp-toolSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 14
Create internal/lsp/adapters/<name>/ with a doc.go stating the adapter's validation status (Experimental or Validated — see the promotion …
- Very specific: line 16
Write adapter.go: type Adapter struct{ *base.Adapter }, var _ lsp.Client = (*Adapter)(nil), func New(conn jsonrpc.Caller) *Adapter { return …
- Very specific: line 34
Test: unit tests with internal/lsp/jsonrpc/mock.go covering what this adapter adds (not the inherited base).
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Adding an LSP adapter to plumb
An adapter embeds *base.Adapter (internal/lsp/adapters/base), which supplies all 23
lsp.Client methods, and shadows only what its server does differently. rust is the
minimal worked example (46 lines); full guide in docs/adding-an-lsp.md.
The 5 steps
- Create
internal/lsp/adapters/<name>/with adoc.gostating the adapter's validation status (Experimental or Validated — see the promotion rule below). - Write
adapter.go:type Adapter struct{ *base.Adapter },var _ lsp.Client = (*Adapter)(nil),func New(conn jsonrpc.Caller) *Adapter { return &Adapter{Adapter: base.New(conn, "<binary-name>")} }, andDefaultInitParams— the one genuinely per-server function. Do NOT hand-write the 23 methods. - Shadow only the methods your server does differently, calling through with
a.Adapter.X(ctx, params). Escape hatches are package-level FUNCTIONS —base.Call[T],base.CallPtr[T],base.CallRaw,base.Notify,base.Wrap. Never add an exported method tobase.Adapter: Go promotes it into all nine adapters andinternal/cliresolves optional capabilities structurally, so one stray method silently opts every server into a capability it does not have. An adapter-only capability (e.g. pull diagnostics) is declared in the adapter's own package. base.Newinstalls BOTH transport handlers (notification fan-out + server-request handler);dispatchandhandleServerRequestare unexported, so there is nothing to register and nothing to forget. Server-specific work left to you: init options, workspace model, and — for a server that answers only for open documents — abase.OpenTrackerheld as a NAMED field (never embedded) with anEnsurecall in each affected method and aRefreshinDidChangeWatchedFiles. The set of methods needing it differs per server; do not copy another adapter's.- Test: unit tests with
internal/lsp/jsonrpc/mock.gocovering what this adapter adds (not the inherited base);conformance.RunConformancefor the protocol contract; andconformance.RunErrorContractfor the"<server> <label>: <cause>"strings. Lazy-open adapters also callconformance.RunLazyOpenErrorContract.
The experimental → validated promotion rule
An adapter stays Experimental until the DidChangeWatchedFiles+DidOpen →
publishDiagnostics round-trip runs green against a real server binary, in an
integration test gated //go:build integration — mock-transport unit tests passing is not
enough to promote. Update the adapter's doc.go and the validation table in
docs/adding-an-lsp.md ("## Validation levels") when a real-binary retest goes green.
Recurring gotchas (from the adapter validation table)
- Some servers resolve nothing for an unopened document. zls needs the file opened via
didOpenbefore any per-document query (documentSymbol, definition, references, hover, hierarchy prepares) resolves. Fix:base.OpenTracker— open lazily on first query, close on a watched-file change. sourcekit-lsp, vscode-html-language-server and kotlin-lsp are the others — but the set of methods differs per server and must be MEASURED, not copied: kotlin-lsp needs it fordocumentSymbolalone and answers everything else unopened. - Some servers publish nothing unless the client advertises
textDocument.publishDiagnostics. typescript-language-server does not implement pull diagnostics (textDocument/diagnosticreturns -32601) — it silently produces no diagnostics at all if that client capability isn't declared inDefaultClientCapabilities(). If a new adapter's diagnostics round-trip test fails with no published diagnostics and no error, check this first before chasing a pull-diagnostics theory. - Some servers need a real project layout, not a bare temp workspace, to produce diagnostics at all (kotlin-lsp needs a resolvable Gradle/Maven project — a build that actually completes, not just the files) — a same-symptom failure with a different root cause from the two gotchas above.
- And some genuinely do not push. kotlin-lsp sends zero
publishDiagnosticshowever the client is configured, and answerstextDocument/diagnosticin under a second. Rule them out in this order — client capability, then project realness, then pull — because all three present identically as "no diagnostics". A green PULL round-trip promotes an adapter exactly as a push one does.
Level-3 reference
Full step-by-step guide, including the promotion hazard and the three worked examples
(rust / typescript / swift): docs/adding-an-lsp.md.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

