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,
|
||||
|
||||
@@ -84,10 +84,20 @@ map('n', '<leader>E', cmd('NvimTreeOpen'))
|
||||
|
||||
-- Diagnostics
|
||||
map('n', ']d', function()
|
||||
vim.diagnostic.jump({ count = 1, float = true })
|
||||
vim.diagnostic.jump({
|
||||
count = 1,
|
||||
on_jump = function()
|
||||
vim.diagnostic.open_float()
|
||||
end,
|
||||
})
|
||||
end)
|
||||
map('n', '[d', function()
|
||||
vim.diagnostic.jump({ count = -1, float = true })
|
||||
vim.diagnostic.jump({
|
||||
count = -1,
|
||||
on_jump = function()
|
||||
vim.diagnostic.open_float()
|
||||
end,
|
||||
})
|
||||
end)
|
||||
map('n', '<leader>q', vim.diagnostic.setloclist)
|
||||
map('n', '<leader>d', vim.diagnostic.open_float)
|
||||
|
||||
@@ -86,7 +86,11 @@ vim.opt.hlsearch = true -- Highlight all matches after searching
|
||||
vim.opt.shortmess:remove('S') -- Show search count, e.g. [3/17]
|
||||
|
||||
vim.opt.inccommand = 'split' -- Preview substitutions live in a split
|
||||
vim.opt.completeopt = { 'fuzzy', 'menuone', 'popup', 'noselect' }
|
||||
vim.opt.autocomplete = true
|
||||
vim.opt.autocompletedelay = 60
|
||||
vim.opt.autocompletetimeout = 120
|
||||
vim.opt.complete = { 'o' }
|
||||
vim.opt.completeopt = { 'menuone', 'popup', 'noselect', 'noinsert' }
|
||||
|
||||
-- Splits
|
||||
vim.opt.splitright = true
|
||||
|
||||
Reference in New Issue
Block a user