nvim/lua/plugins/lsp/init.lua
2023-07-02 22:18:44 +02:00

142 lines
4.6 KiB
Lua

local M = {
'neovim/nvim-lspconfig',
name = 'lsp',
-- event = { 'BufRead *.lua,*.c,*.rust,*.go,*.py,*.java,*.cpp,*.h,*.asm,*.tex',
-- 'BufNewFile *.lua,*.c,*.rust,*.go,*.py,*.java,*.cpp,*.h,*,*.asm,*.tex' },
-- lazy = false,
dependencies = { 'hrsh7th/cmp-nvim-lsp', 'williamboman/mason.nvim' },
}
local servers = { 'clangd', 'rust_analyzer', 'lua_ls', 'pyright', 'gopls', 'jdtls', 'asm_lsp', 'texlab', 'elixirls' }
local function on_attach(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 has_formatter = require('null-ls.sources').get_available(ft, 'NULL_LS_FORMATTING') > 0
--
-- local enable = false
-- if has_formatter and not client.name == 'clangd' then
-- 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
client.server_capabilities.documentFormattingProvider = true
-- client.server_capabilities.semanticTokensProvider = false
client.server_capabilities.semanticTokensProvider = nil
end
function M.config()
local utils = require 'config.utils'
local opts = {}
local cmp_nvim_lsp = require 'cmp_nvim_lsp'
local capabilities = cmp_nvim_lsp.default_capabilities()
local lspconfig = require 'lspconfig'
for _, server in ipairs(servers) do
opts = {
on_attach = on_attach,
capabilities = capabilities,
}
if server == 'lua_ls' then
local sumneko_opts = {
flags = {
debounce_text_changes = 150,
},
settings = {
Lua = {
diagnostics = {
globals = { 'vim' },
},
-- workspace = {
-- library = {
-- [vim.fn.expand '$VIMRUNTIME/lua'] = true,
-- [vim.fn.stdpath 'config' .. '/lua'] = true,
-- },
-- },
telemetry = {
enable = false,
},
},
},
}
opts = vim.tbl_deep_extend('force', sumneko_opts, opts)
end
if server == 'clangd' then
local clangd_flags = {
'-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
if server == 'rust_analyzer' then
require('rust-tools').setup {
server = {
on_attach = on_attach,
standalone = false,
},
}
goto continue
end
if server == 'elixirls' then
local elixir_opts = {
cmd = { "/home/user/.local/share/nvim/mason/packages/elixir-ls/language_server.sh" },
}
opts = vim.tbl_deep_extend('force', elixir_opts, opts)
end
lspconfig[server].setup(opts)
::continue::
end
vim.diagnostic.config(utils.lsp_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',
-- })
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,
})
end
return M