Repository navigation
fix(lsp): silent request timeouts, and inlay-hint drift (#2197, #722) - #3159
Conversation
sinelaw
left a comment
There was a problem hiding this comment.
Careful read of the whole diff. Six findings, all posted inline. The Deno detection change (deno_lsp_override + the bounded authority probe) and the LspError { server_command } plumbing look correct to me; the handle_cancel_request fix (dropping the pending entry) is right and the request-id gating on the editor side means the now-immediate empty result is discarded as an outdated response, so that one is safe.
The two I'd treat as blocking are the wrap-index gravity desync (#722 fix moves the drift from the renderer into WrapIndex's decoration snapshot) and the missing Unresponsive case in the crash predicate in handle_lsp_status_update (a stuck server that then dies no longer auto-restarts and leaves stale diagnostics on screen).
Generated by Claude Code
3d3a5cf to
e7bd096
Compare
…zed, keep inlay hints in place Two bugs where the UI told the user something that wasn't true, and one compatibility push (#2197, #722). with the client advertising `workspace.workspaceFolders` its `initialized` handler skipped `updateSettingsForAllWorkspaces()`, so the workspace never resolved and every request hung (microsoft/pyright#11239, fixed in 1.1.409). Other editors never saw it because their clients push a `workspace/didChangeConfiguration` right after `initialized` — VS Code, Neovim, Helix — and pyright's handler for that happens to do the same setup. Fresh now sends that notification once after `initialized`, with the same object `workspace/configuration` is answered from, so a server sees one configuration whichever way it asks. Verified against the real pyright 1.1.408: F12 jumps, hover works. What was Fresh's bug is that a silent server looked healthy: requests are cancelled after 30s, which is right, but the user saw only an empty result with `LSP (python) ready` on the bar throughout. Now an expired request the user made is named on the status bar (background traffic — inlay hints, diagnostics, semantic tokens, auto-triggered completion and signature help — stays off it); an empty result that follows an expiry of the same method says so instead of posing as an answer; and two expiries in a row with nothing answered between them put the server in a new `Unresponsive` status: `LSP (stuck)` on the pill, `(not responding)` in the servers popup, cleared by the first answered request. A server reporting `$/progress` keeps its spinner. `Unresponsive` counts as "was running" for the crash path. Cancelling a request now also drops its pending entry, so a superseded request resolves immediately instead of 30s later and never counts towards the streak. own anchor carried the hint along, so Enter after `d` in `let d = Duration::from_secs(5);` showed `: Duration` on the next line until the debounced refresh. The inlay-hint path now asks for a left-gravity marker (an explicit `MarkerGravity`, not inferred from `BeforeChar`: the paste placeholder is `BeforeChar` too and must keep travelling). Gravity travels into the wrap index as well — `IndexDecorations::shift_for_edit` shifted every anchor right-gravity by contract, which would have moved the drift into the coordinate service. Tests: the settings push follows `initialized` and precedes `didOpen` exactly once; user-invoked timeouts reach the status bar while background ones do not; an unresponsive server is not rendered as ready, recovers, and is still a crash if it dies while quiet; an empty result after a timeout says the request expired, only for that method, only once, and not after the server answered again; streak transitions; `LSP (stuck)` composition; Enter at a hint anchor keeps the hint on its line and matches the refreshed rendering; gravity contract and wrap-index shifting. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01SHsuKyMdSZ7soeFzDziRNw
e7bd096 to
d93e9a6
Compare
Fixes #2197. Fixes #722.
Before / after
#2197 — pyright 1.1.408 never answers
npm i [email protected], configurepyright-langserver --stdiofor Python, open a file withdef add(a, b): …and a calladd(1, 2); the status bar readsLSP (python) ready.addin the call, pressF12. ThenAlt+K.F12No definition found; status bar stillLSP (python) readydef addimmediatelyAlt+KNo hover information available; stillreadyThe server is unblocked by a
workspace/didChangeConfigurationpushed right afterinitialized, which VS Code, Neovim and Helix all send (details below). For a server that stays silent anyway — a stub that answersinitializeand nothing else reproduces it — the timeouts are no longer invisible:No definition found; status bar stillreadyLSP (python): 'textDocument/definition' timed out after 30sNo hover information available; stillreadyLSP (stuck)(warning colours);Alt+Kpopup shows◍ pyright-langserver (not responding)with Restart/StopLSP (on), popup row back to(ready)#722 — inlay hint jumps to the next line on Enter
let d = Duration::from_secs(5);shows the hint: Durationafterd.d(on the hint's anchor) and press Enter.The "after" frame is identical to what the refresh produces for the split buffer, which the regression test asserts directly.
#2197 — what changed
The hang is pyright 1.1.408's. With the client advertising
workspace.workspaceFolders, itsinitializedhandler skippedupdateSettingsForAllWorkspaces(), so the workspace created duringinitializenever resolved itsisInitializedpromise and every request that awaits it waits forever (microsoft/pyright#11239, shipped in 1.1.409; 1.1.408 was the only affected npm release, Jan 8 – Apr 23, 2026). Other editors never saw it because their clients push aworkspace/didChangeConfigurationright afterinitialized— VS Code viasynchronize.configurationSection, Neovim whensettingsis set, Helix whenconfigis set — and pyright's handler for that notification happens to call the sameupdateSettingsForAllWorkspaces(). Fresh sent no such notification and hit the bug head-on.Compatibility push. Fresh now sends
workspace/didChangeConfigurationonce, right afterinitialized, with the same object it answersworkspace/configurationfrom (the server'sinitialization_options, or{}), so a server sees one configuration whichever way it asks. Not required by the spec, but servers are written against the clients that do it. Verified against the real pyright 1.1.408 in tmux:F12jumps,Alt+Khovers.Visibility. What was Fresh's bug is that a silent server looked healthy. Requests are cancelled after 30s, which is correct, but the user saw only an empty result, indistinguishable from a symbol that genuinely has no definition, with
readyon the status bar throughout. Three surfaces now:LSP (python): no answer — 'textDocument/definition' timed out after 30sin place ofNo definition found. Keyed by method, consumed on use, and dropped when the server answers again, so it explains exactly one empty result and never a later, genuine one. Universal servers are matched by scope, since their records are labelled"universal"rather than by language.LspServerStatus::Unresponsive: theLSP (stuck)pill (same fixed width, nothing else on the bar shifts) and the(not responding)popup row. The first answered request clears it back toRunning, and both transitions re-render an open popup. A server reporting$/progresskeeps its spinner, so an indexing rust-analyzer or jdtls is never called stuck.Unresponsivealso counts as "was running" for the crash path, so a wedged server that then dies still gets its diagnostics cleared and its auto-restart.A request the editor cancels itself no longer counts towards that streak:
handle_cancel_requestwithdrew the request fromactive_requestsbut left the pending entry in place, so a server that ignores$/cancelRequestparked the requester for the full 30s and the expiry looked exactly like a hang — and the editor cancels superseded completion, definition and semantic-token requests on ordinary cursor movement. Cancelling now drops the pending entry, which also resolves the superseded requester immediately rather than 30s later.Open question:
UNRESPONSIVE_TIMEOUT_STREAK = 2and the "expired" phrasing are judgement calls, and something louder — a popup, or offering a restart when a server goes quiet — is a product decision I left alone. Also open, from review: classifying requests by method name is a proxy for what we actually want to know (did the user ask for this?), and threading that from the call site would be the real fix.#722 — what changed
Hints are byte-offset markers, and the marker was carried along by text inserted at the hint's own anchor. The inlay-hint path now asks for a left-gravity marker, so an insertion at the anchor stays behind the hint. Gravity is an explicit
MarkerGravityargument rather than something inferred fromBeforeChar/AfterChar: the two are not the same question. The async-paste placeholder is also aBeforeCharentry, but its marker is the eventual insertion point, so it must keep travelling with text typed at it.AfterCharhints keep right gravity, which the #1572 end-of-line anchoring relies on.Gravity travels with the decoration into the wrap index too.
IndexDecorations::shift_for_editkeeps its own copy of these anchors and shifted them all with right gravity by contract, so without this the index would have placed the hint on the next line while the renderer drew it on this one — moving the drift from the renderer into the coordinate service (row counts, cursor visual columns, scrollbar extent, h-scroll) for the same ~1s window.Scope note: this fixes the Enter-at-the-anchor case from the repro. Undo of that split still shows a brief one-column shift before the refresh lands — the marker survives the undo correctly, but the renderer's end-of-line hint padding differs by a space; a smaller artifact of the same class, not addressed here.
Tests
issue_2197_lsp_timeout_visible.rs— the settings push followsinitialized, precedes the firstdidOpen, and happens exactly once (logging fake server); a user-invoked timeout reaches the status bar while background and auto-triggered ones do not; an unresponsive server is not rendered as ready, recovers, and is still treated as a crash if it dies while quiet; an empty result after a timeout says the request expired, but only for the method that expired, only once, and not after the server has answered again.issue_722_inlay_hint_split_drift.rs— Enter at a hint anchor keeps the hint on its line and already matches the refreshed rendering; a parameter hint stays in front of text typed at its anchor. Both fail without the fix.view::virtual_textpins the gravity contract,view::wrap_indexpins that the index shifts each anchor by its own gravity, and the pre-existing marker-tracking test instate.rsis untouched from master because the paste anchor's behaviour is untouched.services::lsp::async_handler— unit tests for the streak transitions (first expiry, the crossing, reset by an answer, recovery reported once), which had no coverage.app::lsp_status::tests—LSP (stuck)for an unresponsive server, error still outranks it, pill width unchanged.Both issues were reproduced on master and re-verified after the fix by driving the editor interactively in tmux; the existing LSP handshake and ordering tests pass with the extra notification.
cargo fmt --checkandcargo clippy -p fresh-editor --all-targetsare clean on the touched files. Note for anyone reproducing locally: plaincargo testis not equivalent here —wait_untilhas no timeout and the orchestrator/SSH tests share process-global env, so they need nextest's process-per-test isolation.Two new user-facing strings (the timeout messages) are not routed through
t!, matching the LSP status messages beside them — including the"LSP ({}) ready"line this issue is about. The locale files are flat with a strict key-parity test, so localizing them means adding them to all fifteen locales; happy to do that if you'd rather they were translated from the start.🤖 Generated with Claude Code
https://claude.ai/code/session_01SHsuKyMdSZ7soeFzDziRNw