Files
yadm/.config/nvim/lua/plugins/lspconfig.lua
2024-03-29 09:33:27 +01:00

232 lines
8.1 KiB
Lua

return {
'neovim/nvim-lspconfig',
dependencies = {
-- "SmiteshP/nvim-navbuddy",
"jubnzv/virtual-types.nvim",
--"ray-x/lsp_signature.nvim",
"folke/neodev.nvim",
{url = "http://git.sr.ht/~p00f/clangd_extensions.nvim"},
},
config = function()
require("neodev").setup({
library = { plugins = { "nvim-dap-ui" }, types = true },
})
local nvim_lsp = require('lspconfig')
require('clangd_extensions').setup({
inlay_hints = {
inline = false,
-- Options other than `highlight' and `priority' only work
-- if `inline' is disabled
-- Only show inlay hints for the current line
only_current_line = true,
-- 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",
}
}
})
--local lsp_signature = require('lsp_signature')
-- Mappings.
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
vim.keymap.set('n', '<leader>E', vim.diagnostic.setloclist)
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
callback = function(ev)
vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
--vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
--vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
--vim.keymap.set('n', '<space>wl', function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, opts)
vim.keymap.set('n', '<leader>D', vim.lsp.buf.type_definition, opts)
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts)
--vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
vim.keymap.set('n', '<F6>', '<cmd>ClangdSwitchSourceHeader<CR>', opts)
vim.keymap.set("n", "<leader>q", function() vim.lsp.buf.format{ async = true } end, opts)
require'virtualtypes'.on_attach()
-- require'lsp_signature'.on_attach({
-- floating_window = true,
-- floating_window_above_cur_line = true,
-- floating_window_off_x = 10,
-- floating_window_off_y = 0,
-- })
require("clangd_extensions.inlay_hints").setup_autocmd()
require("clangd_extensions.inlay_hints").set_inlay_hints()
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 = false,
severity_sort = true,
underline = true,
update_in_insert = false,
virtual_text = {
spacing = 30,
},
float = true
}
)
end
})
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" },
capabilities = capabilities
})
nvim_lsp.clangd.setup({
capabilities = capabilities,
})
nvim_lsp.pylsp.setup({
settings = {
pylint = {
enabled = false
},
pyflakes = {
enabled = false,
},
},
capabilities = capabilities
})
nvim_lsp.lua_ls.setup({
settings = {
Lua = {
completion = {
callSnippet = "Replace"
}
}
}
})
nvim_lsp.matlab_ls.setup({
cmd = { "matlab-language-server", "--stdio"},
filetypes = { "matlab" },
root_dir = nvim_lsp.util.find_git_ancestor,
single_file_support = true,
settings = {
matlab = {
indexWorkspace = false,
installPath = "/usr/local/MATLAB/R2022b",
matlabConnectionTiming = "onStart",
telemetry = true,
},
}
})
nvim_lsp.typos_lsp.setup({
cmd = { 'typos-lsp' },
filetypes = { '*' },
root_dir = nvim_lsp.util.root_pattern('typos.toml', '_typos.toml', '.typos.toml'),
single_file_support = true,
settings = {},
})
-- 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({
capabilities = capabilities,
})
end
end
}