Skip to content

Instantly share code, notes, and snippets.

@gahrae
Created December 30, 2023 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gahrae/87a87c9ab6cc76c7b37ae57a1ec91258 to your computer and use it in GitHub Desktop.
Save gahrae/87a87c9ab6cc76c7b37ae57a1ec91258 to your computer and use it in GitHub Desktop.
-- Purpose: Debug a single Java class from within LazyVim
-- Overview of steps:
-- 1. Update ~/.config/nvim/lua/config/lazy.lua to enable the 'Java Extra'
-- 2. Add new plugin config at ~/.config/nvim/plugins/debug_java.lua
-- 3. Test: Add break point, hit <leader>dA, Observe debugging in action.
-- Notes:
-- 1. Works for a single Java file, larger projects likely will need other steps or configuration
-- 2. Solution was found on Reddit, see reference 1.
-- References:
-- 1) Reddit: https://www.reddit.com/r/neovim/comments/subfv1/help_setting_up_debugger_for_java/
-- 2) LazyVim's Java Extra: https://www.lazyvim.org/extras/lang/java
-- 3) Neovim: https://neovim.io
-- Fragment of file: lazy.lua ...
-- ...
require("lazy").setup({
spec = {
-- Add line below ...
{ import = "lazyvim.plugins.extras.lang.java" },
-- ...
},
-- ...
-- File: debug_java.lua
return {
"mfussenegger/nvim-dap",
optional = true,
dependencies = {
{
"williamboman/mason.nvim",
opts = function(_, opts)
opts.ensure_installed = opts.ensure_installed or {}
vim.list_extend(opts.ensure_installed, { "java-test", "java-debug-adapter" })
end,
},
},
keys = {
{
-- Shortcut chosen so it appears as the first option
"<leader>dA",
function()
require("jdtls.dap").setup_dap_main_class_configs()
require("dap").continue()
end,
desc = "Run",
},
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment