Repository navigation
fix(lsp)!: publish plugin and load errors where rledger check reports them, and validate a scratch buffer alone - #2969
Merged
Conversation
…them, and validate a scratch buffer alone - #2955: a buffer outside the loaded ledger is validated as a ledger of its own text, as `rledger check` on it does, whatever else is open. It used to get the ledger's errors mapped by byte offset onto its lines, and its `plugin` lines replaced the main file's. - #2957: plugin errors keep their location and are published on the file and line `check` reports (cross-published to an unopened include); only one with no location stays at the top of the main file. - #2959: load errors (`LOAD`) are published: a missing or unreadable include and an include cycle on the `include` line in the including file, the rest in the main file. `LoadError::IncludeCycle` gains `include_site` so the loader, `check --format json` and WASM locate a cycle on that line too. While the ledger has a load error, any watched change reloads it, so creating a missing include clears the error. WASM cache v107 (v106 held by #2931); loader cache unchanged at v73. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
📊 Benchmark Results
vs base, measured in this run
A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: What do these numbers mean?
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
robcohen
added a commit
that referenced
this pull request
Nov 13, 2026
v107 is claimed by #2969; v106 is held by #2931. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
…cle field as breaking - The new main_loop tests read diagnostics off the published notifications by URI instead of MainLoopState::diagnostics, whose keys differ on Windows (an open buffer's URI path `C:\..` against the loader's canonical `\\?\C:\..` for an unopened file). - CHANGELOG: LoadError::IncludeCycle's new public include_site field moves under Breaking, with `rledger check --format json` placing E0002 on the include line, and the FFI component and WASM locating the cycle. - A buffer outside the ledger is validated on its own text without its includes; docs and CHANGELOG now say so instead of claiming it matches `rledger check` on that file in general. - Comment on why plugin and load error lines drift in an edited buffer until the next reload. - check.rs locates the JSON cycle diagnostic with SourceMap::locate. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 13, 2026
… beside a same-cost short (#2970) * fix(booking): read an AVERAGE sale's pool-average cost as a reduction beside a same-cost short On an AVERAGE account holding a short at 101 beside longs averaging 101, a sale `-1 X {}` reduced the longs and booked as `-1 X {101 USD}`. Asked again of the inventory (any consumer realizing a posting with no recorded booking decision), the #2384 own-side exception read that cost lot by lot: it matched the short and neither long, so the booked reduction became a second short. Under AVERAGE a cost is a claim about the pool, so the exception now also treats the other side as named when its pool accepts the cost as a claim. The claim rule moves from rustledger-booking's check_average_spec into rustledger-core (average_claim_mismatch, with written_allowance and its helpers), and both booking and Inventory::is_booking_reduction call it. A written `-1 X {101 USD}` in that shape now books like `-1 X {}`. Commits the proptest seed and adds regression tests at core and validate level. WASM cache bumped to 107 (106 is held by #2931); loader cache unchanged. Closes #2958 Co-Authored-By: Claude Opus 5.5 <[email protected]> * chore(wasm): move the #2958 cache bump to v108 v107 is claimed by #2969; v106 is held by #2931. Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs(booking): name covers in the #2958 rule, and state its two consequences The AVERAGE pool-claim rule applies to a buy that covers shorts as well as to a sale. Say "a sale or a cover" in compatibility.md section 14 and the v108 WASM cache note, and pin the cover with a test: holding a long at 101 beside shorts at 100 and 102, +1 X {101 USD} covers the shorts (1 long, 9 short left), where main opened a second long (2 long, 10 short). The ADR 0007 amendment now states two consequences: a claim the pool accepts only by rounding beats a lot at exactly that cost, and a ledger that loaded can now fail with E4002 on an over-reduction of the pool. Also update the adds_to_its_own_side doc comment to describe the AVERAGE pool test. Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs(changelog): note the AVERAGE reduction fix (#2958) Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 13, 2026
WASM cache: main holds v107 (#2969), #2970 holds 108 and #2971 holds 109, so this PR moves from 106 to 110. The v107 note now says v106 was held here and never released; loader cache stays 73. 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.
What
Three LSP diagnostics bugs. All three are in the same diagnostics-publishing code, so they are fixed in one PR.
#2955: a scratch buffer outside the ledger showed the whole ledger's errors
Cause. In
MainLoopState::publish_diagnostics, a buffer that is not a ledger file took theNonearm and calledall_diagnosticswith the loaded ledger,current_file_id = None, and the other open buffers as overlays. That validated the ledger plus the other buffers but left out the scratch file's own directives. Then, because there was no file id, it mapped every ledger error onto the scratch file's text by byte offset, and merged the scratch file'spluginlines in place of file 0's. With no ledger buffer open the overlay was empty and the scratch file got validated alone. So what it showed depended on what else was open. The single-file branch had the same problem when a single-file ledger was loaded.Fix. A buffer outside the ledger is validated as a single-file ledger of its own text alone, no matter what else is open. Its own
includes are not followed, so this is whatrledger check scratch.beancountreports only when the scratch file includes nothing (checkloads what it includes).all_diagnosticsnow ignoresledger_stateand the overlays when there is nocurrent_file_id, and theNonearm inpublish_diagnosticspasses neither.Why this choice. The ledger's own files still get their diagnostics on every pass: the unopened includes are still cross-published from the scratch buffer's pass, and open ledger buffers publish themselves. So the only question is what the scratch buffer itself shows. The scratch file is not part of the ledger, and
checkon the ledger never reads it, so none of the ledger's findings belong to it. Its own text is the only thing it can be judged by. The other options were worse:Its option diagnostics already followed this rule (#2925).
#2957: plugin errors were published at line 0 of the main file
Cause.
LedgerValidation::plugin_errorskept only(severity, code, message), which dropped theLedgerError's location.map_validation_to_diagnosticsthen showed every plugin error only in file 0, at (0, 0).Fix. Plugin errors keep the whole
LedgerErrortogether with the file id its location names, found by the same path lookup option diagnostics use. Each error is published in that file, on the linecheckreports (the locationplugin_error_to_ledger_errorgives it). Errors in an included file are cross-published to that file when it is not open. An error with no location, or a placeholder one such as<auto_accounts>, stays at the top of the main file. Each error lands in exactly one file.#2959: load errors were not published
Cause.
LedgerState::loaddropped the loader's errors, so a missing or unreadable include, an include cycle, a duplicate include, or an empty glob never reachedpublish_diagnostics. Separately, the loader gave an include cycle no location at all:LoadError::at_includeonly attached the site toIo.Fix.
LoadError::IncludeCyclegains a publicinclude_sitefield, andat_include/include_site()now cover it too.LoadErroris not#[non_exhaustive], so an exhaustive pattern or struct literal on the variant needs the field; hence the!in the title and the### BreakingCHANGELOG entry, as in fix(loader)!: validate options in included files as beancount does, and locate every option diagnostic #2945. A cycle therefore carries theincludethat closed it, in the file that holds that include.processnow locates a load error's include site withSourceMap::locate.rledger check --format jsonputsE0002on that line (also viaSourceMap::locate), matching theIoarm, instead of line 1 of the first file of the cycle. WASM'sinclude_site()consumer and the FFI component (its error'sfilename/line/column, from theLOADerror's location) pick it up without any other change.LedgerState::loadtakes the parse errors out (take_parse_errors), because the LSP already reports those per line from a fresh parse. What remains inledger.errorswith codeLOADis exactly the set of load errors, and the newLedgerState::load_errors()exposes it. Bothall_diagnostics(single-file ledger) andledger_diagnostics_multipublish them through one shared helper,ledger_errors_in_file, which also places option diagnostics by the same rule:includeline in the including file;The message is the loader's
LOADmessage, the same one WASMvalidateMultiFile/Ledger.fromFilesreport..beancountchange reloads it. The file that fixes a missing include is not part of the ledger yet, so without this, creating it would leave the error published. Cross-file publishing already clears an unopened file whose errors are gone.The helpers formerly named
option_error_*were renamedledger_error_*because they now serve option, plugin and load errors.Cache versions
Ledgerarchives its errors and a cycle'sLOADerror now has a location. v106 is held by fix(parser): run a mid-line BOM's invalid token to the next blank, as beancount does #2931.Known limitations (unchanged in kind)
handlers/diagnostics.rsrecords this.rledger check's text output words an unreadable include asfailed to read <path>: .... The loader'sLOADmessage, which the LSP and WASM use, saysfailed to read file <path>: ....Tests
LSP-level tests drive
MainLoopState(on_did_open/didChange/ watched-file events) and compare what is published on the wire (thepublishDiagnosticsnotifications, by URI, so the same on every platform) with the loader'srledger checkerrors on the same files. All four fail onmainand pass with the fix:a_buffer_outside_the_ledger_validates_alone(LSP: a scratch buffer outside the ledger shows the whole ledger's errors #2955):[]whether or not a ledger buffer is open;checkon that file;plugin "auto_accounts"does not clear b's E1001;plugin_errors_are_published_where_check_reports_them(LSP: plugin errors are published at line 0 of the main file, not where rledger check reports them #2957, drift guard):PLUGIN"Disagreeing price entries" is published atb.beancount:4, with the same code, line and message as the loader;a_missing_include_is_published_at_its_include_line(LSP: load errors (missing include, cycle, unreadable include) are not published #2959):LOADappears at line 1 of main with the loader's message, beside theE2001, and clears when the missing file is created.include_cycles_and_unreadable_includes_are_published_at_their_include(LSP: load errors (missing include, cycle, unreadable include) are not published #2959): a cycle and an include of a directory appear on theirincludelines in the unopened include, matching the loader, and clear when fixed on disk.Loader and CLI tests:
test_include_cycle_is_located_at_the_include_that_closes_it(loader): the cycle's site and theLOADerror's location.json_locates_an_include_cycle_at_its_include(CLI):check --format jsonplacesE0002on that include.Gates
cargo fmt --all --checkcargo clippy --workspace --all-features --all-targets -- -D warningsRUSTDOCFLAGS=-Dwarnings cargo doc --workspace --all-features --no-depscargo test -p rustledger-lsp --all-featurescargo test -p rustledger-loader --all-featurescargo test -p rustledger --all-featurescargo test -p rustledger-wasm --all-featuresCloses #2955
Closes #2957
Closes #2959
🤖 Generated with Claude Code