Migrate to mason.nvim and setup jdtls
This commit is contained in:
parent
3a1ab705cb
commit
59ec8d490b
|
@ -4,13 +4,18 @@ setlocal foldmethod=syntax
|
||||||
setlocal foldenable
|
setlocal foldenable
|
||||||
setlocal textwidth=120
|
setlocal textwidth=120
|
||||||
|
|
||||||
nnoremap <silent> <buffer> <leader>jc :JavaCorrect<cr>
|
|
||||||
nnoremap <silent> <buffer> <leader>jd :JavaDocComment<cr>
|
nnoremap <silent> <buffer> <leader>jd :JavaDocComment<cr>
|
||||||
nnoremap <silent> <buffer> <F2> :JavaDocPreview<cr>
|
nnoremap <silent> <buffer> <F2> :JavaDocPreview<cr>
|
||||||
nnoremap <silent> <buffer> <F3> :JavaSearchContext<cr>
|
nnoremap <silent> <buffer> <F3> :JavaSearchContext<cr>
|
||||||
nnoremap <silent> <buffer> <leader>jf :%JavaFormat<cr>
|
nnoremap <silent> <buffer> <leader>ev <Cmd>lua require('jdtls').extract_variable()<CR>
|
||||||
nnoremap <silent> <buffer> <leader>ji :JavaImportOrganize<cr>
|
vnoremap <silent> <buffer> <leader>ev <Esc><Cmd>lua require('jdtls').extract_variable(true)<CR>
|
||||||
nnoremap <buffer> <leader>jr :JavaRename<space>
|
nnoremap <silent> <buffer> <leader>ec <Cmd>lua require('jdtls').extract_constant()<CR>
|
||||||
|
vnoremap <silent> <buffer> <leader>ec <Esc><Cmd>lua require('jdtls').extract_constant(true)<CR>
|
||||||
|
vnoremap <silent> <buffer> <leader>em <Esc><Cmd>lua require('jdtls').extract_method(true)<CR>
|
||||||
|
nnoremap <buffer> <leader>ro <Cmd>lua require('jdtls').organize_imports()<CR>
|
||||||
|
|
||||||
|
nnoremap <silent> <buffer> <leader>tc <Cmd>lua require'jdtls'.test_class()<CR>
|
||||||
|
nnoremap <silent> <buffer> <leader>tm <Cmd>lua require'jdtls'.test_nearest_method()<CR>
|
||||||
|
|
||||||
inoremap <expr> <C-Space> pumvisible() \|\| &omnifunc == '' ?
|
inoremap <expr> <C-Space> pumvisible() \|\| &omnifunc == '' ?
|
||||||
\ "\<lt>C-n>" :
|
\ "\<lt>C-n>" :
|
||||||
|
|
22
ftplugin/java.lua
Normal file
22
ftplugin/java.lua
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
local mylsp = require("my-lsp")
|
||||||
|
local path = require("mason-core.path")
|
||||||
|
|
||||||
|
local function mason_package(...)
|
||||||
|
return path.concat{vim.fn.stdpath("data"), "mason", "packages", ...}
|
||||||
|
end
|
||||||
|
|
||||||
|
local bundles = vim.fn.glob(mason_package("java-debug-adapter", "extension", "server", "com.microsoft.java.debug.plugin-*.jar"), true, true)
|
||||||
|
local extra_bundles = vim.fn.glob(mason_package("java-test", "extension", "server", "*.jar"), true, true)
|
||||||
|
vim.list_extend(bundles, extra_bundles)
|
||||||
|
|
||||||
|
require('jdtls').start_or_attach({
|
||||||
|
cmd = {mason_package("jdtls", "bin", "jdtls") },
|
||||||
|
on_attach = function(client, bufnr)
|
||||||
|
require'jdtls.setup'.add_commands()
|
||||||
|
require'jdtls'.setup_dap()
|
||||||
|
mylsp.on_attach(client, bufnr)
|
||||||
|
end,
|
||||||
|
init_options = {
|
||||||
|
bundles = extra_bundles
|
||||||
|
}
|
||||||
|
})
|
|
@ -1,8 +1,39 @@
|
||||||
local status, lsp_installer = pcall(require,"nvim-lsp-installer")
|
local status1, mason = pcall(require, "mason")
|
||||||
if (not status) then return end
|
local status2, mason_lspconfig = pcall(require, "mason-lspconfig")
|
||||||
|
if (not (status1 and status2)) then return end
|
||||||
|
|
||||||
lsp_installer.on_server_ready(function(server)
|
return function(on_attach)
|
||||||
local opts = {}
|
mason.setup {}
|
||||||
|
mason_lspconfig.setup {
|
||||||
|
ensure_installed = { 'jdtls', 'lua_ls' }
|
||||||
|
}
|
||||||
|
|
||||||
server:setup(opts)
|
local no_autosetup = {
|
||||||
end)
|
jdtls = true
|
||||||
|
}
|
||||||
|
|
||||||
|
local extra_config = {
|
||||||
|
lua_ls = {
|
||||||
|
on_attach = on_attach,
|
||||||
|
settings = {
|
||||||
|
Lua = {
|
||||||
|
diagnostics = { globals = { 'vim' } },
|
||||||
|
workspace = {
|
||||||
|
library = vim.api.nvim_get_runtime_file("", true),
|
||||||
|
},
|
||||||
|
telemetry = { enable = false },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mason_lspconfig.setup_handlers {
|
||||||
|
function(server_name)
|
||||||
|
if (not no_autosetup[server_name]) then
|
||||||
|
require("lspconfig")[server_name].setup(
|
||||||
|
extra_config[server_name] or { on_attach = on_attach }
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
|
@ -42,7 +42,7 @@ return function(on_attach)
|
||||||
-- NOTE: You may or may not want java included here. You will need it if you
|
-- NOTE: You may or may not want java included here. You will need it if you
|
||||||
-- want basic Java support but it may also conflict if you are using
|
-- want basic Java support but it may also conflict if you are using
|
||||||
-- something like nvim-jdtls which also works on a java filetype autocmd.
|
-- something like nvim-jdtls which also works on a java filetype autocmd.
|
||||||
pattern = { "scala", "sbt", "java" },
|
pattern = { "scala", "sbt" },
|
||||||
callback = function()
|
callback = function()
|
||||||
require("metals").initialize_or_attach(metals_config)
|
require("metals").initialize_or_attach(metals_config)
|
||||||
end,
|
end,
|
||||||
|
|
|
@ -2,18 +2,20 @@
|
||||||
|
|
||||||
--lsp_status.register_progress()
|
--lsp_status.register_progress()
|
||||||
|
|
||||||
|
local map = vim.keymap.set
|
||||||
|
map("n", "<leader>dr", function() require("dap").repl.toggle() end, { silent = true })
|
||||||
|
|
||||||
-- Use an on_attach function to only map the following keys
|
-- Use an on_attach function to only map the following keys
|
||||||
-- after the language server attaches to the current buffer
|
-- after the language server attaches to the current buffer
|
||||||
local on_attach = function(client, bufnr)
|
local on_attach = function(client, bufnr)
|
||||||
local map = vim.keymap.set
|
|
||||||
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
|
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
|
||||||
|
|
||||||
--Enable completion triggered by <c-x><c-o>
|
--Enable completion triggered by <c-x><c-o>
|
||||||
vim.bo[bufnr].omnifunc = 'v:lua.vim.lsp.omnifunc'
|
vim.bo[bufnr].omnifunc = 'v:lua.vim.lsp.omnifunc'
|
||||||
|
|
||||||
-- Mappings.
|
-- Mappings.
|
||||||
local opts = { silent=true, buffer=bufnr }
|
local opts = { silent = true, buffer = bufnr }
|
||||||
local loud = { buffer=bufnr }
|
local loud = { buffer = bufnr }
|
||||||
|
|
||||||
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
||||||
map('n', 'gD', vim.lsp.buf.declaration, opts)
|
map('n', 'gD', vim.lsp.buf.declaration, opts)
|
||||||
|
@ -24,16 +26,15 @@ local on_attach = function(client, bufnr)
|
||||||
map('n', '<C-k>', vim.lsp.buf.signature_help, opts)
|
map('n', '<C-k>', vim.lsp.buf.signature_help, opts)
|
||||||
map('n', '<Leader>D', vim.lsp.buf.type_definition, opts)
|
map('n', '<Leader>D', vim.lsp.buf.type_definition, opts)
|
||||||
map('n', '<Leader>rn', vim.lsp.buf.rename, opts)
|
map('n', '<Leader>rn', vim.lsp.buf.rename, opts)
|
||||||
map('n', '<M-a>', vim.lsp.buf.code_action, loud)
|
map('n', '<M-x>', vim.lsp.buf.code_action, loud)
|
||||||
map('n', '<M-s>', vim.lsp.codelens.run, loud)
|
map('n', '<M-s>', vim.lsp.codelens.run, loud)
|
||||||
map('n', 'gr', vim.lsp.buf.references, opts)
|
map('n', 'gr', vim.lsp.buf.references, opts)
|
||||||
map('n', '<M-e>', vim.diagnostic.open_float, opts)
|
map('n', '<M-e>', vim.diagnostic.open_float, opts)
|
||||||
map('n', '[d', vim.diagnostic.goto_prev, opts)
|
map('n', '[d', vim.diagnostic.goto_prev, opts)
|
||||||
map('n', ']d', vim.diagnostic.goto_next, opts)
|
map('n', ']d', vim.diagnostic.goto_next, opts)
|
||||||
map('n', '<M-q>', vim.diagnostic.setloclist, opts)
|
map('n', '<M-q>', vim.diagnostic.setloclist, opts)
|
||||||
map("n", "<Leader>f", vim.lsp.buf.formatting, opts)
|
map("n", "<Leader>f", function() vim.lsp.buf.format { async = true } end, opts)
|
||||||
map("n", "<leader>dc", function() require("dap").continue() end, opts)
|
map("n", "<leader>dc", function() require("dap").continue() end, opts)
|
||||||
map("n", "<leader>dr", function() require("dap").repl.toggle() end, opts)
|
|
||||||
map("n", "<leader>dK", function() require("dap.ui.widgets").hover() end, opts)
|
map("n", "<leader>dK", function() require("dap.ui.widgets").hover() end, opts)
|
||||||
map("n", "<leader>dt", function() require("dap").toggle_breakpoint() end, opts)
|
map("n", "<leader>dt", function() require("dap").toggle_breakpoint() end, opts)
|
||||||
map("n", "<leader>dso", function() require("dap").step_over() end, opts)
|
map("n", "<leader>dso", function() require("dap").step_over() end, opts)
|
||||||
|
@ -44,13 +45,15 @@ local on_attach = function(client, bufnr)
|
||||||
map("n", "<leader>aw", function() vim.diagnostic.setqflist({ severity = "W" }) end, opts)
|
map("n", "<leader>aw", function() vim.diagnostic.setqflist({ severity = "W" }) end, opts)
|
||||||
map("n", "<leader>ae", function() vim.diagnostic.setqflist({ severity = "E" }) end, opts)
|
map("n", "<leader>ae", function() vim.diagnostic.setqflist({ severity = "E" }) end, opts)
|
||||||
|
|
||||||
vim.cmd [[autocmd BufEnter,CursorHold,InsertLeave <buffer> lua vim.lsp.codelens.refresh()]]
|
vim.cmd [[autocmd BufEnter,BufWrite <buffer> lua vim.lsp.codelens.refresh()]]
|
||||||
-- vim.cmd [[autocmd CursorHoldI * silent! lua vim.lsp.buf.signature_help()]]
|
vim.cmd [[autocmd CursorHoldI * silent! lua vim.lsp.buf.signature_help()]]
|
||||||
vim.cmd [[autocmd CursorHold * lua vim.diagnostic.open_float({max_width = 100, focusable = false})]]
|
vim.cmd [[autocmd CursorHold * lua vim.diagnostic.open_float({max_width = 100, focusable = false})]]
|
||||||
|
|
||||||
|
vim.lsp.codelens.refresh()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
require("lsp.installer")(on_attach)
|
||||||
require("lsp.metals")(on_attach)
|
require("lsp.metals")(on_attach)
|
||||||
|
|
||||||
require("lsp.typescript")(on_attach)
|
require("lsp.typescript")(on_attach)
|
||||||
|
|
||||||
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
|
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
|
||||||
|
@ -58,14 +61,16 @@ vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
|
||||||
virtual_text = false,
|
virtual_text = false,
|
||||||
underline = true,
|
underline = true,
|
||||||
signs = true,
|
signs = true,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(
|
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(
|
||||||
vim.lsp.handlers.signature_help, {
|
vim.lsp.handlers.signature_help, {
|
||||||
silent = true, focusable = false
|
silent = true, focusable = false
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
local signature_help_cfg = {}
|
local signature_help_cfg = {}
|
||||||
require "lsp_signature".setup(signature_help_cfg)
|
require "lsp_signature".setup(signature_help_cfg)
|
||||||
|
|
||||||
|
return { on_attach = on_attach }
|
||||||
|
|
|
@ -39,7 +39,8 @@ Plug 'hrsh7th/vim-vsnip'
|
||||||
Plug 'hrsh7th/vim-vsnip-integ'
|
Plug 'hrsh7th/vim-vsnip-integ'
|
||||||
Plug 'nvim-lua/plenary.nvim'
|
Plug 'nvim-lua/plenary.nvim'
|
||||||
Plug 'scalameta/nvim-metals'
|
Plug 'scalameta/nvim-metals'
|
||||||
Plug 'williamboman/nvim-lsp-installer'
|
Plug 'williamboman/mason.nvim'
|
||||||
|
Plug 'williamboman/mason-lspconfig.nvim'
|
||||||
|
|
||||||
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
|
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
|
||||||
Plug 'nvim-lua/lsp-status.nvim'
|
Plug 'nvim-lua/lsp-status.nvim'
|
||||||
|
@ -52,6 +53,7 @@ Plug 'nvim-telescope/telescope.nvim'
|
||||||
Plug 'nvim-telescope/telescope-fzf-native.nvim', { 'do': 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build' }
|
Plug 'nvim-telescope/telescope-fzf-native.nvim', { 'do': 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build' }
|
||||||
Plug 'gbrlsnchs/telescope-lsp-handlers.nvim'
|
Plug 'gbrlsnchs/telescope-lsp-handlers.nvim'
|
||||||
Plug 'ray-x/lsp_signature.nvim'
|
Plug 'ray-x/lsp_signature.nvim'
|
||||||
|
Plug 'mfussenegger/nvim-jdtls'
|
||||||
|
|
||||||
Plug 'mfussenegger/nvim-dap'
|
Plug 'mfussenegger/nvim-dap'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue