99 lines
3.1 KiB
Lua
99 lines
3.1 KiB
Lua
local M = {
|
|
'neovim/nvim-lspconfig',
|
|
name = 'lsp',
|
|
event = { 'BufRead *.lua,*.c,*.rust,*.go,*.py,*.java,*.cpp,*.h' , 'BufNewFile *.lua,*.c,*.rust,*.go,*.py,*.java,*.cpp,*.h' },
|
|
-- lazy = false,
|
|
dependencies = { 'hrsh7th/cmp-nvim-lsp', 'williamboman/mason.nvim' },
|
|
}
|
|
|
|
local servers = { 'clangd', 'rust_analyzer', 'lua_ls', 'pyright', 'gopls', 'jdtls' }
|
|
|
|
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 = utils.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
|
|
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
|