dotfiles/.config/nvim/lua/my/lsp.lua
tastytea 4615f1f9c5
nvim: declare all plugins in one file
Having it in many files is logically nicer, but breaks on fresh
installs.
2022-08-15 04:06:26 +02:00

165 lines
5.2 KiB
Lua

require('my/plugins')
require('my/keymaps')
require('my/completion')
-- only do this after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
local function map(mode, shortcut, command) -- overwrite function in keymaps
vim.keymap.set(mode, shortcut, command, {
noremap = true, silent = true, buffer=bufnr })
end
map('n', '<f5>', vim.diagnostic.goto_prev)
map('n', '<f6>', vim.diagnostic.goto_next)
map('n', 'gD', vim.lsp.buf.declaration)
map('n', 'gd', vim.lsp.buf.definition)
map('n', '<M-.>', vim.lsp.buf.definition)
map('n', 'gi', vim.lsp.buf.implementation)
map('n', 'gr', vim.lsp.buf.references)
map('n', 'K', vim.lsp.buf.hover)
map('n', '<C-k>', vim.lsp.buf.signature_help)
map('n', '<Leader>lwa', vim.lsp.buf.add_workspace_folder)
map('n', '<Leader>lwr', vim.lsp.buf.remove_workspace_folder)
map('n', '<Leader>lwl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end)
map('n', '<Leader>lr', vim.lsp.buf.rename)
map('n', '<Leader>la', vim.lsp.buf.code_action)
map('n', '<Leader>lf', vim.lsp.buf.formatting)
-- highlight symbol under cursor
if client.resolved_capabilities.document_highlight then
vim.cmd [[
execute "hi! LspReferenceRead cterm=bold ctermbg=".g:amora#palette.comment[1]." guibg=".g:amora#palette.comment[0]
execute "hi! LspReferenceText cterm=bold ctermbg=".g:amora#palette.comment[1]." guibg=".g:amora#palette.comment[0]
execute "hi! LspReferenceWrite cterm=bold ctermbg=".g:amora#palette.comment[1]." guibg=".g:amora#palette.comment[0]
]]
vim.api.nvim_create_augroup('config_lsp', { clear = false })
vim.api.nvim_clear_autocmds({
buffer = bufnr,
group = 'config_lsp',
})
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
group = 'config_lsp',
buffer = bufnr,
callback = vim.lsp.buf.document_highlight,
})
vim.api.nvim_create_autocmd('CursorMoved', {
group = 'config_lsp',
buffer = bufnr,
callback = vim.lsp.buf.clear_references,
})
end
-- -- show help on hover -- cursor ends up in popup
-- if client.resolved_capabilities.hover then
-- vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
-- group = 'config_lsp',
-- buffer = bufnr,
-- callback = function()
-- vim.lsp.buf.hover({ focusable = false })
-- end
-- })
-- end
end
-- update client capabilities with completion plugin stuff
local capabilities = require('cmp_nvim_lsp').update_capabilities(
vim.lsp.protocol.make_client_capabilities())
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(
vim.lsp.handlers.hover, {
border = "rounded",
width = 60,
})
-- setup servers
if vim.fn.executable('clangd') > 0 then
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,
capabilities = capabilities
}
end
if vim.fn.executable('lua-language-server') > 0 then
require'lspconfig'.sumneko_lua.setup {
settings = {
Lua = {
runtime = {
version = 'LuaJIT',
},
diagnostics = {
globals = {'vim'},
},
workspace = {
library = vim.api.nvim_get_runtime_file("", true),
},
telemetry = {
enable = false,
},
completion = {
-- complete full function signature
callSnippet = 'Replace',
},
},
},
on_attach = on_attach,
capabilities = capabilities
}
end
if vim.fn.executable('pylsp') > 0 then
require'lspconfig'.pylsp.setup{
settings = {
pylsp = {
}
},
on_attach = on_attach,
capabilities = capabilities
}
end
if vim.fn.executable('lemminx') > 0 then
require'lspconfig'.lemminx.setup{
filetypes = {
'xml', 'xsd', 'xsl', 'xslt', 'svg', 'gentoo-metadata'
},
on_attach = on_attach,
capabilities = capabilities
}
end
if vim.fn.executable('vscode-html-language-server') > 0 then
require'lspconfig'.html.setup{
on_attach = on_attach,
capabilities = capabilities
}
end
if vim.fn.executable('vscode-css-language-server') > 0 then
require'lspconfig'.cssls.setup{
on_attach = on_attach,
capabilities = capabilities
}
end
if vim.fn.executable('vscode-eslint-language-server') > 0 then
require'lspconfig'.eslint.setup{
on_attach = on_attach,
capabilities = capabilities
}
end
if vim.fn.executable('vscode-json-language-server') > 0 then
require'lspconfig'.jsonls.setup{
on_attach = on_attach,
capabilities = capabilities
}
end