mfussenegger / nvim-jdtls

Extensions for the built-in LSP support in Neovim for eclipse.jdt.ls
GNU General Public License v3.0
979 stars 62 forks source link

Could not resolve java executable: Index 1 out of bound for lengh 1 #593

Closed Zeioth closed 7 months ago

Zeioth commented 7 months ago

LSP client configuration

-- 6. Java debugger.
if is_available "nvim-dap" then
  autocmd("BufRead", {
    desc = "On java files, start jdtls",
    callback = function()
      if vim.bo.filetype == "java" then
        local config = {
          cmd = { vim.fn.stdpath "data" .. "/mason/packages/jdtls/jdtls" },
          root_dir = vim.fs.dirname(vim.fs.find({ "gradlew", ".git", "mvnw" }, { upward = true })[1]),
          init_options = {
            bundles = {
              vim.fn.glob(vim.fn.stdpath "data" .. "/mason/packages/java-test/extension/server/*.jar", true),
              vim.fn.glob(vim.fn.stdpath "data" .. "/mason/packages/java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-*.jar", true),
            },
          },
        }
        require("jdtls").start_or_attach(config)

        -- Give enough time for jdt to fully load the project, or it will fail with
        -- "No LSP client found"
        local timer = 2500
        for _ = 0, 12, 1 do
          vim.defer_fn(
            function()
              require("jdtls.dap").setup_dap_main_class_configs()
            end,
            timer
          )
          timer = timer + 2500
        end
      end
    end,
  })
end

Eclipse.jdt.ls version

jdtls v1.30.0 → installed through mason

Steps to Reproduce

With the provided config, open a java file.

Expected Result

Adding a breakpoint and running DapConfinue opens DAP.

Actual Result

No configuration found for java. You need to add configs to dap.configurations.java (See :h dap-configurations)

Extra info: It was working fine in the past.

Zeioth commented 7 months ago

Screenshot screenshot_2023-12-10_20-16-55_859679031

Zeioth commented 7 months ago

The issue seem to happen when running the next line:

require("jdtls.dap").setup_dap_main_class_configs()

mfussenegger commented 7 months ago

This is probably not working because you opened a non-project file.

See https://github.com/mfussenegger/nvim-jdtls#is-a-non-project-file-only-syntax-errors-are-reported

On proper projects it works fine for me