config-nvim/lua/plugins/lsp.lua

128 lines
3.8 KiB
Lua

vim.opt.completeopt = "menu,menuone,noinsert"
local nvim_lsp = require'lspconfig'
local capabilities = require('cmp_nvim_lsp').default_capabilities()
local opts = {
capabilities = capabilities,
tools = { -- rust-tools options
autoSetHints = true,
inlay_hints = {
show_parameter_hints = false,
parameter_hints_prefix = "",
other_hints_prefix = "",
},
},
-- all the opts to send to nvim-lspconfig
-- these override the defaults set by rust-tools.nvim
-- see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer
server = {
-- on_attach is a callback called when the language server attachs to the buffer
-- on_attach = on_attach,
settings = {
-- to enable rust-analyzer settings visit:
-- https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc
["rust-analyzer"] = {
-- enable clippy on save
checkOnSave = {
command = "clippy"
},
}
}
},
}
require('rust-tools').setup(opts)
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
local servers = { 'pylsp', 'gdscript', 'ltex'}
for _, lsp in pairs(servers) do
require('lspconfig')[lsp].setup {
capabilities = capabilities,
on_attach = on_attach,
flags = {
-- This will be the default in neovim 0.7+
debounce_text_changes = 150,
}
}
end
-- Java LSP (WPILib broken :/)
require'lspconfig'.java_language_server.setup{ cmd = { "/home/erin/src/java-language-server/dist/lang_server_linux.sh" } }
-- Setup Completion
-- See https://github.com/hrsh7th/nvim-cmp#basic-configuration
local cmp = require'cmp'
cmp.setup({
-- Enable LSP snippets
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
-- Add tab support
['<S-Tab>'] = cmp.mapping.select_prev_item(),
['<Tab>'] = cmp.mapping.select_next_item(),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Insert,
select = true,
})
},
-- Installed sources
sources = {
{ name = 'nvim_lsp' },
{ name = 'vsnip' },
{ name = 'path' },
{ name = 'buffer' },
{ name = 'lua-latex-symbols', option = { cache = true } },
{ name = 'treesitter' },
},
})
local api = vim.api
-- set updatetime for CursorHold
-- 300ms of no cursor movement to trigger CursorHold
vim.opt.updatetime = 300
-- show diagnostic popup on cursor hold
api.nvim_create_autocmd("CursorHold", {
command = "lua vim.diagnostic.open_float(nil, { focusable = false })",
})
-- fixed column for the diagnostics to appear in
vim.opt.signcolumn = "yes"
-- auto-format *.rs (rust) files prior to saving them
api.nvim_create_autocmd("BufWritePre", {
pattern = "*.rs",
command = "lua vim.lsp.buf.formatting_sync(nil, 1000)",
})
-- Code navigation shortcutst
vim.keymap.set('n', 'K', function()
return vim.lsp.buf.hover()
end, { silent = true })
vim.keymap.set('n', 'gr', function()
return vim.lsp.buf.references()
end, { silent = true, buffer = true })
vim.keymap.set('n', 'gd', function()
return vim.lsp.buf.definition()
end, { silent = true, buffer = true })
vim.keymap.set('n', 'ga', function()
return vim.lsp.buf.code_action()
end, { silent = true, buffer = true })
vim.keymap.set('n', '1gD', function()
return vim.lsp.buf.type_definition()
end, { silent = true, buffer = true })