diff options
| author | Étienne Robert <etiennerobert33@gmail.com> | 2026-08-24 14:41:57 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-24 08:41:57 -0400 |
| commit | 143bbfbb1239cba40b9adc52559c358aaa69a277 (patch) | |
| tree | c39c0442ae99df8afb01343249b011d1465582a6 /runtime/lua/vim/lsp/inline_completion.lua | |
| parent | 2a382ffb6173b14919acf3a430b7504eb5793063 (diff) | |
| download | rneovim-143bbfbb1239cba40b9adc52559c358aaa69a277.tar.gz rneovim-143bbfbb1239cba40b9adc52559c358aaa69a277.tar.bz2 rneovim-143bbfbb1239cba40b9adc52559c358aaa69a277.zip | |
fix(lsp): clamp inline completion range to the line on accept #41435
Problem:
`Completor:accept()` hands the item's range straight to
`nvim_buf_set_text()`. That range is resolved when the response arrives,
so text deleted before accepting (backspacing within the 200 ms
debounce) leaves the range end past what is left of the line, and the
accept aborts with `Invalid 'end_col': out of range`.
18d6436 fixed the same staleness in `Completor:show()`, which drops an
item once its range *start* falls outside the buffer. That guard does
not cover the range end, and `accept()` was never given one, so this is
a hole left by that fix rather than a regression of it.
Solution:
Clamp the end of the range to the end of the line before writing. The
start needs no clamp: `show()` dropped the item one event loop tick
earlier if it had gone out of range.
Diffstat (limited to 'runtime/lua/vim/lsp/inline_completion.lua')
| -rw-r--r-- | runtime/lua/vim/lsp/inline_completion.lua | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/runtime/lua/vim/lsp/inline_completion.lua b/runtime/lua/vim/lsp/inline_completion.lua index d016f678ea..bd7b771d52 100644 --- a/runtime/lua/vim/lsp/inline_completion.lua +++ b/runtime/lua/vim/lsp/inline_completion.lua @@ -342,6 +342,10 @@ function Completor:accept(item) if type(insert_text) == 'string' then if item.range then local start_row, start_col, end_row, end_col = item.range:to_extmark() + -- The line may have shrunk past the range since the item arrived. + local end_line = api.nvim_buf_get_lines(self.bufnr, end_row, end_row + 1, true)[1] + end_col = math.min(end_col, #end_line) + local lines = vim.split(insert_text, '\n') api.nvim_buf_set_text(self.bufnr, start_row, start_col, end_row, end_col, lines) local win = api.nvim_get_current_win() |