nvim/lua/plugins/lsp/init.lua

132 lines
4.1 KiB
Lua
Raw Normal View History

2022-12-31 17:43:31 +01:00
local M = {
'neovim/nvim-lspconfig',
name = 'lsp',
2023-04-08 23:47:10 +02:00
event = { 'BufRead', 'BufNewFile' },
-- lazy = false,
dependencies = { 'hrsh7th/cmp-nvim-lsp', 'williamboman/mason-lspconfig.nvim' },
2022-12-31 17:43:31 +01:00
}
2023-04-08 23:47:10 +02:00
local function has_formatter(ft)
local sources = require 'null-ls.sources'
local available = sources.get_available(ft, 'NULL_LS_FORMATTING')
return #available > 0
end
2022-12-31 17:43:31 +01:00
function M.config()
require('mason-lspconfig').setup {
automatic_installation = false,
}
2022-12-31 17:43:31 +01:00
local opts = {}
local cmp_nvim_lsp = require 'cmp_nvim_lsp'
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
capabilities = cmp_nvim_lsp.default_capabilities(capabilities)
local on_attach = function(client, bufnr)
--[[ vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') ]]
if client.name == 'jdt.ls' then
client.server_capabilities.documentFormattingProvider = false
vim.lsp.codelens.refresh()
if JAVA_DAP_ACTIVE then
require('jdtls').setup_dap { hotcodereplace = 'auto' }
require('jdtls.dap').setup_dap_main_class_configs()
end
end
local ft = vim.api.nvim_buf_get_option(bufnr, 'filetype')
local enable = false
2023-04-08 23:47:10 +02:00
if has_formatter(ft) then
2022-12-31 17:43:31 +01:00
enable = client.name == 'null-ls'
else
enable = not (client.name == 'null-ls')
end
-- util.info(client.name .. " " .. (enable and "yes" or "no"), "format")
client.server_capabilities.documentFormattingProvider = enable
2023-04-09 23:43:04 +02:00
client.server_capabilities.semanticTokensProvider = false
2022-12-31 17:43:31 +01:00
end
require('mason-lspconfig').setup_handlers {
function(server) -- default handler (optional)
opts = {
on_attach = on_attach,
capabilities = capabilities,
2022-12-31 17:43:31 +01:00
}
if server == 'sumneko_lua' or server == 'lua_ls' then
local sumneko_opts = require 'plugins.lsp.settings.sumneko_lua'
opts = vim.tbl_deep_extend('force', sumneko_opts, opts)
end
if server == 'clangd' then
local clangd_flags = {
2023-04-08 23:47:10 +02:00
'-j=5',
'--all-scopes-completion',
'--suggest-missing-includes',
'--background-index',
'--pch-storage=disk',
'--cross-file-rename',
'--log=info',
'--completion-style=detailed',
'--enable-config', -- clangd 11+ supports reading from .clangd configuration file
'--clang-tidy',
-- "--clang-tidy-checks=-*,llvm-*,clang-analyzer-*,modernize-*,-modernize-use-trailing-return-type",
-- "--fallback-style=Google",
-- "--header-insertion=never",
-- "--query-driver=<list-of-white-listed-complers>"
}
local clang_opts = {
arg = { unpack(clangd_flags) },
}
opts = vim.tbl_deep_extend('force', clang_opts, opts)
end
if server == 'jdtls' then
vim.cmd "command! -buffer -nargs=? -complete=custom,v:lua.require'jdtls'._complete_compile JdtCompile lua require('jdtls').compile(<f-args>)"
vim.cmd "command! -buffer -nargs=? -complete=custom,v:lua.require'jdtls'._complete_set_runtime JdtSetRuntime lua require('jdtls').set_runtime(<f-args>)"
vim.cmd "command! -buffer JdtUpdateConfig lua require('jdtls').update_project_config()"
-- vim.cmd "command! -buffer JdtJol lua require('jdtls').jol()"
vim.cmd "command! -buffer JdtBytecode lua require('jdtls').javap()"
-- vim.cmd "command! -buffer JdtJshell lua require('jdtls').jshell()"
goto continue
end
require('lspconfig')[server].setup(opts)
::continue::
end,
}
2022-12-31 17:43:31 +01:00
local config = {
virtual_text = {
prefix = '',
},
signs = false,
underline = true,
update_in_insert = true,
severity_sort = false,
2022-12-31 17:43:31 +01:00
float = {
focusable = false,
-- style = 'minimal',
2022-12-31 17:43:31 +01:00
border = 'rounded',
source = 'always',
header = '',
prefix = '',
},
}
vim.diagnostic.config(config)
vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, {
border = 'rounded',
})
vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, {
border = 'rounded',
})
2023-01-01 19:36:00 +01:00
local on_references = vim.lsp.handlers['textDocument/references']
vim.lsp.handlers['textDocument/references'] = vim.lsp.with(on_references, {
-- Use location list instead of quickfix list
loclist = true,
})
2022-12-31 17:43:31 +01:00
end
return M