feat(lsp): support annotated text edits (#34508)

This commit is contained in:
Maria José Solano
2025-06-23 06:30:49 -07:00
committed by GitHub
parent a5c55d200b
commit 835f11595f
5 changed files with 202 additions and 94 deletions

View File

@ -2069,13 +2069,16 @@ describe('LSP', function()
end)
describe('apply_text_edits', function()
local buffer_text = {
'First line of text',
'Second line of text',
'Third line of text',
'Fourth line of text',
'å å ɧ 汉语 ↥ 🤦 🦄',
}
before_each(function()
insert(dedent([[
First line of text
Second line of text
Third line of text
Fourth line of text
å å ɧ 汉语 ↥ 🤦 🦄]]))
insert(dedent(table.concat(buffer_text, '\n')))
end)
it('applies simple edits', function()
@ -2226,6 +2229,34 @@ describe('LSP', function()
eq({ 2, 1 }, api.nvim_buf_get_mark(1, 'a'))
end)
it('applies edit based on confirmation response', function()
--- @type lsp.AnnotatedTextEdit
local edit = make_edit(0, 0, 5, 0, 'foo')
edit.annotationId = 'annotation-id'
local function test(response)
exec_lua(function()
---@diagnostic disable-next-line: duplicate-set-field
vim.fn.confirm = function()
return response
end
vim.lsp.util.apply_text_edits(
{ edit },
1,
'utf-16',
{ ['annotation-id'] = { label = 'Insert "foo"', needsConfirmation = true } }
)
end, { response })
end
test(2) -- 2 = No
eq(buffer_text, buf_lines(1))
test(1) -- 1 = Yes
eq({ 'foo' }, buf_lines(1))
end)
describe('cursor position', function()
it("don't fix the cursor if the range contains the cursor", function()
api.nvim_win_set_cursor(0, { 2, 6 })