dotfiles/.config/nvim/lua/lsp.lua

50 lines
2.0 KiB
Lua
Raw Normal View History

2022-08-08 11:07:10 +02:00
require('plugins')
require('keymaps')
2022-08-08 20:27:58 +02:00
packer.use {
2022-08-08 13:57:38 +02:00
'https://github.com/neovim/nvim-lspconfig',
requires = 'https://github.com/L3MON4D3/LuaSnip',
2022-08-08 13:57:38 +02:00
config = function()
2022-08-08 14:52:28 +02:00
map('n', '<space>e', vim.diagnostic.open_float)
2022-08-08 13:57:38 +02:00
map('n', '<f5>', vim.diagnostic.goto_prev)
map('n', '<f6>', vim.diagnostic.goto_next)
2022-08-08 14:52:28 +02:00
map('n', '<space>q', vim.diagnostic.setloclist)
2022-08-08 11:07:10 +02:00
2022-08-08 13:57:38 +02:00
-- Only map the following keys after the language server attaches to the
-- current buffer
local on_attach = function(client, bufnr)
local function maplsp(mode, shortcut, command)
vim.keymap.set(mode, shortcut, command,
{ noremap = true, silent = true, buffer=bufnr })
end
2022-08-08 11:07:10 +02:00
2022-08-08 13:57:38 +02:00
maplsp('n', 'gD', vim.lsp.buf.declaration)
maplsp('n', 'gd', vim.lsp.buf.definition)
maplsp('n', 'K', vim.lsp.buf.hover)
maplsp('n', 'gi', vim.lsp.buf.implementation)
maplsp('n', '<C-k>', vim.lsp.buf.signature_help)
maplsp('n', '<space>wa', vim.lsp.buf.add_workspace_folder)
maplsp('n', '<space>wr', vim.lsp.buf.remove_workspace_folder)
maplsp('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end)
maplsp('n', '<space>D', vim.lsp.buf.type_definition)
maplsp('n', '<space>rn', vim.lsp.buf.rename)
maplsp('n', '<space>ca', vim.lsp.buf.code_action)
maplsp('n', 'gr', vim.lsp.buf.references)
maplsp('n', '<space>f', vim.lsp.buf.formatting)
end
2022-08-08 11:07:10 +02:00
2022-08-08 13:57:38 +02:00
-- setup servers
require'lspconfig'.clangd.setup{
cmd = {
'clangd',
'--compile-commands-dir=build',
'--clang-tidy', -- needs >=clangd-9
'--ranking-model=decision_forest' -- needs >=clangd-12
},
on_attach = on_attach
2022-08-08 13:57:38 +02:00
}
end
2022-08-08 11:07:10 +02:00
}