setup rust-tools, make lspconfig be handled by mason-lspconfig

This commit is contained in:
Volodymyr Patuta 2023-01-23 18:57:39 +01:00
parent 134e6ea0b0
commit d908d1dcce
4 changed files with 90 additions and 57 deletions

View File

@ -34,5 +34,6 @@ return {
end, end,
}, },
{ 'nvim-tree/nvim-web-devicons', lazy = true }, { 'nvim-tree/nvim-web-devicons', lazy = true },
'simrat39/rust-tools.nvim',
-- { 'dstein64/vim-startuptime', lazy = false }, -- { 'dstein64/vim-startuptime', lazy = false },
} }

View File

@ -2,18 +2,14 @@ local M = {
'neovim/nvim-lspconfig', 'neovim/nvim-lspconfig',
name = 'lsp', name = 'lsp',
event = 'BufRead', event = 'BufRead',
dependencies = { 'hrsh7th/cmp-nvim-lsp', 'williamboman/mason.nvim' }, dependencies = { 'hrsh7th/cmp-nvim-lsp', 'williamboman/mason.nvim', 'williamboman/mason-lspconfig.nvim' },
}
local tools = {
'clangd',
'gopls',
'sumneko_lua',
'jdtls',
} }
function M.config() function M.config()
local lspconfig = require 'lspconfig' require('mason-lspconfig').setup {
automatic_installation = false,
}
local opts = {} local opts = {}
local cmp_nvim_lsp = require 'cmp_nvim_lsp' local cmp_nvim_lsp = require 'cmp_nvim_lsp'
local capabilities = vim.lsp.protocol.make_client_capabilities() local capabilities = vim.lsp.protocol.make_client_capabilities()
@ -80,50 +76,59 @@ function M.config()
-- util.info(client.name .. " " .. (enable and "yes" or "no"), "format") -- util.info(client.name .. " " .. (enable and "yes" or "no"), "format")
client.server_capabilities.documentFormattingProvider = enable client.server_capabilities.documentFormattingProvider = enable
end end
for _, tool in ipairs(tools) do
opts = {
on_attach = on_attach,
capabilities = capabilities,
}
local server = vim.split(tool, '@')[1]
if server == 'sumneko_lua' then require('mason-lspconfig').setup_handlers {
local sumneko_opts = require 'plugins.lsp.settings.sumneko_lua' function(server) -- default handler (optional)
opts = vim.tbl_deep_extend('force', sumneko_opts, opts) opts = {
end on_attach = on_attach,
if server == 'clangd' then capabilities = capabilities,
local clangd_flags = {
'--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) }, if server == 'sumneko_lua' 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 = {
'--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,
['rust_analyzer'] = function()
require('rust-tools').setup {
server = {
on_attach = on_attach,
}
} }
opts = vim.tbl_deep_extend('force', clang_opts, opts) end,
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
local config = { local config = {
virtual_text = { virtual_text = {
@ -132,10 +137,10 @@ function M.config()
signs = false, signs = false,
underline = true, underline = true,
update_in_insert = true, update_in_insert = true,
severity_sort = true, severity_sort = false,
float = { float = {
focusable = true, focusable = false,
style = 'minimal', -- style = 'minimal',
border = 'rounded', border = 'rounded',
source = 'always', source = 'always',
header = '', header = '',

View File

@ -8,10 +8,40 @@ local M = {
} }
function M.config() function M.config()
local dap = require 'dap'
require('mason-nvim-dap').setup { require('mason-nvim-dap').setup {
automatic_setup = true, automatic_setup = true,
} }
require('mason-nvim-dap').setup_handlers() require('mason-nvim-dap').setup_handlers {
function(source_name)
-- all sources with no handler get passed here
-- Keep original functionality of `automatic_setup = true`
require 'mason-nvim-dap.automatic_setup'(source_name)
end,
elixir = function(source_name)
dap.adapters.mix_task = {
type = 'executable',
command = '/home/user/.local/share/nvim/mason/packages/elixir-ls/debugger.sh', -- debugger.bat for windows
args = {},
}
dap.configurations.elixir = {
{
type = 'mix_task',
name = 'mix test',
task = 'test',
taskArgs = { '--trace' },
request = 'launch',
startApps = true, -- for Phoenix projects
projectDir = '${workspaceFolder}',
requireFiles = {
'test/**/test_helper.exs',
'test/**/*_test.exs',
},
},
}
end,
}
end end
return M return M

View File

@ -42,9 +42,6 @@ function M.config()
}, },
} }
-- M.check() -- M.check()
require('mason-lspconfig').setup {
automatic_installation = false,
}
end end
return M return M