You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: nvim - LSP Restarts required to show and clear balance #685
I analyzed the asciinema recording and the LSP source code. Here's what I found:
Observed Behavior
~14s: User changes -5000 to -5001 (creates imbalance) — no error appears
~26s: Error finally appears (Transaction does not balance) — but only after what appears to be an LSP restart or save
~56s: User fixes it back to -5000 — error persists even though the text is now correct
Error only clears after another LSP restart
Code Analysis
The on_did_change handler in main_loop.rs:1069 looks correct — it updates the VFS and calls publish_diagnostics synchronously with the new text. The publish_diagnostics function re-parses the document and runs validation fresh each time.
Two possible root causes to investigate:
1. Neovim client-side diagnostic caching
The LSP sends PublishDiagnostics notifications (push model), but some neovim LSP client configurations may not immediately refresh inline diagnostics on every publishDiagnostics notification. Check if the user's neovim config has any diagnostic display settings that require manual refresh.
2. textDocument/didChange not being sent
If neovim is configured to only send didChange on save (not on every keystroke), the LSP never sees the buffer changes until :w. The server declares TextDocumentSyncKind::FULL which should cause neovim to send full content on every change, but some neovim LSP client wrappers may override this behavior.
Debugging suggestion
Add a tracing::info! in on_did_change that logs the text length and first few characters, then check the LSP log to verify didChange notifications are actually being received on each keystroke. If they are, the issue is on the nvim diagnostic display side. If they're not, the issue is in the nvim LSP client configuration.
// In on_did_change, after getting the text:
tracing::info!("didChange: {} bytes, starts with: {:?}", text.len(),&text[..text.len().min(50)]);
Confirmed: Server is working correctly, issue is client-side
I tested the LSP server directly by sending JSON-RPC messages and verified diagnostics update correctly:
=== After didOpen (balanced) ===
Diagnostics: 0
=== After didChange (unbalanced -5001) ===
Diagnostics: 1
1: Transaction does not balance: residual -1 USD (2024-01-15)
=== After didChange (fixed back to -5000) ===
Diagnostics: 0
The server sends publishDiagnostics notifications immediately and correctly after every textDocument/didChange.
Likely cause
This is a neovim client configuration issue. Common causes:
The nvim LSP client is not forwarding didChange on every keystroke. Check if your LSP client config sets flags = { debounce_text_changes = ... } or similar. The server needs TextDocumentSyncKind.Full changes on every edit.
Diagnostic display refresh. Some nvim diagnostic display plugins (or vim.diagnostic settings) don't refresh inline virtual text immediately. Try:
vim.diagnostic.config({ update_in_insert=true })
If using a wrapper like nvim-lspconfig, ensure the on_attach callback doesn't override diagnostic refresh behavior.
Quick test
You can verify if didChange is being sent by checking the LSP log:
:luavim.lsp.set_log_level("debug")
Then edit a file and check ~/.local/state/nvim/lsp.log for didChange messages.
I tested with a minimal nvim config (no plugins, no lspconfig) and the LSP works correctly — diagnostics update live as you type:
Before edit: 0 diagnostics
After changing -5000 to -5001: 1 diagnostic (E3001: Transaction does not balance)
After fixing back: 0 diagnostics
The LSP log confirms textDocument/didChange is sent and publishDiagnostics is received immediately.
The issue is in your neovim configuration, not the LSP server. Most likely causes:
A plugin debouncing didChange — some LSP plugins (e.g., older nvim-lspconfig configs) add flags.debounce_text_changes which delays sending changes to the server
update_in_insert = false (the default) — nvim won't display new diagnostics while in insert mode. Add to your config:
vim.diagnostic.config({ update_in_insert=true })
A diagnostic display plugin (like trouble.nvim or custom virtual text handlers) overriding the default diagnostic rendering
To reproduce the working behavior
Save this as /tmp/init.lua and run nvim -u /tmp/init.lua test.bean:
@lutzky you were right, this is a server-side bug and my earlier diagnosis was wrong. Apologies for the runaround.
The JSON-RPC test I ran earlier didn't have a journal file loaded, which took a different code path than the one your nvim setup actually hits. With a real journal the LSP uses directives from ledger_state (loaded from disk at startup, refreshed only by file-watcher events on save) rather than from the fresh parse of the buffer. In-memory edits never reach validation until you save, which is exactly what you were seeing.
Root cause
crates/rustledger-lsp/src/handlers/diagnostics.rs:282 pulls full_directives from ledger_state, and validation_errors_to_diagnostics at line 147 prefers that over the fresh parse whenever a current_file_id is known:
let directives_to_validate = if current_file_id.is_some(){
full_directives.unwrap_or(directives)// stale directives win}else{
directives // fresh directives only used in single-file mode};
ledger_state is loaded in main_loop.rs:141 and only reloaded via reload_journal() from the file-watcher. Buffer edits never touch it. So the sequence is:
LSP starts, loads file from disk (balanced)
You edit -5000 to -5001, nvim sends didChange
publish_diagnostics parses the fresh text, finds current_file_id, then validates against the stale ledger_state directives and reports no error
You save, file-watcher fires, reload_journal picks up the new disk content, diagnostics republish, error appears
You fix it back to -5000 in the buffer, but ledger_state still holds the saved -5001, so the error persists until the next save
That matches both your asciicast and the original report.
Fix
Live overlay at the all_diagnostics layer: when both ledger_state and current_file_id are available, build a merged directive list that takes full_directives minus the stale entries for current_file_id and appends the fresh parse from the buffer (remapped to current_file_id so the existing per-file filter still works). PR on the way.
Activity
robcohen commentedon Apr 6, 2026
I analyzed the asciinema recording and the LSP source code. Here's what I found:
Observed Behavior
-5000to-5001(creates imbalance) — no error appearsTransaction does not balance) — but only after what appears to be an LSP restart or save-5000— error persists even though the text is now correctCode Analysis
The
on_did_changehandler inmain_loop.rs:1069looks correct — it updates the VFS and callspublish_diagnosticssynchronously with the new text. Thepublish_diagnosticsfunction re-parses the document and runs validation fresh each time.Two possible root causes to investigate:
1. Neovim client-side diagnostic caching
The LSP sends
PublishDiagnosticsnotifications (push model), but some neovim LSP client configurations may not immediately refresh inline diagnostics on everypublishDiagnosticsnotification. Check if the user's neovim config has any diagnostic display settings that require manual refresh.2.
textDocument/didChangenot being sentIf neovim is configured to only send
didChangeon save (not on every keystroke), the LSP never sees the buffer changes until:w. The server declaresTextDocumentSyncKind::FULLwhich should cause neovim to send full content on every change, but some neovim LSP client wrappers may override this behavior.Debugging suggestion
Add a
tracing::info!inon_did_changethat logs the text length and first few characters, then check the LSP log to verifydidChangenotifications are actually being received on each keystroke. If they are, the issue is on the nvim diagnostic display side. If they're not, the issue is in the nvim LSP client configuration.robcohen commentedon Apr 6, 2026
Confirmed: Server is working correctly, issue is client-side
I tested the LSP server directly by sending JSON-RPC messages and verified diagnostics update correctly:
The server sends
publishDiagnosticsnotifications immediately and correctly after everytextDocument/didChange.Likely cause
This is a neovim client configuration issue. Common causes:
The nvim LSP client is not forwarding
didChangeon every keystroke. Check if your LSP client config setsflags = { debounce_text_changes = ... }or similar. The server needsTextDocumentSyncKind.Fullchanges on every edit.Diagnostic display refresh. Some nvim diagnostic display plugins (or
vim.diagnosticsettings) don't refresh inline virtual text immediately. Try:If using a wrapper like
nvim-lspconfig, ensure theon_attachcallback doesn't override diagnostic refresh behavior.Quick test
You can verify if
didChangeis being sent by checking the LSP log:Then edit a file and check
~/.local/state/nvim/lsp.logfordidChangemessages.robcohen commentedon Apr 6, 2026
Update: Verified working with stock Neovim 0.11.7
I tested with a minimal nvim config (no plugins, no lspconfig) and the LSP works correctly — diagnostics update live as you type:
The LSP log confirms
textDocument/didChangeis sent andpublishDiagnosticsis received immediately.The issue is in your neovim configuration, not the LSP server. Most likely causes:
didChange— some LSP plugins (e.g., oldernvim-lspconfigconfigs) addflags.debounce_text_changeswhich delays sending changes to the serverupdate_in_insert = false(the default) — nvim won't display new diagnostics while in insert mode. Add to your config:trouble.nvimor custom virtual text handlers) overriding the default diagnostic renderingTo reproduce the working behavior
Save this as
/tmp/init.luaand runnvim -u /tmp/init.lua test.bean:If diagnostics work with this minimal config but not your normal config, bisect your plugins to find the culprit.
robcohen commentedon Apr 6, 2026
Please reopen this issue if you determine it is not a client side issue.
lutzky commentedon Apr 7, 2026
The diagnostics still don't behave correctly with the minimal config.
Note, I don't have permission to reopen the issue.
robcohen commentedon Apr 11, 2026
@lutzky you were right, this is a server-side bug and my earlier diagnosis was wrong. Apologies for the runaround.
The JSON-RPC test I ran earlier didn't have a journal file loaded, which took a different code path than the one your nvim setup actually hits. With a real journal the LSP uses directives from
ledger_state(loaded from disk at startup, refreshed only by file-watcher events on save) rather than from the fresh parse of the buffer. In-memory edits never reach validation until you save, which is exactly what you were seeing.Root cause
crates/rustledger-lsp/src/handlers/diagnostics.rs:282pullsfull_directivesfromledger_state, andvalidation_errors_to_diagnosticsat line 147 prefers that over the fresh parse whenever acurrent_file_idis known:ledger_stateis loaded inmain_loop.rs:141and only reloaded viareload_journal()from the file-watcher. Buffer edits never touch it. So the sequence is:-5000to-5001, nvim sendsdidChangepublish_diagnosticsparses the fresh text, findscurrent_file_id, then validates against the staleledger_statedirectives and reports no errorreload_journalpicks up the new disk content, diagnostics republish, error appears-5000in the buffer, butledger_statestill holds the saved-5001, so the error persists until the next saveThat matches both your asciicast and the original report.
Fix
Live overlay at the
all_diagnosticslayer: when bothledger_stateandcurrent_file_idare available, build a merged directive list that takesfull_directivesminus the stale entries forcurrent_file_idand appends the fresh parse from the buffer (remapped tocurrent_file_idso the existing per-file filter still works). PR on the way.lutzky commentedon Apr 11, 2026
Perhaps it's advisable to use plenary.nvim to create an integration test? Or VHS by charm for an end-to-end visual integration test?
fix: overlay in-memory buffer on stale ledger snapshot for LSP diagno…
test: add end-to-end all_diagnostics regression test and helper invar…
fix: overlay all open buffers when publishing LSP diagnostics
fix: overlay all open buffers when publishing LSP diagnostics
fix: overlay all open buffers when publishing LSP diagnostics (#764)
chore: release v0.12.0