84 lines
2.4 KiB
Lua
84 lines
2.4 KiB
Lua
local status, lspconfig = pcall(require, "lspconfig")
|
|
if not status then return end
|
|
|
|
local util = require "lspconfig/util"
|
|
|
|
local status, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
|
|
if not status then return end
|
|
|
|
local capabilities = cmp_nvim_lsp.default_capabilities()
|
|
|
|
lspconfig.gopls.setup {
|
|
cmd = {"gopls", "serve"},
|
|
filetypes = {"go", "gomod"},
|
|
root_dir = util.root_pattern("go.work", "go.mod", ".git"),
|
|
settings = {
|
|
gopls = {
|
|
analyses = {
|
|
unusedparams = true,
|
|
},
|
|
staticcheck = true,
|
|
},
|
|
},
|
|
capabilites = capabilites,
|
|
}
|
|
|
|
lspconfig.rust_analyzer.setup {
|
|
-- Server-specific settings. See `:help lspconfig-setup`
|
|
settings = {
|
|
['rust-analyzer'] = {},
|
|
},
|
|
capabilites = capabilites,
|
|
}
|
|
|
|
lspconfig.tsserver.setup {
|
|
}
|
|
|
|
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float)
|
|
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
|
|
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
|
|
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist)
|
|
|
|
vim.api.nvim_create_autocmd('LspAttach', {
|
|
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
|
|
callback = function(ev)
|
|
-- Enable completion triggered by <c-x><c-o>
|
|
vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
|
|
|
|
-- Buffer local mappings.
|
|
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
|
local opts = { buffer = ev.buf }
|
|
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
|
|
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
|
|
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
|
|
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
|
|
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
|
|
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
|
|
vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
|
|
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
|
|
end,
|
|
})
|
|
|
|
local status, lspsignature = pcall(require, "lsp_signature")
|
|
if not status then return end
|
|
|
|
local cfg = {}
|
|
lspsignature.setup(cfg)
|
|
|
|
local status, cmp = pcall(require, "cmp")
|
|
if not status then return end
|
|
|
|
local status, luasnip = pcall(require, "luasnip")
|
|
if not status then return end
|
|
|
|
cmp.setup {
|
|
snippet = {
|
|
expand = function(args)
|
|
luasnip.lsp_expand(args.body)
|
|
end,
|
|
},
|
|
sources = {
|
|
{ name = 'nvim_lsp' },
|
|
{ name = 'luasnip' },
|
|
},
|
|
}
|