94 lines
2.5 KiB
Lua
94 lines
2.5 KiB
Lua
--
|
|
--
|
|
-- Completion config
|
|
--
|
|
--
|
|
|
|
|
|
vim.o.completeopt = "menu,menuone,noinsert,fuzzy"
|
|
|
|
vim.api.nvim_set_keymap("i", "<C-Space>", "<C-x><C-o>", { noremap = true })
|
|
|
|
vim.api.nvim_create_autocmd('LspAttach', {
|
|
group = vim.api.nvim_create_augroup('my.lsp', {}),
|
|
callback = function(args)
|
|
local client = assert(vim.lsp.get_client_by_id(args.data.client_id))
|
|
|
|
-- Make tab accept the selected completion
|
|
vim.keymap.set('i', '<Tab>', function()
|
|
if vim.fn.pumvisible() == 1 then
|
|
return '<C-y>'
|
|
else
|
|
return '<Tab>'
|
|
end
|
|
end, { expr = true })
|
|
|
|
-- Make enter just insert a newline (don't accept completion)
|
|
vim.keymap.set('i', '<CR>', function()
|
|
if vim.fn.pumvisible() == 1 then
|
|
return '<C-e><CR>'
|
|
else
|
|
return '<CR>'
|
|
end
|
|
end, { expr = true })
|
|
|
|
if client:supports_method('textDocument/completion') then
|
|
-- Trigger autocompletion on every keypress
|
|
local chars = {}; for i = 32, 126 do table.insert(chars, string.char(i)) end
|
|
client.server_capabilities.completionProvider.triggerCharacters = chars
|
|
|
|
vim.lsp.completion.enable(true, client.id, args.buf, { autotrigger = true })
|
|
end
|
|
|
|
vim.keymap.set('n', '<M-L>',
|
|
function() vim.lsp.buf.format() end, {
|
|
desc = "Format",
|
|
noremap = true,
|
|
silent = true
|
|
})
|
|
vim.keymap.set('i', '<M-L>',
|
|
function() vim.lsp.buf.format() end, {
|
|
desc = "Format",
|
|
noremap = true,
|
|
silent = true
|
|
})
|
|
|
|
vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, { desc = "Go to definition" })
|
|
end,
|
|
})
|
|
|
|
|
|
--
|
|
--
|
|
-- Diagnostics config
|
|
--
|
|
--
|
|
|
|
|
|
vim.diagnostic.config({
|
|
virtual_text = true,
|
|
severity_sort = true,
|
|
})
|
|
|
|
vim.api.nvim_create_autocmd("CursorHold", {
|
|
callback = function()
|
|
local width = vim.api.nvim_win_get_width(0);
|
|
|
|
vim.diagnostic.open_float(nil, {
|
|
scope = "cursor",
|
|
close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" },
|
|
source = true,
|
|
relative = "editor",
|
|
width = 40,
|
|
focusable = false,
|
|
focused = false,
|
|
border = "rounded",
|
|
title = "Diagnostics",
|
|
header = "",
|
|
title_pos = "center",
|
|
offset_x = width,
|
|
offset_y = -1,
|
|
})
|
|
end,
|
|
})
|