LSP Phase 6: edit-tool diagnostic integration - #30
Merged
Conversation
This was referenced May 19, 2026
src/lsp/diagnostic.rs (new) - pretty(diagnostic): one-line 'SEVERITY [line:col] msg' rendering with LSP 0-based → display 1-based coordinate conversion. - report(file, issues): wraps in <diagnostics file="..."> block. ERROR severity only (warnings/hints are noise). MAX_PER_FILE=20 with '... and N more' overflow footer. - build_report_block(current, all): the full agent-facing block that write/edit tools append. Two sections (each optional): current file errors, then up to MAX_PROJECT_DIAGNOSTICS_FILES=5 other-file errors (e.g. downstream callers that now fail type-checking). - 15 tests covering: severity labels, 1-based coordinate display, missing-severity defaults to ERROR (regression — pretty must never panic or hide a diagnostic), error filtering (regression — warnings must NOT appear), wrap tags, cap at MAX_PER_FILE with overflow (regression — generated files with hundreds of errors must not blow context), other-files cap (regression — single edit shouldn't dump entire project state), warning-only files don't appear, caller path preserved in display (regression — not canonical form). src/agent/tools/write.rs - New optional Option<Arc<LspManager>> field. With manager set, after the write: touch_file(AwaitPush) + build_report_block + append to output. DIAGNOSTIC_WAIT = 10s matches opencode. - Shared append_lsp_block helper used by both write and edit. - 2 tests: no-manager path preserves pre-LSP output exactly (regression); manager-with-no-diagnostics appends nothing. src/agent/tools/edit.rs - Same Option<Arc<LspManager>> field + integration. Diagnostic block appended after the existing diff block. src/agent/tools/read.rs - New optional Option<Arc<LspManager>> field. Read warms the LSP server with a fire-and-forget tokio::spawn(touch_file(Notify)). The read's primary output is unchanged — no diagnostic block (that's the edit tool's job). src/agent/builder.rs - All three tool constructors now pass None for lsp_manager. Phase 7's CLI/config plumbing will populate it. Code review fixes applied before push: - Display caller path (not canonical form) in current-file section so macOS /tmp / /private/tmp asymmetry doesn't confuse the agent. Phase 5: 100, Phase 6: +16 -> 116 LSP tests. Suite: 405 -> 421.
yogthos
force-pushed
the
feature/lsp-phase-6-edit-integration
branch
from
May 20, 2026 01:53
0fb964e to
29885e2
Compare
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.
Phase 6 of 9. Stacked on #29 (Phase 5).
After every `write` / `edit`, the LSP server's fresh diagnostics surface in the tool result so the agent corrects errors on the same turn — instead of writing broken code and discovering it via a manual `cargo check` round-trip.
What's in this PR
`src/lsp/diagnostic.rs` (new)
15 diagnostic tests covering severity labels, coordinate conversion, error filtering, MAX_PER_FILE cap with overflow footer, other-files cap, warning-only-files-don't-appear, and caller-path preservation through canonicalize lookup.
`src/agent/tools/write.rs` + `edit.rs`
New optional `Option<Arc>` field. When set, after the write/edit:
The shared `append_lsp_block` helper lives in `write.rs` and is called from both tools. Errors during touch/wait are swallowed — diagnostic surfacing is a side-effect; the primary tool contract is "wrote/edited the file."
`src/agent/tools/read.rs`
New optional `Option<Arc>` field. Read fires off a `tokio::spawn(touch_file(Notify))` so the server has the file open by the time the agent edits it. No diagnostic block in the read's output — that's the edit tool's job.
Test coverage
Code review fixes applied before push
Scope
Test plan
Next: Phase 7 (config + CLI plumbing — `build_channels` creates the `LspManager` with `ProcessSpawner` configured for the 4 built-in servers; threads through every `build_agent` call site).