Migrate Neovim config to 0.12
This commit is contained in:
@@ -92,7 +92,7 @@ au('VimEnter', {
|
||||
au('TextYankPost', {
|
||||
group = group,
|
||||
callback = function()
|
||||
vim.highlight.on_yank({ timeout = 200 })
|
||||
vim.hl.on_yank({ timeout = 200 })
|
||||
end,
|
||||
})
|
||||
|
||||
@@ -131,6 +131,43 @@ au({ 'WinLeave', 'InsertEnter' }, {
|
||||
})
|
||||
|
||||
-- Autocompletion
|
||||
local function convert_completion_item(item)
|
||||
local converted = {}
|
||||
|
||||
if item.kind then
|
||||
local kind = vim.lsp.protocol.CompletionItemKind[item.kind] or ''
|
||||
converted.menu = '[' .. kind .. ']'
|
||||
end
|
||||
|
||||
local _, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
local next_char = vim.api.nvim_get_current_line():sub(col + 1, col + 1)
|
||||
if next_char ~= '"' and next_char ~= "'" then
|
||||
return converted
|
||||
end
|
||||
|
||||
local completion_text
|
||||
if item.textEdit then
|
||||
completion_text = item.textEdit.newText
|
||||
elseif item.insertText and item.insertText ~= '' then
|
||||
completion_text = item.insertText
|
||||
else
|
||||
completion_text = item.label
|
||||
end
|
||||
|
||||
if completion_text and completion_text:sub(-1) == next_char then
|
||||
local trimmed = completion_text:sub(1, -2)
|
||||
converted.word = trimmed
|
||||
|
||||
if item.textEdit and item.textEdit.newText == completion_text then
|
||||
item.textEdit.newText = trimmed
|
||||
elseif item.insertText == completion_text then
|
||||
item.insertText = trimmed
|
||||
end
|
||||
end
|
||||
|
||||
return converted
|
||||
end
|
||||
|
||||
au('LspAttach', {
|
||||
group = group,
|
||||
callback = function(event)
|
||||
@@ -141,22 +178,12 @@ au('LspAttach', {
|
||||
|
||||
-- Enable native completion
|
||||
if client:supports_method('textDocument/completion') then
|
||||
vim.lsp.completion.enable(true, client.id, event.buf, { autotrigger = true })
|
||||
vim.lsp.completion.enable(true, client.id, event.buf, {
|
||||
convert = convert_completion_item,
|
||||
})
|
||||
end
|
||||
end,
|
||||
})
|
||||
vim.lsp.handlers['textDocument/completion'] = function(err, result, ctx, config)
|
||||
if err or not result then
|
||||
return
|
||||
end
|
||||
for _, item in ipairs(result.items or result) do
|
||||
if item.kind then
|
||||
local kind = vim.lsp.protocol.CompletionItemKind[item.kind] or ''
|
||||
item.menu = '[' .. kind .. ']'
|
||||
end
|
||||
end
|
||||
return vim.lsp.completion._on_completion_result(err, result, ctx, config)
|
||||
end
|
||||
|
||||
au('InsertEnter', {
|
||||
group = group,
|
||||
|
||||
Reference in New Issue
Block a user