2021-11-26 18:19:36 +02:00
|
|
|
local lsp_installer = require("nvim-lsp-installer")
|
|
|
|
|
2022-03-02 23:15:00 +02:00
|
|
|
local M = {}
|
|
|
|
|
|
|
|
M.lsp_map_keys = function(server, bufnr)
|
2022-03-02 20:19:11 +02:00
|
|
|
local function map_key(...)
|
|
|
|
-- Map to buffer if buffer number is supplied,
|
|
|
|
-- globally otherwise
|
|
|
|
if bufnr == nil then
|
|
|
|
vim.api.nvim_set_keymap(...)
|
|
|
|
else
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, ...)
|
|
|
|
end
|
2021-11-27 10:25:59 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local keymapOpts = {noremap = true, silent = true}
|
2022-03-02 20:19:11 +02:00
|
|
|
map_key('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', keymapOpts)
|
|
|
|
map_key('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', keymapOpts)
|
|
|
|
map_key('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', keymapOpts)
|
|
|
|
map_key('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', keymapOpts)
|
|
|
|
map_key('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>',
|
|
|
|
keymapOpts)
|
|
|
|
map_key('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>',
|
|
|
|
keymapOpts)
|
|
|
|
map_key('n', '<space>wr',
|
|
|
|
'<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', keymapOpts)
|
|
|
|
map_key('n', '<space>wl',
|
|
|
|
'<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>',
|
|
|
|
keymapOpts)
|
|
|
|
map_key('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>',
|
|
|
|
keymapOpts)
|
|
|
|
map_key('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', keymapOpts)
|
|
|
|
map_key('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>',
|
|
|
|
keymapOpts)
|
|
|
|
map_key('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', keymapOpts)
|
|
|
|
map_key('n', '<space>e',
|
|
|
|
'<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>',
|
|
|
|
keymapOpts)
|
|
|
|
map_key('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', keymapOpts)
|
|
|
|
map_key('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', keymapOpts)
|
|
|
|
map_key('n', '<space>q', '<cmd>lua vim.diagnostic.set_loclist()<CR>',
|
|
|
|
keymapOpts)
|
|
|
|
map_key('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', keymapOpts)
|
2021-11-27 10:25:59 +02:00
|
|
|
end
|
|
|
|
|
2022-02-24 17:27:49 +02:00
|
|
|
-- Add additional capabilities supported by nvim-cmp
|
|
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
|
|
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
|
|
|
|
|
2021-11-26 18:19:36 +02:00
|
|
|
-- Register a handler that will be called for all installed servers.
|
|
|
|
lsp_installer.on_server_ready(function(server)
|
2022-02-24 18:08:59 +02:00
|
|
|
-- Don't setup jdtls here since it is done by nvim-jdtls
|
|
|
|
if server.name == "jdtls" then return end
|
|
|
|
|
2021-11-26 18:19:36 +02:00
|
|
|
local opts = {}
|
|
|
|
|
2021-11-27 10:25:59 +02:00
|
|
|
-- Lua specific settings
|
2021-12-04 11:43:26 +02:00
|
|
|
if server.name == "sumneko_lua" then
|
2021-11-26 18:19:36 +02:00
|
|
|
local runtime_path = vim.split(package.path, ';')
|
2021-11-27 10:25:59 +02:00
|
|
|
opts.settings = {
|
|
|
|
Lua = {
|
|
|
|
runtime = {
|
|
|
|
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
|
|
|
|
version = 'LuaJIT',
|
|
|
|
-- Setup your lua path
|
|
|
|
path = runtime_path
|
|
|
|
},
|
|
|
|
diagnostics = {
|
|
|
|
-- Get the language server to recognize the `vim` global
|
|
|
|
globals = {'vim'}
|
|
|
|
},
|
|
|
|
workspace = {
|
|
|
|
-- Make the server aware of Neovim runtime files
|
|
|
|
library = vim.api.nvim_get_runtime_file("", true)
|
|
|
|
},
|
|
|
|
-- Do not send telemetry data containing a randomized but unique identifier
|
|
|
|
telemetry = {enable = false}
|
2021-08-08 15:33:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
2021-11-29 16:19:53 +02:00
|
|
|
|
2022-03-02 23:16:25 +02:00
|
|
|
opts.on_attach = M.lsp_map_keys
|
2022-02-24 18:08:59 +02:00
|
|
|
opts.capabilities = capabilities
|
2021-11-29 16:19:53 +02:00
|
|
|
server:setup(opts)
|
2021-11-26 18:19:36 +02:00
|
|
|
end)
|
2022-03-02 23:15:00 +02:00
|
|
|
|
|
|
|
return M
|