Files
yadm/.config/nvim/lua/plugins/lspconfig.lua
2023-08-08 10:04:36 +02:00

259 lines
9.7 KiB
Lua

return {
'neovim/nvim-lspconfig',
dependencies = {
"SmiteshP/nvim-navbuddy",
{url = "http://git.sr.ht/~p00f/clangd_extensions.nvim"},
"jubnzv/virtual-types.nvim",
"ray-x/lsp_signature.nvim",
},
config = function()
local nvim_lsp = require('lspconfig')
local clangd_extensions = require('clangd_extensions')
local lsp_signature = require('lsp_signature')
-- Mappings.
local opts = { noremap=true, silent=true }
vim.api.nvim_set_keymap('n', '<leader>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
vim.api.nvim_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
vim.api.nvim_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
vim.api.nvim_set_keymap('n', '<leader>E', '<cmd>lua vim.diagnostic.set_loclist()<CR>', opts)
vim.api.nvim_set_keymap("n", "<leader>q", "<cmd>lua vim.lsp.buf.format{ async = true }<CR>", opts)
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
--Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
---- See `:help vim.lsp.*` for documentation on any of the below functions
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
--vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
--vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
--vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<F6>', '<cmd>ClangdSwitchSourceHeader<cr>', opts)
-- require'illuminate'.on_attach(client)
require'virtualtypes'.on_attach()
require'lsp_signature'.on_attach({
floating_window = true,
floating_window_above_cur_line = false,
floating_window_off_x = 500,
floating_window_off_y = -5,
})
require'nvim-navbuddy'.attach(client, bufnr)
require'nvim-navic'.attach(client, bufnr)
require("clangd_extensions.inlay_hints").setup_autocmd()
require("clangd_extensions.inlay_hints").set_inlay_hints()
end
local signs = {
{ name = "DiagnosticSignError", text = "" },
{ name = "DiagnosticSignWarn", text = "" },
{ name = "DiagnosticSignHint", text = "" },
{ name = "DiagnosticSignInfo", text = "" },
}
for _, sign in ipairs(signs) do
vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" })
end
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
signs = {
active = signs,
--severity_limit = 'info',
},
severity_sort = true,
underline = false,
update_in_insert = false,
--virtual_text = {
-- spacing = 40,
-- severity_limit = 'Warning',
--},
virtual_text = false,
}
)
local capabilities = require('cmp_nvim_lsp').default_capabilities()
capabilities.offsetEncoding = { "utf-16" }
nvim_lsp.groovyls.setup({
cmd = { "java", "-jar", "/home/kmcr/tools/groovy-language-server/build/libs/groovy-language-server-all.jar" },
on_attach = on_attach,
--on_publish_diagnostics = diagnostic_handler,
capabilities = capabilities
})
-- nvim_lsp.ccls.setup(
-- coq.lsp_ensure_capabilities({
-- init_options = {
-- compilationDatabaseDirectory = ".";
-- index = {
-- threads = 0;
-- },
-- clang = {
-- excludeArgs = { "-frounding-math"} ;
-- },
-- },
-- root_dir = nvim_lsp.util.root_pattern("compile_commands.json"),
-- on_attach = on_attach,
-- on_publish_diagnostics = diagnostic_handler,
-- flags = {
-- debounce_text_changes = 150,
-- }}
-- )
-- )
nvim_lsp.clangd.setup({
settings = {
inlay_hints = {
inline = vim.fn.has("nvim-0.10") == 1,
-- Options other than `highlight' and `priority' only work
-- if `inline' is disabled
-- Only show inlay hints for the current line
only_current_line = false,
-- Event which triggers a refresh of the inlay hints.
-- You can make this { "CursorMoved" } or { "CursorMoved,CursorMovedI" } but
-- not that this may cause higher CPU usage.
-- This option is only respected when only_current_line and
-- autoSetHints both are true.
only_current_line_autocmd = { "CursorHold" },
-- whether to show parameter hints with the inlay hints or not
show_parameter_hints = true,
-- prefix for parameter hints
parameter_hints_prefix = "<- ",
-- prefix for all the other hints (type, chaining)
other_hints_prefix = "=> ",
-- whether to align to the length of the longest line in the file
max_len_align = false,
-- padding from the left if max_len_align is true
max_len_align_padding = 1,
-- whether to align to the extreme right or not
right_align = false,
-- padding from the right if right_align is true
right_align_padding = 7,
-- The color of the hints
highlight = "Comment",
-- The highlight group priority for extmark
priority = 100,
},
ast = {
-- These are unicode, should be available in any font
role_icons = {
type = "🄣",
declaration = "🄓",
expression = "🄔",
statement = ";",
specifier = "🄢",
["template argument"] = "🆃",
},
kind_icons = {
Compound = "🄲",
Recovery = "🅁",
TranslationUnit = "🅄",
PackExpansion = "🄿",
TemplateTypeParm = "🅃",
TemplateTemplateParm = "🅃",
TemplateParamObject = "🅃",
},
--[[ These require codicons (https://github.com/microsoft/vscode-codicons)
role_icons = {
type = "",
declaration = "",
expression = "",
specifier = "",
statement = "",
["template argument"] = "",
},
kind_icons = {
Compound = "",
Recovery = "",
TranslationUnit = "",
PackExpansion = "",
TemplateTypeParm = "",
TemplateTemplateParm = "",
TemplateParamObject = "",
}, ]]
highlights = {
detail = "Comment",
},
memory_usage = {
border = "none",
},
symbol_info = {
border = "none",
}
}
},
on_attach = on_attach,
--on_publish_diagnostics = diagnostic_handler,
capabilities = capabilities,
-- flags = {
-- debounce_text_changes = 150,
-- }
})
nvim_lsp.pylsp.setup({
settings = {
pylint = {
enabled = false
},
pyflakes = {
enabled = false,
},
},
-- flags = {
-- debounce_text_changes = 150,
-- },
on_attach = on_attach,
capabilities = capabilities
--on_publish_diagnostics = diagnostic_handler,
})
nvim_lsp.matlab_ls.setup({
cmd = { "matlab-language-server", "--stdio"},
filetypes = { "matlab" },
handlers = { [ "workspace/configuration"] = function(_, _, ctx)
local client = vim.lsp.get_client_by_id(ctx.client_id)
return {client.config.settings.matlab}
end
},
root_dir = nvim_lsp.util.find_git_ancestor,
single_file_support = false,
settings = {
matlab = {
indexWorkspace = true,
installPath = "/home/kmcr/.local/usr/MATLAB/R2021b",
matlabConnectionTiming = "onStart",
telemetry = true,
},
},
on_attach = on_attach,
capabilities = capabilities
})
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
local servers = { "cmake", "rust_analyzer", "bashls", "marksman" }
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup({
on_attach = on_attach,
--on_publish_diagnostics = diagnostic_handler,
capabilities = capabilities,
-- flags = {
-- debounce_text_changes = 150,
-- }
})
end
end
}