dotvim/lua/config/lsp.lua

90 lines
3.2 KiB
Lua
Raw Normal View History

2022-10-23 06:15:22 +00:00
-- neodev.nvim
local neodev_nvim = require('neodev')
2022-10-25 05:17:21 +00:00
neodev_nvim.setup({})
2022-10-23 06:15:22 +00:00
2022-10-25 05:17:21 +00:00
-- cmp-nvim-lsp
local cmp_nvim_lsp = require('cmp_nvim_lsp')
local capabilities = cmp_nvim_lsp.default_capabilities({snippetSupport = false})
2022-10-22 05:45:38 +00:00
2022-10-25 05:17:21 +00:00
-- nvim-lspconfig
local nvim_lspconfig = require('lspconfig')
2022-11-16 04:20:48 +00:00
if vim.fn.executable('clangd') then
nvim_lspconfig.clangd.setup({capabilities = capabilities})
end
if vim.fn.executable('gopls') then
nvim_lspconfig.gopls.setup({capabilities = capabilities})
end
if vim.fn.executable('jedi-language-server') then
nvim_lspconfig.jedi_language_server.setup({capabilities = capabilities})
end
if vim.fn.executable('typescript-language-server') then
nvim_lspconfig.tsserver.setup({capabilities = capabilities})
end
if vim.fn.executable('lua-language-server') then
2023-02-20 23:28:56 +00:00
local runtime_path = vim.split(package.path, ';', {})
2023-01-23 02:31:05 +00:00
table.insert(runtime_path, 'lua/?.lua')
table.insert(runtime_path, 'lua/?/init.lua')
2023-02-20 23:28:56 +00:00
nvim_lspconfig.lua_ls.setup({
2022-11-16 04:20:48 +00:00
settings = {
Lua = {
2023-01-23 02:31:05 +00:00
diagnostics = {
globals = {'vim'},
2023-02-20 23:41:18 +00:00
disable = {'param-type-mismatch', 'undefined-field'},
2023-01-23 02:31:05 +00:00
},
runtime = {
path = runtime_path,
version = 'LuaJIT',
},
telemetry = {
enable = false,
},
workspace = {
checkThirdParty = false,
library = vim.api.nvim_get_runtime_file('', true),
},
2022-11-16 04:20:48 +00:00
},
2022-10-22 05:45:38 +00:00
},
2022-11-16 04:20:48 +00:00
})
end
2022-10-22 05:45:38 +00:00
2023-09-22 19:29:25 +00:00
vim.keymap.set('n', '<C-s>', vim.lsp.buf.signature_help)
2022-10-25 05:17:21 +00:00
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition)
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action)
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float)
vim.keymap.set('n', '<space>f', function() vim.lsp.buf.format({async = true}) end)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename)
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder)
vim.keymap.set('n', '<space>wl', function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder)
vim.keymap.set('n', 'K', vim.lsp.buf.hover)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation)
vim.keymap.set('n', 'gr', vim.lsp.buf.references)
2022-10-22 05:45:38 +00:00
2022-10-25 05:17:21 +00:00
vim.opt.omnifunc = 'v:lua.vim.lsp.omnifunc'
2022-10-22 05:45:38 +00:00
-- nvim-cmp
local nvim_cmp = require('cmp')
2022-10-25 05:17:21 +00:00
nvim_cmp.setup({
mapping = {
['<c-d>'] = nvim_cmp.mapping.scroll_docs(-4),
['<c-f>'] = nvim_cmp.mapping.scroll_docs(4),
['<c-n>'] = nvim_cmp.mapping.select_next_item(),
['<c-p>'] = nvim_cmp.mapping.select_prev_item(),
['<tab>'] = nvim_cmp.mapping.confirm({ select = true }),
},
sources = {
{name = 'nvim_lsp'},
{name = 'vsnip'},
2022-12-07 04:21:40 +00:00
{name = "nvim_lsp_signature_help"},
2022-10-25 05:17:21 +00:00
},
snippet = {
expand = function(args) vim.fn['vsnip#anonymous'](args.body) end,
},
})