97 lines
3.2 KiB
Lua
97 lines
3.2 KiB
Lua
-- Set up LSP
|
|
|
|
local lsp_configs = {}
|
|
|
|
for _, f in pairs(vim.api.nvim_get_runtime_file('lsp/*.lua', true)) do
|
|
local server_name = vim.fn.fnamemodify(f, ':t:r')
|
|
table.insert(lsp_configs, server_name)
|
|
end
|
|
|
|
vim.lsp.enable(lsp_configs)
|
|
|
|
|
|
vim.o.completeopt = "menu,menuone,noinsert,fuzzy"
|
|
vim.api.nvim_set_keymap("i", "<C-Space>", "<C-x><C-o>", { noremap = true })
|
|
|
|
|
|
-- TODO: Put this somewhere sensible
|
|
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 })
|
|
|
|
-- Enable auto-completion. Note: Use CTRL-Y to select an item. |complete_CTRL-Y|
|
|
if client:supports_method('textDocument/completion') then
|
|
-- Trigger autocompletion on EVERY keypress. May be slow!
|
|
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"
|
|
})
|
|
|
|
vim.keymap.set("n", "grr", ":Trouble lsp_references<CR>", {
|
|
desc = "Show references"
|
|
})
|
|
|
|
-- if client:supports_method('textDocument/implementation') then
|
|
-- -- Create a keymap for vim.lsp.buf.implementation ...
|
|
-- end
|
|
|
|
-- -- Auto-format ("lint") on save.
|
|
-- -- Usually not needed if server supports "textDocument/willSaveWaitUntil".
|
|
-- if not client:supports_method('textDocument/willSaveWaitUntil')
|
|
-- and client:supports_method('textDocument/formatting') then
|
|
-- vim.api.nvim_create_autocmd('BufWritePre', {
|
|
-- group = vim.api.nvim_create_augroup('my.lsp', { clear = false }),
|
|
-- buffer = args.buf,
|
|
-- callback = function()
|
|
-- vim.lsp.buf.format({ bufnr = args.buf, id = client.id, timeout_ms = 1000 })
|
|
-- end,
|
|
-- })
|
|
-- end
|
|
end,
|
|
})
|
|
|
|
-- vim.diagnostic.config({
|
|
-- virtual_lines = {
|
|
-- current_line = true,
|
|
-- },
|
|
-- })
|