317 lines
10 KiB
Lua
317 lines
10 KiB
Lua
return {
|
|
'neovim/nvim-lspconfig',
|
|
dependencies = {
|
|
'williamboman/mason.nvim',
|
|
'williamboman/mason-lspconfig.nvim',
|
|
'p00f/clangd_extensions.nvim',
|
|
'jose-elias-alvarez/null-ls.nvim',
|
|
'ray-x/lsp_signature.nvim',
|
|
{
|
|
'folke/neodev.nvim',
|
|
config = true,
|
|
},
|
|
},
|
|
config = function()
|
|
require('mason').setup()
|
|
require('mason-lspconfig').setup({
|
|
automatic_installation = false,
|
|
})
|
|
local lspconfig = require 'lspconfig'
|
|
|
|
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
|
|
|
vim.api.nvim_set_hl(
|
|
0,
|
|
"LspReferenceText",
|
|
{ bold = true,
|
|
ctermbg = 'red',
|
|
bg = "#5a524c" }
|
|
)
|
|
vim.api.nvim_set_hl(
|
|
0,
|
|
"LspReferenceRead",
|
|
{ bold = true,
|
|
ctermbg = 'red',
|
|
bg = 'DarkGreen' }
|
|
)
|
|
vim.api.nvim_set_hl(
|
|
0,
|
|
"LspReferenceWrite",
|
|
{ bold = true,
|
|
ctermbg = 'red',
|
|
bg = 'DarkRed' }
|
|
)
|
|
local diagnostics = {
|
|
Error = " ",
|
|
Warning = " ",
|
|
Information = " ",
|
|
Question = " ",
|
|
Hint = " ",
|
|
}
|
|
local signs = {
|
|
{ name = "DiagnosticSignError", text = diagnostics.Error },
|
|
{ name = "DiagnosticSignWarn", text = diagnostics.Warning },
|
|
{ name = "DiagnosticSignHint", text = diagnostics.Hint },
|
|
{ name = "DiagnosticSignInfo", text = diagnostics.Information },
|
|
}
|
|
|
|
for _, sign in ipairs(signs) do
|
|
vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = sign.name })
|
|
end
|
|
|
|
OpenDiagFloat = function()
|
|
for _, winid in pairs(vim.api.nvim_tabpage_list_wins(0)) do
|
|
if vim.api.nvim_win_get_config(winid).zindex then
|
|
return
|
|
end
|
|
end
|
|
vim.diagnostic.open_float({ focusable = false, width = 80 })
|
|
end
|
|
|
|
local on_attach = function(client, bufnr)
|
|
local function buf_set_option(...)
|
|
vim.api.nvim_buf_set_option(bufnr, ...)
|
|
end
|
|
|
|
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
|
|
vim.api.nvim_buf_set_option(0, 'formatexpr', 'v:lua.vim.lsp.formatexpr()')
|
|
|
|
-- Mappings.
|
|
vim.keymap.set('n', '<space>,', vim.diagnostic.goto_prev,
|
|
{ noremap = true, silent = false, desc = 'Diag prev', buffer = bufnr })
|
|
vim.keymap.set('n', '<space>;', vim.diagnostic.goto_next,
|
|
{ noremap = true, silent = false, desc = 'Diag next', buffer = bufnr })
|
|
vim.keymap.set('n', '<space>a', vim.lsp.buf.code_action,
|
|
{ noremap = true, silent = false, desc = 'Code action', buffer = bufnr })
|
|
vim.keymap.set('n', '<space>d', vim.lsp.buf.definition,
|
|
{ noremap = true, silent = false, desc = 'Definition', buffer = bufnr })
|
|
vim.keymap.set('n', '<space>e', vim.lsp.buf.declaration,
|
|
{ noremap = true, silent = false, desc = 'Declaration', buffer = bufnr })
|
|
vim.keymap.set('n', '<space>h', vim.lsp.buf.hover,
|
|
{ noremap = true, silent = false, desc = 'Hover', buffer = bufnr })
|
|
vim.keymap.set('n', '<space>c', vim.lsp.buf.outgoing_calls,
|
|
{ noremap = true, silent = false, desc = 'Outgoing calls', buffer = bufnr })
|
|
vim.keymap.set('n', '<space>C', vim.lsp.buf.incoming_calls,
|
|
{ noremap = true, silent = false, desc = 'Incoming calls', buffer = bufnr })
|
|
vim.keymap.set('n', '<space>m', vim.lsp.buf.rename,
|
|
{ noremap = true, silent = false, desc = 'Rename', buffer = bufnr })
|
|
local tele_builtins = require('telescope.builtin')
|
|
vim.keymap.set('n', '<C-t>', tele_builtins.lsp_dynamic_workspace_symbols,
|
|
{ noremap = true, silent = false, desc = 'Workspace symbols', buffer = bufnr })
|
|
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition,
|
|
{ noremap = true, silent = false, desc = 'Type definition', buffer = bufnr })
|
|
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help,
|
|
{ noremap = true, silent = false, desc = 'Signature help', buffer = bufnr })
|
|
vim.keymap.set('n', '<space>r', tele_builtins.lsp_references,
|
|
{ noremap = true, silent = false, desc = 'References', buffer = bufnr })
|
|
vim.keymap.set('n', '<A-m>', tele_builtins.lsp_document_symbols,
|
|
{ noremap = true, silent = false, desc = 'References', buffer = bufnr })
|
|
vim.keymap.set('n', '<space>v', function() tele_builtins.diagnostics({ bufnr = 0 }) end,
|
|
{ noremap = true, silent = false, desc = 'Diagnostics', buffer = bufnr })
|
|
vim.keymap.set('n', '<A-o>', '<cmd>ClangdSwitchSourceHeader<CR>',
|
|
{ noremap = true, silent = false, desc = 'Switch Source/Header', buffer = bufnr })
|
|
|
|
vim.cmd([[autocmd CursorHold <buffer> lua OpenDiagFloat()]])
|
|
|
|
-- Set some keybinds conditional on server capabilities
|
|
if client.server_capabilities.documentFormattingProvider then
|
|
vim.keymap.set('n', '<space>f', function()
|
|
vim.lsp.buf.format({ timeout_ms = 10000 })
|
|
end,
|
|
{ noremap = true, silent = false, desc = 'Format file', buffer = bufnr })
|
|
end
|
|
if client.server_capabilities.documentRangeFormattingProvider then
|
|
vim.keymap.set('x', '<space>f', function()
|
|
vim.lsp.buf.format({ timeout_ms = 10000 })
|
|
end,
|
|
{ noremap = true, silent = false, desc = 'Format visual', buffer = bufnr })
|
|
end
|
|
|
|
-- Set autocommands conditional on server_capabilities
|
|
if client.server_capabilities.documentHighlightProvider then
|
|
local group = vim.api.nvim_create_augroup("lsp_document_highlight", { clear = false })
|
|
vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
|
|
callback = function()
|
|
vim.lsp.buf.document_highlight()
|
|
end,
|
|
buffer = bufnr,
|
|
group = group,
|
|
desc = "Document Highlight",
|
|
})
|
|
vim.api.nvim_create_autocmd("CursorMoved", {
|
|
callback = function()
|
|
vim.lsp.buf.clear_references()
|
|
end,
|
|
buffer = bufnr,
|
|
group = group,
|
|
desc = "Clear All the References",
|
|
})
|
|
vim.api.nvim_create_autocmd({ 'LspDetach' }, {
|
|
group = group,
|
|
buffer = bufnr,
|
|
callback = function()
|
|
vim.lsp.buf.clear_references()
|
|
vim.api.nvim_clear_autocmds {
|
|
group = group,
|
|
buffer = bufnr
|
|
}
|
|
end,
|
|
})
|
|
end
|
|
|
|
require('lsp_signature').on_attach({
|
|
bind = true, -- This is mandatory, otherwise border config won't get registered.
|
|
handler_opts = {
|
|
border = 'single',
|
|
},
|
|
hi_parameter = 'IncSearch',
|
|
}, bufnr)
|
|
end
|
|
|
|
lspconfig['pyright'].setup {
|
|
capabilities = capabilities,
|
|
on_attach = on_attach,
|
|
}
|
|
|
|
lspconfig['groovyls'].setup {
|
|
capabilities = capabilities,
|
|
on_attach = on_attach,
|
|
}
|
|
|
|
lspconfig['cmake'].setup {
|
|
capabilities = capabilities,
|
|
on_attach = on_attach,
|
|
}
|
|
|
|
local clangd_capabilities = capabilities
|
|
clangd_capabilities.textDocument.semanticHighlighting = true
|
|
clangd_capabilities.offsetEncoding = { "utf-16" }
|
|
require("clangd_extensions").setup {
|
|
server = {
|
|
capabilities = clangd_capabilities,
|
|
on_attach = on_attach,
|
|
cmd = { 'clangd', '--compile-commands-dir=build_nvim' },
|
|
root_dir = lspconfig.util.root_pattern(
|
|
'.clangd',
|
|
'.clang-tidy',
|
|
'.clang-format',
|
|
'compile_commands.json',
|
|
'compile_flags.txt',
|
|
'configure.ac',
|
|
'.git',
|
|
'build_nvim'
|
|
)
|
|
},
|
|
extensions =
|
|
{
|
|
inlay_hints = {
|
|
-- Only show inlay hints for the current line
|
|
only_current_line = true,
|
|
}
|
|
}
|
|
|
|
}
|
|
-- require('clangd_extensions').setup({
|
|
-- server = {
|
|
-- on_attach = on_attach,
|
|
-- capabilities = capabilities,
|
|
-- cmd = { 'clangd', '--compile-commands-dir=build_nvim' },
|
|
-- },
|
|
-- })
|
|
|
|
lspconfig['jsonls'].setup {
|
|
capabilities = capabilities,
|
|
on_attach = on_attach,
|
|
}
|
|
|
|
local lua_rtp = vim.split(package.path, ';')
|
|
table.insert(lua_rtp, 'lua/?.lua')
|
|
table.insert(lua_rtp, 'lua/?/init.lua')
|
|
lspconfig.sumneko_lua.setup {
|
|
capabilities = capabilities,
|
|
on_attach = on_attach,
|
|
settings = {
|
|
Lua = {
|
|
runtime = {
|
|
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
|
|
version = 'LuaJIT',
|
|
-- Setup your lua path
|
|
path = lua_rtp,
|
|
},
|
|
diagnostics = {
|
|
-- Get the language server to recognize the `vim` global
|
|
globals = { 'vim', 'use' },
|
|
},
|
|
workspace = {
|
|
-- Make the server aware of Neovim runtime files
|
|
library = vim.api.nvim_get_runtime_file('', true),
|
|
checkThirdParty = false,
|
|
},
|
|
-- Do not send telemetry data containing a randomized but unique identifier
|
|
telemetry = {
|
|
enable = false,
|
|
},
|
|
format = {
|
|
enable = true,
|
|
defaultConfig = {
|
|
indent_style = 'space',
|
|
indent_size = '2',
|
|
quote_style = 'single'
|
|
}
|
|
}
|
|
},
|
|
}
|
|
}
|
|
|
|
lspconfig['dockerls'].setup {
|
|
capabilities = capabilities,
|
|
on_attach = on_attach,
|
|
}
|
|
|
|
lspconfig['yamlls'].setup {
|
|
capabilities = capabilities,
|
|
on_attach = on_attach,
|
|
settings = {
|
|
yaml = {
|
|
validate = true
|
|
}
|
|
}
|
|
}
|
|
|
|
local null_ls = require('null-ls')
|
|
null_ls.setup({
|
|
sources = {
|
|
null_ls.builtins.code_actions.gitsigns,
|
|
-- null_ls.builtins.formatting.black,
|
|
null_ls.builtins.formatting.autopep8,
|
|
null_ls.builtins.formatting.prettier,
|
|
null_ls.builtins.formatting.xmlformat,
|
|
null_ls.builtins.diagnostics.flake8,
|
|
null_ls.builtins.formatting.isort,
|
|
null_ls.builtins.formatting.cmake_format,
|
|
},
|
|
debug = true,
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
})
|
|
|
|
-- vim.diagnostic.config({ virtual_text = false })
|
|
vim.diagnostic.config({
|
|
virtual_text = false,
|
|
signs = true,
|
|
float = {
|
|
border = "single",
|
|
format = function(diagnostic)
|
|
return string.format(
|
|
"%s (%s) [%s]",
|
|
diagnostic.message,
|
|
diagnostic.source,
|
|
diagnostic.code or diagnostic.user_data.lsp.code
|
|
)
|
|
end,
|
|
},
|
|
})
|
|
end,
|
|
event = 'VeryLazy'
|
|
}
|