Preserve 'buflisted' state when applying LSP text edits (#2141)
This commit is contained in:
@@ -433,11 +433,11 @@ core.confirm = function(self, e, option, callback)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
vim.cmd([[silent! undojoin]])
|
vim.cmd([[silent! undojoin]])
|
||||||
vim.lsp.util.apply_text_edits(text_edits, ctx.bufnr, e.source:get_position_encoding_kind())
|
api.apply_text_edits(text_edits, ctx.bufnr, e.source:get_position_encoding_kind())
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
vim.cmd([[silent! undojoin]])
|
vim.cmd([[silent! undojoin]])
|
||||||
vim.lsp.util.apply_text_edits(e.completion_item.additionalTextEdits, ctx.bufnr, e.source:get_position_encoding_kind())
|
api.apply_text_edits(e.completion_item.additionalTextEdits, ctx.bufnr, e.source:get_position_encoding_kind())
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
feedkeys.call('', 'n', function()
|
feedkeys.call('', 'n', function()
|
||||||
@@ -486,7 +486,7 @@ core.confirm = function(self, e, option, callback)
|
|||||||
if is_snippet then
|
if is_snippet then
|
||||||
completion_item.textEdit.newText = ''
|
completion_item.textEdit.newText = ''
|
||||||
end
|
end
|
||||||
vim.lsp.util.apply_text_edits({ completion_item.textEdit }, ctx.bufnr, 'utf-8')
|
api.apply_text_edits({ completion_item.textEdit }, ctx.bufnr, 'utf-8')
|
||||||
|
|
||||||
local texts = vim.split(completion_item.textEdit.newText, '\n')
|
local texts = vim.split(completion_item.textEdit.newText, '\n')
|
||||||
vim.api.nvim_win_set_cursor(0, {
|
vim.api.nvim_win_set_cursor(0, {
|
||||||
|
|||||||
@@ -67,4 +67,15 @@ api.get_cursor_before_line = function()
|
|||||||
return string.sub(api.get_current_line(), 1, cursor[2])
|
return string.sub(api.get_current_line(), 1, cursor[2])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Applies a list of text edits to a buffer. Preserves 'buflisted' state.
|
||||||
|
---@param text_edits lsp.TextEdit[]
|
||||||
|
---@param bufnr integer Buffer id
|
||||||
|
---@param position_encoding 'utf-8'|'utf-16'|'utf-32'
|
||||||
|
api.apply_text_edits = function(text_edits, bufnr, position_encoding)
|
||||||
|
-- preserve 'buflisted' state because vim.lsp.util.apply_text_edits forces it to true
|
||||||
|
local prev_buflisted = vim.bo[bufnr].buflisted
|
||||||
|
vim.lsp.util.apply_text_edits(text_edits, bufnr, position_encoding)
|
||||||
|
vim.bo[bufnr].buflisted = prev_buflisted
|
||||||
|
end
|
||||||
|
|
||||||
return api
|
return api
|
||||||
|
|||||||
Reference in New Issue
Block a user