LSP 3.17 (#1306)
* 3.17 * PositionEncodingKind * Implement PositionEncodingKind * Remove luarc.json
This commit is contained in:
@@ -344,7 +344,10 @@ end, config.get().performance.throttle)
|
||||
---@param callback function
|
||||
core.confirm = function(self, e, option, callback)
|
||||
if not (e and not e.confirmed) then
|
||||
return callback()
|
||||
if callback then
|
||||
callback()
|
||||
end
|
||||
return
|
||||
end
|
||||
e.confirmed = true
|
||||
|
||||
@@ -357,9 +360,10 @@ core.confirm = function(self, e, option, callback)
|
||||
|
||||
feedkeys.call(keymap.indentkeys(), 'n')
|
||||
feedkeys.call('', 'n', function()
|
||||
-- Emulate `<C-y>` behavior to save `.` register.
|
||||
local ctx = context.new()
|
||||
local keys = {}
|
||||
table.insert(keys, keymap.backspace(ctx.cursor.character - misc.to_utfindex(ctx.cursor_line, e:get_offset())))
|
||||
table.insert(keys, keymap.backspace(ctx.cursor_before_line:sub(e:get_offset())))
|
||||
table.insert(keys, e:get_word())
|
||||
table.insert(keys, keymap.undobreak())
|
||||
feedkeys.call(table.concat(keys, ''), 'in')
|
||||
@@ -368,7 +372,7 @@ core.confirm = function(self, e, option, callback)
|
||||
local ctx = context.new()
|
||||
if api.is_cmdline_mode() then
|
||||
local keys = {}
|
||||
table.insert(keys, keymap.backspace(ctx.cursor.character - misc.to_utfindex(ctx.cursor_line, e:get_offset())))
|
||||
table.insert(keys, keymap.backspace(ctx.cursor_before_line:sub(e:get_offset())))
|
||||
table.insert(keys, string.sub(e.context.cursor_before_line, e:get_offset()))
|
||||
feedkeys.call(table.concat(keys, ''), 'in')
|
||||
else
|
||||
@@ -405,11 +409,15 @@ core.confirm = function(self, e, option, callback)
|
||||
return
|
||||
end
|
||||
vim.cmd([[silent! undojoin]])
|
||||
vim.lsp.util.apply_text_edits(text_edits, ctx.bufnr, 'utf-16')
|
||||
vim.lsp.util.apply_text_edits(text_edits, ctx.bufnr, e.source:get_position_encoding_kind())
|
||||
end)
|
||||
else
|
||||
vim.cmd([[silent! undojoin]])
|
||||
vim.lsp.util.apply_text_edits(e:get_completion_item().additionalTextEdits, ctx.bufnr, 'utf-16')
|
||||
vim.lsp.util.apply_text_edits(
|
||||
e:get_completion_item().additionalTextEdits,
|
||||
ctx.bufnr,
|
||||
e.source:get_position_encoding_kind()
|
||||
)
|
||||
end
|
||||
end)
|
||||
feedkeys.call('', 'n', function()
|
||||
@@ -426,30 +434,33 @@ core.confirm = function(self, e, option, callback)
|
||||
completion_item.textEdit.range = e:get_insert_range()
|
||||
end
|
||||
|
||||
local diff_before = math.max(0, e.context.cursor.character - completion_item.textEdit.range.start.character)
|
||||
local diff_after = math.max(0, completion_item.textEdit.range['end'].character - e.context.cursor.character)
|
||||
local diff_before = math.max(0, e.context.cursor.col - (completion_item.textEdit.range.start.character + 1))
|
||||
local diff_after = math.max(0, (completion_item.textEdit.range['end'].character + 1) - e.context.cursor.col)
|
||||
local new_text = completion_item.textEdit.newText
|
||||
|
||||
if api.is_insert_mode() then
|
||||
local is_snippet = completion_item.insertTextFormat == types.lsp.InsertTextFormat.Snippet
|
||||
completion_item.textEdit.range.start.line = ctx.cursor.line
|
||||
completion_item.textEdit.range.start.character = ctx.cursor.character - diff_before
|
||||
completion_item.textEdit.range.start.character = (e.context.cursor.col - 1) - diff_before
|
||||
completion_item.textEdit.range['end'].line = ctx.cursor.line
|
||||
completion_item.textEdit.range['end'].character = ctx.cursor.character + diff_after
|
||||
completion_item.textEdit.range['end'].character = (ctx.cursor.col - 1) + diff_after
|
||||
|
||||
local is_snippet = completion_item.insertTextFormat == types.lsp.InsertTextFormat.Snippet
|
||||
if is_snippet then
|
||||
completion_item.textEdit.newText = ''
|
||||
end
|
||||
vim.lsp.util.apply_text_edits({ completion_item.textEdit }, ctx.bufnr, 'utf-16')
|
||||
vim.lsp.util.apply_text_edits({ completion_item.textEdit }, ctx.bufnr, 'utf-8')
|
||||
|
||||
local texts = vim.split(completion_item.textEdit.newText, '\n')
|
||||
local position = completion_item.textEdit.range.start
|
||||
position.line = position.line + (#texts - 1)
|
||||
if #texts == 1 then
|
||||
position.character = position.character + misc.to_utfindex(texts[1])
|
||||
else
|
||||
position.character = misc.to_utfindex(texts[#texts])
|
||||
end
|
||||
local pos = types.lsp.Position.to_vim(0, position)
|
||||
vim.api.nvim_win_set_cursor(0, { pos.row, pos.col - 1 })
|
||||
vim.api.nvim_win_set_cursor(0, {
|
||||
completion_item.textEdit.range.start.line + #texts,
|
||||
(
|
||||
#texts == 1 and (
|
||||
completion_item.textEdit.range.start.character + #texts[1]
|
||||
) or (
|
||||
#texts[#texts]
|
||||
)
|
||||
)
|
||||
})
|
||||
if is_snippet then
|
||||
config.get().snippet.expand({
|
||||
body = new_text,
|
||||
@@ -458,8 +469,8 @@ core.confirm = function(self, e, option, callback)
|
||||
end
|
||||
else
|
||||
local keys = {}
|
||||
table.insert(keys, string.rep(keymap.t('<BS>'), diff_before))
|
||||
table.insert(keys, string.rep(keymap.t('<Del>'), diff_after))
|
||||
table.insert(keys, keymap.backspace(ctx.cursor_line:sub(completion_item.textEdit.range.start.character + 1, ctx.cursor.col - 1)))
|
||||
table.insert(keys, keymap.delete(ctx.cursor_line:sub(ctx.cursor.col, completion_item.textEdit.range['end'].character)))
|
||||
table.insert(keys, new_text)
|
||||
feedkeys.call(table.concat(keys, ''), 'in')
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user