Skip to content

fix(lsp): count transactions, not postings, in account summaries - #2862

Merged
robcohen merged 4 commits into
mainfrom
fix/lsp-completion-transaction-count
Nov 5, 2026
Merged

robcohen merged 4 commits into
mainfrom
fix/lsp-completion-transaction-count

Conversation

@robcohen

@robcohen robcohen commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

What changed

Three LSP surfaces counted every posting to an account as a transaction:

  • account completion (completionItem/resolve): the detail (30000 KRW · 2 txns) and the popup (2 transactions);
  • the inlay-hint tooltip;
  • the open code lens.

Each transaction now counts once per account, however many of its postings touch it. The labels use the existing count_noun helper, so a single one reads 1 transaction / 1 txn.

Why

The issue's fixture, one transaction with two postings to Expenses:Supplies, showed 2 txns. The count and its label now use the same unit (the issue's first option).

How to test

cargo test -p rustledger-lsp --all-features. Three new tests, one per surface, use the issue's split-invoice transaction and assert 1 transaction / 1 txn:

  • test_resolve_account_completion_counts_each_transaction_once
  • test_inlay_hint_resolve_counts_each_transaction_once
  • test_code_lens_counts_each_transaction_once

Review round 1

  • One shared rule: account_activity in handlers/utils.rs gives the count, units balance and date range, and completion resolve and the inlay tooltip both call it. The code lens tallies every account in one pass with transaction_accounts, which applies the same rule. No copy of the counting loop is left.

  • Drift guard: test_code_lens_and_completion_resolve_agree_on_transaction_counts checks, for one buffer with split and mixed transactions, that the code lens and completion resolve report the same count for every account, and that both helpers agree.

  • Exact assertions: the code-lens and tooltip tests assert exact strings (1 transaction | KRW, 📊 1 transaction), so 1 transactions or 11 transactions cannot pass.

  • Not changed: which transactions each surface counts. This PR fixes the count unit, not the set:

    • the code lens counts the current file only, so in a multi-file ledger an open in accounts.bean shows "No transactions";
    • completion resolve counts the loaded ledger as written;
    • the inlay tooltip counts the loaded ledger with pad-generated transactions, so a padded account shows one more transaction there than in completion.

    Unifying them would mean the code lens reading the whole ledger, and completion resolve rebuilding the pad-expanded view on every resolve, which fires constantly while scrolling a completion list. The CHANGELOG states this.

Closes #2850

🤖 Generated with Claude Code

Account completion, the inlay-hint tooltip and the `open` code lens
counted every posting to the account, so one transaction with two
postings to it showed as `2 transactions` / `2 txns`. Each transaction
now counts once per account, and the labels use `count_noun`, so a
single one reads `1 transaction` / `1 txn`.

Closes #2850

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen requested a review from a team as a code owner November 5, 2026 03:37
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 50.5ms ± 1.9ms 851.6ms ± 4.2ms 16.9x 34.7 MB / 51.1 MB
investment 77.2ms ± 3.1ms 3038.3ms ± 21.1ms 39.3x 43.7 MB / 59.0 MB
fifo 77.3ms ± 3.0ms 14900.9ms ± 199.4ms 192.8x 40.4 MB / 59.1 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 49.6ms ± 0.3ms 50.5ms ± 1.9ms +1.8% ✅ within noise 34.5 MB → 34.7 MB (+0.7%)
investment 77.0ms ± 1.6ms 77.2ms ± 3.1ms +0.4% ✅ within noise 44.7 MB → 43.7 MB (-2.3%)
fifo 75.1ms ± 0.8ms 77.3ms ± 3.0ms +2.9% ✅ within noise 40.7 MB → 40.4 MB (-0.8%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 0.9ms, investment 1.6ms, fifo 1.4ms), and is at least 5%.
10,000 transactions per shape · 20 runs, 3 warmup · hyperfine

What do these numbers mean?
  • simple — Two-posting transfers, one currency. The historical workload — keep as the floor, not as the benchmark.
  • investment — Cost specs, per-unit prices and lot reductions. Exercises booking and inventory, which simple leaves at 0.3%.
  • fifo — Bare {} reductions against a FIFO account — how FIFO sells are normally written. The other four shapes reach the ordered-selection path twice in 2k transactions between them, so it was effectively unprofiled until it turned out to be quadratic (plan_ordered scans every lot per reduction: FIFO ledgers are quadratic (8.8s at 20k transactions) #2083).
  • vs base: the PR and the base-branch commit it is built on, built and measured in the same job
  • RSS: peak resident set size, a single sample — reported without a verdict because there is no spread to test it against
  • A shape with no beancount column is one bean-check reports errors on; it is timed for rledger only

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100% (raw 93%, 179 masked)
Full AST Match 100%
Total Files 826
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
    The headline is the EFFECTIVE rate, after pairs where beanquery
    itself is wrong are masked. raw is the same run with nothing
    masked. A widening gap means the registry grew, not that rledger
    changed.
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

robcohen and others added 2 commits November 5, 2026 00:44
…ift guard

Review of #2862: completion resolve and the inlay tooltip repeated the
count and balance loop, and the code lens used its own per-transaction
set. All three now use `account_activity` / `transaction_accounts` in
handlers/utils.rs, and a drift-guard test checks that the code lens,
completion resolve and both helpers report the same count per account.
The code-lens and tooltip tests assert exact strings, so `1 transactions`
or `11 transactions` cannot pass. The CHANGELOG states that this fixes
the count unit, not which transactions each surface counts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the count notes

The balance command kept its own copy of the per-currency sum; it now uses
the shared helper. The CHANGELOG described completion as counting the
ledger as written: with a ledger loaded it counts it after booking and
plugins, and the tooltip adds pad-generated transactions (one more per
pad). The currency completion read "1 postings".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen enabled auto-merge (squash) November 5, 2026 08:00
@codecov

codecov Bot commented Nov 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.52941% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../rustledger-lsp/src/handlers/completion_resolve.rs 95.23% 2 Missing ⚠️
crates/rustledger-lsp/src/handlers/inlay_hints.rs 97.14% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Account completion labels posting count as transaction count

1 participant