95 lines
3 KiB
Lua
95 lines
3 KiB
Lua
-- Nvim LSP Config
|
|
|
|
local map_opts = { noremap=true, silent=true }
|
|
|
|
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, map_opts)
|
|
vim.keymap.set('n', '<space>p', vim.diagnostic.goto_prev, map_opts)
|
|
vim.keymap.set('n', '<space>n', vim.diagnostic.goto_next, map_opts)
|
|
vim.keymap.set('n', '<space>l', vim.diagnostic.setloclist, map_opts)
|
|
|
|
|
|
-- Enable keybinds on LSP server attach
|
|
local on_attach = function(client, bufnr)
|
|
-- Enable completion triggered by <C-x><C-o>
|
|
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
|
|
|
|
-- Mappings
|
|
local bufopts = { noremap=true, silent=true, buffer=bufnr }
|
|
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
|
|
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
|
|
vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
|
|
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
|
|
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
|
|
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts)
|
|
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
|
|
vim.keymap.set('n', '<space>wl', function()
|
|
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
|
end, bufopts)
|
|
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
|
|
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
|
|
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
|
|
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
|
|
vim.keymap.set('n', '<space>f', function() vim.lsp.buf.format { async = true } end, bufopts)
|
|
end
|
|
|
|
-- Set-up autocompletion
|
|
|
|
local cmp = require('cmp')
|
|
vim.opt.completeopt = {'menu', 'menuone', 'noselect'}
|
|
|
|
cmp.setup({
|
|
snippet = {
|
|
-- Necessary snippet engine
|
|
expand = function (args)
|
|
vim.fn["vsnip#anonymous"](args.body)
|
|
end,
|
|
},
|
|
|
|
window = {
|
|
-- completion = cmp.config.window.bordered(),
|
|
-- documentation = cmp.config.window.bordered,
|
|
},
|
|
|
|
mapping = cmp.mapping.preset.insert({
|
|
['<C-u>'] = cmp.mapping.scroll_docs(4),
|
|
['<C-d>'] = cmp.mapping.scroll_docs(-4),
|
|
['<C-Space>'] = cmp.mapping.complete(),
|
|
['<C-e>'] = cmp.mapping.abort(),
|
|
['<CR>'] = cmp.mapping.confirm({select = true}),
|
|
}),
|
|
|
|
sources = cmp.config.sources({
|
|
{ name = 'nvim_lsp' },
|
|
{ name = 'vsnip' },
|
|
}, { { name = 'buffer' } }),
|
|
})
|
|
|
|
|
|
-- Language servers setup
|
|
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
|
|
|
require('lspconfig')['rust_analyzer'].setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
}
|
|
|
|
require('lspconfig')['rnix'].setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities
|
|
}
|
|
|
|
require('lspconfig')["nil_ls"].setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities
|
|
}
|
|
|
|
require('lspconfig')['ltex'].setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities
|
|
}
|
|
|
|
require('lspconfig')['texlab'].setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities
|
|
}
|