mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-25 14:01:06 +00:00
feat(java): allow opting out default keymaps
These keymaps cannot be disabled in the { keys = { '{lhs}', false } }
fashion. So instead, this patch offers a chance to disable them in
opts.keys.
It makes which-key.nvim an optional dependency too.
This commit is contained in:
parent
879e29504d
commit
ddde91f260
1 changed files with 33 additions and 28 deletions
|
|
@ -62,7 +62,7 @@ return {
|
||||||
-- Set up nvim-jdtls to attach to java files.
|
-- Set up nvim-jdtls to attach to java files.
|
||||||
{
|
{
|
||||||
"mfussenegger/nvim-jdtls",
|
"mfussenegger/nvim-jdtls",
|
||||||
dependencies = { "folke/which-key.nvim" },
|
dependencies = { { "folke/which-key.nvim", optional = true } },
|
||||||
ft = java_filetypes,
|
ft = java_filetypes,
|
||||||
opts = function()
|
opts = function()
|
||||||
return {
|
return {
|
||||||
|
|
@ -169,39 +169,44 @@ return {
|
||||||
callback = function(args)
|
callback = function(args)
|
||||||
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
||||||
if client and client.name == "jdtls" then
|
if client and client.name == "jdtls" then
|
||||||
local wk = require("which-key")
|
local ok, wk = pcall(require, "which-key")
|
||||||
wk.register({
|
local keys = vim.tbl_extend("force", {
|
||||||
["<leader>cx"] = { name = "+extract" },
|
action = ok,
|
||||||
["<leader>cxv"] = { require("jdtls").extract_variable_all, "Extract Variable" },
|
test = ok,
|
||||||
["<leader>cxc"] = { require("jdtls").extract_constant, "Extract Constant" },
|
}, opts.keys or {})
|
||||||
["gs"] = { require("jdtls").super_implementation, "Goto Super" },
|
if keys.action then
|
||||||
["gS"] = { require("jdtls.tests").goto_subjects, "Goto Subjects" },
|
wk.register({
|
||||||
["<leader>co"] = { require("jdtls").organize_imports, "Organize Imports" },
|
["<leader>cx"] = { name = "+extract" },
|
||||||
}, { mode = "n", buffer = args.buf })
|
["<leader>cxv"] = { require("jdtls").extract_variable_all, "Extract Variable" },
|
||||||
wk.register({
|
["<leader>cxc"] = { require("jdtls").extract_constant, "Extract Constant" },
|
||||||
["<leader>c"] = { name = "+code" },
|
["gs"] = { require("jdtls").super_implementation, "Goto Super" },
|
||||||
["<leader>cx"] = { name = "+extract" },
|
["gS"] = { require("jdtls.tests").goto_subjects, "Goto Subjects" },
|
||||||
["<leader>cxm"] = {
|
["<leader>co"] = { require("jdtls").organize_imports, "Organize Imports" },
|
||||||
[[<ESC><CMD>lua require('jdtls').extract_method(true)<CR>]],
|
}, { mode = "n", buffer = args.buf })
|
||||||
"Extract Method",
|
wk.register({
|
||||||
},
|
["<leader>c"] = { name = "+code" },
|
||||||
["<leader>cxv"] = {
|
["<leader>cx"] = { name = "+extract" },
|
||||||
[[<ESC><CMD>lua require('jdtls').extract_variable_all(true)<CR>]],
|
["<leader>cxm"] = {
|
||||||
"Extract Variable",
|
[[<ESC><CMD>lua require('jdtls').extract_method(true)<CR>]],
|
||||||
},
|
"Extract Method",
|
||||||
["<leader>cxc"] = {
|
},
|
||||||
[[<ESC><CMD>lua require('jdtls').extract_constant(true)<CR>]],
|
["<leader>cxv"] = {
|
||||||
"Extract Constant",
|
[[<ESC><CMD>lua require('jdtls').extract_variable_all(true)<CR>]],
|
||||||
},
|
"Extract Variable",
|
||||||
}, { mode = "v", buffer = args.buf })
|
},
|
||||||
|
["<leader>cxc"] = {
|
||||||
|
[[<ESC><CMD>lua require('jdtls').extract_constant(true)<CR>]],
|
||||||
|
"Extract Constant",
|
||||||
|
},
|
||||||
|
}, { mode = "v", buffer = args.buf })
|
||||||
|
end
|
||||||
if opts.dap and Util.has("nvim-dap") and mason_registry.is_installed("java-debug-adapter") then
|
if opts.dap and Util.has("nvim-dap") and mason_registry.is_installed("java-debug-adapter") then
|
||||||
-- custom init for Java debugger
|
-- custom init for Java debugger
|
||||||
require("jdtls").setup_dap(opts.dap)
|
require("jdtls").setup_dap(opts.dap)
|
||||||
require("jdtls.dap").setup_dap_main_class_configs()
|
require("jdtls.dap").setup_dap_main_class_configs()
|
||||||
|
|
||||||
-- Java Test require Java debugger to work
|
-- Java Test require Java debugger to work
|
||||||
if opts.test and mason_registry.is_installed("java-test") then
|
if opts.test and keys.test and mason_registry.is_installed("java-test") then
|
||||||
-- custom keymaps for Java test runner (not yet compatible with neotest)
|
-- custom keymaps for Java test runner (not yet compatible with neotest)
|
||||||
wk.register({
|
wk.register({
|
||||||
["<leader>t"] = { name = "+test" },
|
["<leader>t"] = { name = "+test" },
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue