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',
|
2022-08-08 20:23:44 +02:00
|
|
|
requires = 'https://github.com/L3MON4D3/LuaSnip',
|
2022-08-08 13:57:38 +02:00
|
|
|
config = function()
|
|
|
|
map('n', '<f5>', vim.diagnostic.goto_prev)
|
|
|
|
map('n', '<f6>', vim.diagnostic.goto_next)
|
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)
|
2022-08-10 16:36:41 +02:00
|
|
|
maplsp('n', '<Leader>wa', vim.lsp.buf.add_workspace_folder)
|
|
|
|
maplsp('n', '<Leader>wr', vim.lsp.buf.remove_workspace_folder)
|
|
|
|
maplsp('n', '<Leader>wl', function()
|
2022-08-08 13:57:38 +02:00
|
|
|
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
|
|
|
end)
|
2022-08-10 16:36:41 +02:00
|
|
|
maplsp('n', '<Leader>rn', vim.lsp.buf.rename)
|
|
|
|
maplsp('n', '<Leader>ca', vim.lsp.buf.code_action)
|
2022-08-08 13:57:38 +02:00
|
|
|
maplsp('n', 'gr', vim.lsp.buf.references)
|
2022-08-10 16:36:41 +02:00
|
|
|
maplsp('n', '<Leader>f', vim.lsp.buf.formatting)
|
2022-08-10 16:24:04 +02:00
|
|
|
|
|
|
|
-- highlight symbol under cursor
|
|
|
|
if client.resolved_capabilities.document_highlight then
|
|
|
|
vim.cmd [[
|
|
|
|
hi! LspReferenceRead cterm=bold ctermbg=red guibg=#633466
|
|
|
|
hi! LspReferenceText cterm=bold ctermbg=red guibg=#633466
|
|
|
|
hi! LspReferenceWrite cterm=bold ctermbg=red guibg=#633466
|
|
|
|
]]
|
|
|
|
vim.api.nvim_create_augroup('lsp_document_highlight', {
|
|
|
|
clear = false
|
|
|
|
})
|
|
|
|
vim.api.nvim_clear_autocmds({
|
|
|
|
buffer = bufnr,
|
|
|
|
group = 'lsp_document_highlight',
|
|
|
|
})
|
|
|
|
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
|
|
|
|
group = 'lsp_document_highlight',
|
|
|
|
buffer = bufnr,
|
|
|
|
callback = vim.lsp.buf.document_highlight,
|
|
|
|
})
|
|
|
|
vim.api.nvim_create_autocmd('CursorMoved', {
|
|
|
|
group = 'lsp_document_highlight',
|
|
|
|
buffer = bufnr,
|
|
|
|
callback = vim.lsp.buf.clear_references,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
vim.api.nvim_create_autocmd("CursorHold", {
|
|
|
|
buffer = bufnr,
|
|
|
|
callback = function()
|
|
|
|
local opts = {
|
|
|
|
focusable = false,
|
|
|
|
close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" },
|
|
|
|
border = 'rounded',
|
|
|
|
source = 'always',
|
|
|
|
prefix = ' ',
|
|
|
|
scope = 'cursor',
|
|
|
|
}
|
|
|
|
vim.diagnostic.open_float(nil, opts)
|
|
|
|
end
|
|
|
|
})
|
2022-08-08 13:57:38 +02:00
|
|
|
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
|
2022-08-08 16:57:58 +02:00
|
|
|
},
|
|
|
|
on_attach = on_attach
|
2022-08-08 13:57:38 +02:00
|
|
|
}
|
|
|
|
end
|
2022-08-08 11:07:10 +02:00
|
|
|
}
|