diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-11 08:37:31 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-11 08:37:31 +0300 |
| commit | dc8f0ab28276fac6aa16c0cf3591c322367036b7 (patch) | |
| tree | 46337a37ade2b02a6ecaac7811450df9f8f4540f /internal/askcli/command_write_test.go | |
| parent | e95f3fdf0a66ba05ba2c8fb7e755e107f9cf7991 (diff) | |
Fix LSP panic: bounds-check stale line index in async chat apply
When handleChatPrompt detects an in-editor chat prompt it captures the
line index, then spawns a goroutine (requestChatResponse) that later
calls applyChatEdits/buildChatHistory. If a concurrent didChange shrinks
the document in the meantime, the captured lineIdx can exceed
len(d.lines), causing an index-out-of-range panic in the chat goroutine.
- applyChatEdits: skip the stale edit (and log) when lineIdx is < 0 or
>= len(d.lines), rather than indexing d.lines[lineIdx] and panicking
(or corrupting the already-changed document at the wrong position).
- buildChatHistory: clamp the starting index to len(d.lines)-1 so the
upward walk over d.lines[i] cannot read past the end.
Adds regression test TestChatEdits_StaleLineIndexAfterShrink covering
the shrink-then-apply race for both functions, including the
one-past-the-end boundary and a negative index. Confirmed the test
panics without the fix and passes with it; full `mage test` (-race) green.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'internal/askcli/command_write_test.go')
0 files changed, 0 insertions, 0 deletions
