Repository navigation
fix(lsp): publish diagnostics for unopened included files - #1487
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
📊 Benchmark Results
vs main branch (2026-06-21)
What do these numbers mean?
|
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates rustledger-lsp so validation errors originating in included ledger files are surfaced even when those files have no open editor buffer, by computing and publishing diagnostics for unopened included files after validating an open document.
Changes:
- Adds tracking and publishing/clearing of diagnostics for unopened included files (
cross_file_diag_uris+ cross-file publish flow). - Computes diagnostics per unopened ledger file by validating against the full ledger with open-buffer overlays applied.
- Adds an integration regression test ensuring
publishDiagnosticsis emitted for an unopened included file with anE3001(unbalanced) error.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/rustledger-lsp/src/main_loop.rs | Compute/publish diagnostics for unopened included files and track URIs for explicit clearing. |
| crates/rustledger-lsp/tests/lsp_protocol.rs | Adds an integration regression test asserting diagnostics are published for an unopened included file. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Validation errors in an included file the user had not opened were invisible: they were filtered to the open file id, and publish_diagnostics only ran for open buffers. Publish diagnostics for every ledger file not open in a buffer, validated against the full ledger and mapped to its own source, tracking URIs so fixed errors are cleared. Found via LSP dogfooding. Co-Authored-By: Claude Opus 4.8 <[email protected]>
robcohen
force-pushed
the
fix/lsp-included-file-diagnostics
branch
from
June 21, 2026 17:04
bb06383 to
95a678e
Compare
- Skip the current buffer overlay when its fresh parse has errors (avoid validating other files against a partial overlay). - Robustly clear stale cross-file diagnostics: any previously-published URL no longer erroring and not open is cleared, covering fixed errors, include-graph changes, and the ledger becoming single-file/unavailable. - Warn (instead of silently dropping) when a file path is not a valid file:// URI. Added included_file_diagnostics_are_cleared_when_fixed regression test. Co-Authored-By: Claude Opus 4.8 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Jul 19, 2026
…#1813) * fix(lsp): validate multi-file ledgers once, not once per file (#1799) The cross-file diagnostics added in #1487 (c3e8454) called all_diagnostics once per ledger file, and each call re-ran the WHOLE ledger's booking + plugin passes + Early/Late validation just to keep one file's errors — O(files) full validations on every keystroke. Because didChange is handled synchronously on the single LSP main-loop thread, that work blocked completion requests (dispatched only after the notification returns), so completions timed out on large multi-file ledgers (the reporter's 4-file / ~50k-line ledger). Worse without --release, worse with more currencies — both just mean more directives per pass. Split the file-independent, expensive half of validation into run_ledger_validation (sort + book + plugins + Early/Late), computed ONCE, and map each file's diagnostics from the shared result by filtering errors on file_id. ledger_diagnostics_multi produces the current file's AND every unopened file's diagnostics from that single validation; publish_diagnostics routes multi-file ledgers through it and leaves the single-file path unchanged. Unopened files are also no longer re-parsed via a redundant per-file all_diagnostics. Regression test ledger_diagnostics_multi_validates_once_for_all_files asserts exactly one whole-ledger validation regardless of file count (thread-local counter so parallel tests don't interfere). The #1487 behavior tests (included_file_validation_errors_are_published, included_file_diagnostics_are_cleared_when_fixed) still pass. Closes #1799. * perf(lsp): skip the whole-ledger validation when no target uses it Copilot review: ledger_diagnostics_multi ran the whole-ledger book+plugin+validate even when every target failed validation_would_run (all parse errors, or all over the size cap), discarding the result and still blocking the main loop. Gate the validation (and the expensive directive-overlay build) behind `any target validates`; skip to an empty LedgerValidation otherwise. Regression test extended to assert ZERO validations when all targets have parse errors. * fix(lsp): address deep-review findings on the single-pass refactor Two real regressions the review caught in the first cut: 1. Editing a buffer NOT part of the multi-file ledger (a scratch file, current_file_id == None) fell to the else branch, which published an EMPTY cross-file set and thereby CLEARED genuine diagnostics in unopened included files. Now `is_multi_file` alone routes through the cross-file path: the current (non-ledger) buffer self-validates via the single-file path while the unopened ledger files' diagnostics are still recomputed and republished, not cleared. multi_file_diagnostics handles current_file_id == None (unopened targets only). 2. ledger_diagnostics_multi injected the current file's fresh plugins into the shared whole-ledger validation UNCONDITIONALLY — even when the current parse was broken, whose recovered .plugins list is partial or empty. That dropped e.g. auto_accounts from the validation the clean unopened files run against, producing phantom E1001s. Now the fresh plugins are used only when the current file is a ledger file AND parsed cleanly (mirroring the directive-overlay's clean guard); otherwise the ledger's stored plugins are kept, matching the old per-file behavior. Also: restored the size-cap "Skipping validation for large file" debug log for parity with all_diagnostics, and corrected the merged_plugins comment. Regression tests: editing_a_non_ledger_buffer_keeps_unopened_file_diagnostics (integration) and broken_current_parse_keeps_stored_plugins_for_cross_file_validation (unit, asserts no phantom E1001).
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.
What
LSP: a validation error living in an
included file that the user hasn't opened was completely invisible. Found by LSP dogfounding (round 3).Example — open
main.beancountwhich doesinclude "bad.beancount", wherebad.beancounthas an unbalanced transaction.bean-checkreports the imbalance; the LSP reported nothing (no diagnostic onmain, and none onbadeither).Two causes:
validation_errors_to_diagnosticsfilters errors to the open file's id, dropping included-file errors.publish_diagnosticsonly ever runs for an open buffer, so a file with no open buffer never receives apublishDiagnostics— and the LSP spec has no implicit "clear".How
When a ledger is loaded, after publishing the open buffer's diagnostics, also compute and publish diagnostics for every ledger file (reachable via
include) that is not open in any buffer:compute_unopened_ledger_diagnosticsvalidates each unopened file against the full ledger by reusing the existing, testedall_diagnostics— filtered to that file's id and mapped against that file's own source (so ranges are correct), with the open buffers' fresh parses overlaid so unsaved edits are reflected.publish_cross_file_diagnosticspublishes non-empty sets and tracks their URIs incross_file_diag_uris, so when the errors are fixed an explicit empty set is sent to clear them (these files have noon_did_closeto do it).Open files are skipped (they self-publish via didOpen/didChange). The work only runs for multi-file ledgers, and is O(unopened ledger files) validations — real-world ledgers have few files. (A single-pass distribution would remove the per-file re-validation; noted as a possible future optimization.)
Tests
included_file_validation_errors_are_published(integration, via the LSP harness): a journal includesgood+bad; opening onlygood, the client receives apublishDiagnosticsforbad.beancount's URI carrying theE3001(unbalanced) error. Fullrustledger-lspsuite passes (249 + integration); clippy + fmt clean.🤖 Generated with Claude Code