Repository navigation
Add a built-in D2 language server for editors - #3059
Merged
Merged
Conversation
- sent from alixander's Codex
Compare single-file language-server renames against d2oracle on compiled diagrams, including near targets and connections. - sent from alixander's Codex
- sent from alixander's Codex
- sent from alixander's Codex
alixander
added a commit
that referenced
this pull request
Nov 26, 2026
Master adds the CLI's MCP and LSP servers (#3058, #3059), uvx distribution (#3061) and a setup-d2 doc (#3062), and makes native builds embed the TTFs the way master's WebAssembly initializer did (9064887). d2fonts_embed.go and d2fonts_woff.go are master's, limited to native builds, so the native CLI's font bytes match master's exactly. WebAssembly builds keep this branch's d2fonts_embed_wasm.go, which loads the same TTFs from ttf_stream.br. go.sum is master's, tidied. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human
AI
Adds
d2 lsp [--stdio], a built-in LSP 3.17 server for D2. The editor guide includes setup for Neovim, Helix, and Claude Code.Editors get live diagnostics, formatting, completion, hover, an outline, folding, document links, color pickers, go-to-definition, find-references, and shape rename. Imports see open buffers, so navigation and diagnostics track unsaved changes. Renaming a shape also updates its references in imported files and inherited scenario boards.
The server uses UTF-16 positions and full document sync. Syntax features remain available during incomplete edits. Navigation uses a cached partial IR. Board-local declarations take precedence over inherited ones, and rename checks for collisions in each affected container.
Find-references and rename follow shape paths in literal
nearvalues. For example, renamingatobedits both the declaration andnote: {near: a}. The outline groupsx.shapeandx.style.fillunder onexentry and omits separate entries for connection style assignments.References and rename include open importers of a shared diagram. Rename refreshes closed dependencies before calculating edit ranges and sends document versions to clients that support them. When a selective import, a board override, or conflicting unsaved buffers make a complete edit uncertain, the server returns a reason.
Go-to-definition follows locally shadowed variables. Incomplete syntax still has an outline and diagnostics while the user types.
Closes #2550.
Verification
./make.sh fmt,./make.sh lint, and./make.sh testpass locally.go test -race ./d2lsp/lspserver/passes.All tests L1 to L78 exist and pass. L78 compares the shapes, connections, and placement targets after applying LSP edits with the compiled result of
d2oracle.Renameacross seven cases. The framing reader passed a ten-second fuzz run with more than 66,000 inputs.go.modandgo.sumare unchanged.Outside the server package, changes cover CLI integration, the partial IR option, completion context in the existing helper, tests, documentation, and CI. CI runs the server suite on Windows and under the Linux race detector.
The existing
d2lsppackage and D2.js dependency graph exclude the server. Checked withgo list -deps ./d2js/...and withGOOS=js GOARCH=wasm.The Appendix C transcript ran against the built binary. Stdout contained two framed JSON-RPC responses, stderr was empty, and the process exited 0.
Existing test fixtures and expected outputs are unchanged.
Tested in Neovim 0.11.6 with the documented configuration. It attached, reported and cleared diagnostics on unsaved edits, formatted the buffer, jumped to a definition, applied a rename, and shut down cleanly. Helix 25.07.1 also launched the server using the documented configuration, received a live diagnostic at the correct UTF-16 range, and shut down cleanly.
A live stdio session exercised 2,650 feature requests against 265 partial edits, with no protocol errors or stderr. Separate runs checked 32 open buffers and a diagram with 1,500 shapes and 500 edges.
With the documented Neovim configuration, renaming a shared declaration updated an unsaved
neartarget and an edge in a second open buffer.sent from alixander's Codex