From 143bbfbb1239cba40b9adc52559c358aaa69a277 Mon Sep 17 00:00:00 2001 From: Étienne Robert Date: Mon, 24 Aug 2026 14:41:57 +0200 Subject: 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. --- test/functional/plugin/lsp/inline_completion_spec.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/functional/plugin/lsp/inline_completion_spec.lua') diff --git a/test/functional/plugin/lsp/inline_completion_spec.lua b/test/functional/plugin/lsp/inline_completion_spec.lua index 529f0b4126..5383480437 100644 --- a/test/functional/plugin/lsp/inline_completion_spec.lua +++ b/test/functional/plugin/lsp/inline_completion_spec.lua @@ -280,6 +280,19 @@ describe('vim.lsp.inline_completion', function() }, }, result) end) + + it('accepts an item after the line shrank past its range', function() + feed('i') + screen:expect({ grid = grid_with_candidates }) + exec_lua(function() + -- Shrink the line the item's range covers, as backspacing would. + vim.api.nvim_buf_set_text(0, 0, 18, 0, 20, {}) + vim.lsp.inline_completion.get() + end) + n.poke_eventloop() + feed('') + screen:expect({ grid = grid_applied_candidates }) + end) end) describe('select()', function() -- cgit