0

I've been getting into Neovim more and I quite like it so far. I need to use java for university in a couple months so I've been setting that up. I've gotten java to run pretty good, but I'm running into issues setting up the debugger.

My config is based off kickstart.nvim, I cloned it a couple weeks ago and decided to go off on my own from there.

I tried to follow a guide to setup the java debugger after a bit of trouble shooting I managed to download java-debug and vscode-java-test using mason (which was 10x easier than the way they did it, I had a lot of issues). Afterwards the guide said to put the following code in a file, which to my knowledge attaches jdtls to the buffer.

...

local HOME = os.getenv "HOME"

-- Debugger installation location
local DEBUGGER_LOCATION = HOME .. "/.local/share/nvim"

-- Debugging
local bundles = {
  vim.fn.glob(
    DEBUGGER_LOCATION .. "/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-*.jar"
  ),
}
vim.list_extend(bundles, vim.split(vim.fn.glob(DEBUGGER_LOCATION .. "/vscode-java-test/server/*.jar"), "\n"))


local config = {
  ...
  
  on_attach = require("config.lsp").on_attach,

  -- If you don't plan on using the debugger or other eclipse.jdt.ls plugins you can remove this
  init_options = {
    bundles = bundles,
  },
}
...

I tried to change that code and put it in my own config, with a notable change being that I changed the path vim.fn.glob() gets because it didn't line up with the files I had, the result of that is the following (from line 500 in init.lua in my config if anyone wants to see that)

local HOME = os.getenv "HOME"

local DEBUGGER_LOCATION = HOME .. "/.local/share/nvim/mason/packages"

local jdtlsBundles = {
  vim.fn.glob(
    DEBUGGER_LOCATION .. "/java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-*.jar"
  ),
}
vim.list_extend(jdtlsBundles, vim.split(vim.fn.glob(DEBUGGER_LOCATION .. "/java-test/extension/server/*.jar"), "\n"))

local serverSettings = {
  -- clangd = {},
  -- gopls = {},
  pyright = {},
  -- rust_analyzer = {},
  -- tsserver = {},
  jdtls = {
    init_options = {
      bundles = jdtlsBundles
    }
  },

  lua_ls = {
    Lua = {
      workspace = { checkThirdParty = false },
      telemetry = { enable = false },
    },
  },
}
-- Setup neovim lua configuration
require('neodev').setup()

-- nvim-cmp supports additional completion capabilities, so broadcast that to servers
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)

-- Ensure the servers above are installed
local mason_lspconfig = require 'mason-lspconfig'

mason_lspconfig.setup {
  ensure_installed = vim.tbl_keys(serverSettings),
}


mason_lspconfig.setup_handlers {
  function(server_name)
    require('lspconfig')[server_name].setup {
      capabilities = capabilities,
      on_attach = on_attach,
      settings = serverSettings[server_name],
    }
  end,
}

Then finally the guide says to copy the following code in a file /lsp/init.lua so I assume that's to setup the lsp.

function M.on_attach(client, bufnr)
  ...
 
  -- Configure for jdtls
  if client.name == "jdt.ls" then
    require("jdtls").setup_dap { hotcodereplace = "auto" }
    require("jdtls.dap").setup_dap_main_class_configs()
    vim.lsp.codelens.refresh()
  end
end

From my understanding the last function in the previous code block does that, so in the on_attach function that it calls I copied this code directly. (line 480 in init.lua in my config).

Kickstart.nvim itself already has some setup done for nvim-dap, copying it all here seems overboard but this seems like the relevant part:

        require('mason-nvim-dap').setup {
            automatic_setup = true,

            handlers = {},

            ensure_installed = {
                'delve',
                'java-debug',
                'vscode-java-test',
            },
        }

as far as I remember I never changed this, but 'java-debug' and 'vs-code-java-test' aren't in base kickstart.nvim so I may have added those and forgotten.

From this point, the guide suggests things should be working, which they half are. When I'm in a java project, pressing F7 does give me a few windows that seems to be debug related (albeit that they're empty) however if I try to continue/run the debugger I get the error no configuration found for `java`. You need to add configs to `dap.configurations.java` (see `:h dap-configuration`) The guide suggests to run the command :JdtRefreshDebugConfigs, but that command doesn't exist for me.

And there I'm stuck right now, I've looked around a little for ways to solve my problem, but frankly I don't even know where to look, so I just decided to make a post here (this is a cross-post from a post on Neovim discourse https://neovim.discourse.group/t/cant-seem-to-figure-out-how-to-set-up-the-java-debug-adapter/4216). If anyone knows how to point me into the right direction, or knows what I'm doing wrong, any help is much appreciated! (please keep in mind that I'm pretty close to a complete beginner, so this could be a simple mistake I made)

1 Answer 1

0

you should change the client name to 'jdtls',

 -- Configure for jdtls
  if client.name == "jdtls" then
1
  • Welcome to Vi and Vim! This answer would be better if you edited to include details (teach 'em to fish), such as how someone could figure this out for themselves next time they have an issue with the client.name property
    – D. Ben Knoble
    Oct 8, 2023 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.