339 lines
11 KiB
Lua
339 lines
11 KiB
Lua
local lspKeys = function(client, bufnr)
|
|
local fzf = require('fzf-lua')
|
|
local options = { noremap = true, silent = false, buffer = bufnr }
|
|
vim.keymap.set('n', '<space>,', vim.diagnostic.goto_prev, vim.tbl_extend('error', options, { desc = 'Diag prev' }))
|
|
vim.keymap.set('n', '<space>;', vim.diagnostic.goto_next, vim.tbl_extend('error', options, { desc = 'Diag next' }))
|
|
vim.keymap.set({ 'n', 'x' }, '<space>a', vim.lsp.buf.code_action, vim.tbl_extend('error', options, { desc = 'Code action' }))
|
|
vim.keymap.set('n', '<space>d', function()
|
|
fzf.lsp_definitions({ jump_to_single_result = true })
|
|
end, vim.tbl_extend('error', options, { desc = 'Definition' }))
|
|
vim.keymap.set('n', '<space>e', vim.lsp.buf.declaration, vim.tbl_extend('error', options, { desc = 'Declaration' }))
|
|
vim.keymap.set('n', '<space>h', function()
|
|
require('pretty_hover').hover()
|
|
end, vim.tbl_extend('error', options, { desc = 'Hover' }))
|
|
vim.keymap.set('n', '<space>c', vim.lsp.buf.outgoing_calls, vim.tbl_extend('error', options, { desc = 'Outgoing calls' }))
|
|
vim.keymap.set('n', '<space>C', vim.lsp.buf.incoming_calls, vim.tbl_extend('error', options, { desc = 'Incoming calls' }))
|
|
vim.keymap.set('n', '<space>m', vim.lsp.buf.rename, vim.tbl_extend('error', options, { desc = 'Rename' }))
|
|
vim.keymap.set('n', '<C-t>', fzf.lsp_live_workspace_symbols, vim.tbl_extend('error', options, { desc = 'Workspace symbols' }))
|
|
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, vim.tbl_extend('error', options, { desc = 'Type definition' }))
|
|
vim.keymap.set({ 'n', 'i', 'x' }, '<C-k>', vim.lsp.buf.signature_help, vim.tbl_extend('error', options, { desc = 'Signature help' }))
|
|
vim.keymap.set('n', '<space>r', fzf.lsp_references, vim.tbl_extend('error', options, { desc = 'References' }))
|
|
vim.keymap.set('n', '<A-m>', fzf.lsp_document_symbols, vim.tbl_extend('error', options, { desc = 'Document symbols' }))
|
|
vim.keymap.set('n', '<space>s', fzf.lsp_live_workspace_symbols, vim.tbl_extend('error', options, { desc = 'Workspace symbols' }))
|
|
vim.keymap.set('n', '<space>v', vim.diagnostic.open_float, vim.tbl_extend('error', options, { desc = 'Diagnostics Float' }))
|
|
vim.keymap.set('n', '<space>V', fzf.diagnostics_document, vim.tbl_extend('error', options, { desc = 'Diagnostics' }))
|
|
vim.keymap.set('n', '<A-o>', '<cmd>ClangdSwitchSourceHeader<CR>', vim.tbl_extend('error', options, { desc = 'Switch Source/Header' }))
|
|
|
|
-- 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
|
|
if client.supports_method('inlayHintProvider') then
|
|
vim.keymap.set('n', '<space>i', function()
|
|
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }), { bufnr = bufnr })
|
|
end, {
|
|
noremap = true,
|
|
silent = false,
|
|
desc = 'Toggle inlay hints',
|
|
buffer = bufnr,
|
|
})
|
|
end
|
|
end
|
|
|
|
local document_highlight = function(bufnr)
|
|
-- Set autocommands conditional on server_capabilities
|
|
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
|
|
|
|
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()')
|
|
|
|
lspKeys(client, bufnr)
|
|
|
|
if client.server_capabilities.documentHighlightProvider then
|
|
document_highlight(bufnr)
|
|
end
|
|
end
|
|
|
|
return {
|
|
'neovim/nvim-lspconfig',
|
|
dependencies = {
|
|
'williamboman/mason.nvim',
|
|
'williamboman/mason-lspconfig.nvim',
|
|
'p00f/clangd_extensions.nvim',
|
|
'jose-elias-alvarez/null-ls.nvim',
|
|
'Fildo7525/pretty_hover',
|
|
'creativenull/efmls-configs-nvim',
|
|
},
|
|
build = ':MasonUpdate',
|
|
version = nil,
|
|
branch = 'master',
|
|
config = function()
|
|
require('mason').setup({
|
|
ui = {
|
|
border = 'rounded',
|
|
},
|
|
})
|
|
require('mason-lspconfig').setup({
|
|
automatic_installation = false,
|
|
ensure_installed = {
|
|
'clangd',
|
|
'basedpyright',
|
|
-- 'neocmake',
|
|
'efm',
|
|
'lua_ls',
|
|
'jsonls',
|
|
'markdown_oxide',
|
|
},
|
|
})
|
|
local lspconfig = require('lspconfig')
|
|
|
|
local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())
|
|
capabilities.workspace = {
|
|
didChangeWatchedFiles = {
|
|
dynamicRegistration = true,
|
|
},
|
|
}
|
|
|
|
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
|
|
|
|
-- lspconfig['pyright'].setup {
|
|
-- capabilities = capabilities,
|
|
-- on_attach = on_attach,
|
|
-- }
|
|
|
|
lspconfig['basedpyright'].setup({
|
|
capabilities = capabilities,
|
|
on_attach = on_attach,
|
|
settings = {
|
|
basedpyright = {
|
|
typeCheckingMode = 'standard',
|
|
},
|
|
},
|
|
})
|
|
|
|
lspconfig['groovyls'].setup({
|
|
capabilities = capabilities,
|
|
on_attach = on_attach,
|
|
})
|
|
|
|
-- lspconfig['cmake'].setup {
|
|
-- capabilities = capabilities,
|
|
-- on_attach = on_attach,
|
|
-- }
|
|
|
|
local configs = require('lspconfig.configs')
|
|
if not configs.neocmake then
|
|
configs.neocmake = {
|
|
default_config = {
|
|
cmd = { 'neocmakelsp', '--stdio' },
|
|
filetypes = { 'cmake' },
|
|
root_dir = function(fname)
|
|
return lspconfig.util.find_git_ancestor(fname)
|
|
end,
|
|
single_file_support = true, -- suggested
|
|
on_attach = on_attach, -- on_attach is the on_attach function you defined
|
|
},
|
|
}
|
|
lspconfig.neocmake.setup({})
|
|
end
|
|
|
|
local clangd_capabilities = capabilities
|
|
clangd_capabilities.textDocument.semanticHighlighting = true
|
|
clangd_capabilities.offsetEncoding = { 'utf-16' }
|
|
lspconfig['clangd'].setup({
|
|
capabilities = clangd_capabilities,
|
|
on_attach = on_attach,
|
|
cmd = {
|
|
'clangd',
|
|
'--compile-commands-dir=build_nvim',
|
|
'--query-driver',
|
|
'/opt/cortex-a78-2022.08-gcc12.1-linux5.15/bin/aarch64-linux-gnu-g*',
|
|
'--clang-tidy',
|
|
'--background-index',
|
|
'--use-dirty-headers',
|
|
'--completion-style=detailed',
|
|
},
|
|
root_dir = lspconfig.util.root_pattern('.clangd', '.clang-tidy', '.clang-format', 'compile_flags.txt', 'configure.ac', '.git', 'build_nvim'),
|
|
})
|
|
|
|
require('clangd_extensions').setup({
|
|
extensions = {
|
|
inlay_hints = {
|
|
-- Only show inlay hints for the current line
|
|
only_current_line = true,
|
|
},
|
|
},
|
|
})
|
|
|
|
lspconfig['jsonls'].setup({
|
|
capabilities = capabilities,
|
|
on_attach = on_attach,
|
|
})
|
|
|
|
-- lspconfig['rust_analyzer'].setup {
|
|
-- capabilities = capabilities,
|
|
-- on_attach = on_attach,
|
|
-- }
|
|
|
|
lspconfig['lua_ls'].setup({
|
|
capabilities = capabilities,
|
|
on_attach = on_attach,
|
|
settings = {
|
|
Lua = {
|
|
workspace = {
|
|
checkThirdParty = false,
|
|
},
|
|
completion = {
|
|
callSnippet = 'Replace',
|
|
},
|
|
-- 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['markdown_oxide'].setup({
|
|
capabilities = capabilities,
|
|
on_attach = on_attach,
|
|
})
|
|
|
|
-- lspconfig['marksman'].setup {
|
|
-- capabilities = capabilities,
|
|
-- on_attach = on_attach,
|
|
-- }
|
|
|
|
lspconfig['yamlls'].setup({
|
|
capabilities = capabilities,
|
|
on_attach = on_attach,
|
|
settings = {
|
|
yaml = {
|
|
validate = true,
|
|
},
|
|
},
|
|
})
|
|
|
|
local prettier = require('efmls-configs.formatters.prettier')
|
|
local stylua = require('efmls-configs.formatters.stylua')
|
|
local gersemi = require('efmls-configs.formatters.gersemi')
|
|
local black = require('efmls-configs.formatters.black')
|
|
local isort = require('efmls-configs.formatters.isort')
|
|
local cmake_lint = require('efmls-configs.linters.cmake_lint')
|
|
local flake8 = require('efmls-configs.linters.flake8')
|
|
local languages = {
|
|
lua = { stylua },
|
|
markdown = { prettier },
|
|
cmake = { gersemi, cmake_lint },
|
|
python = { isort, black, flake8 },
|
|
}
|
|
|
|
local efmls_config = {
|
|
-- filetypes = vim.tbl_keys(languages),
|
|
settings = {
|
|
rootMarkers = { '.git/' },
|
|
languages = languages,
|
|
},
|
|
init_options = {
|
|
documentFormatting = true,
|
|
documentRangeFormatting = true,
|
|
},
|
|
}
|
|
|
|
require('lspconfig').efm.setup(vim.tbl_extend('force', efmls_config, {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
}))
|
|
|
|
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',
|
|
}
|