Closed PauloPintor closed 12 months ago
Is this still an issue with recent eclipse.jdt.ls + java-debug & nvim-jdtls?
If so, could you share a project setup where it happens?
Checked with the master repo, yes the bug is reproduced with the above config. Checked on an individual java file.
@PauloPintor Please wrap all of your logs and blocks of code in triple backticks on a new line on the top and bottom of each section. They are difficult to read as of now. Like this:
``` my code with code formatting goes in here ```
becomes
my code
with code formatting
goes in here
You should add "lua" after the top backticks for chunks of lua code and it will add syntax highlighting, i.e.:
```lua local audience = "world" print("Hello " .. audience) ```
local audience = "world"
print("Hello " .. audience)
LSP client configuration
local status, jdtls = pcall(require, "jdtls") if not status then return end
-- GENERAL SETTINGS
-- Determine OS local home = os.getenv("HOME") if vim.fn.has("mac") == 1 then WORKSPACE_PATH = home .. "/.cache/jdtls/workspace/" CONFIG = "mac" elseif vim.fn.has("unix") == 1 then WORKSPACE_PATH = home .. "/.cache/jdtls/workspace/" CONFIG = "linux" else print("Unsupported system") end
-- Find root of project local root_markers = { ".git", "mvnw", "gradlew", "pom.xml", "build.gradle" } local root_dir = require("jdtls.setup").find_root(root_markers)
local project_name = vim.fn.fnamemodify(root_dir, ":p:h:t")
local workspace_dir = WORKSPACE_PATH .. project_name
--Make sure DAP is activated by default JAVA_DAP_ACTIVE = true
-- Prepare JAR dependencies
--Debugging local bundles = { vim.fn.glob(home .. "/.config/nvim/jars/java-debug/com.microsoft.java.debug.plugin-*.jar", 1), }
--Testing for _, bundle in ipairs(vim.split(vim.fn.glob(home .. "/.config/nvim/jars/vscode-java-test/server/*.jar", 1), "\n")) do --These two jars are not bundles, therefore don't put them in the table if not vim.endswith(bundle, "com.microsoft.java.test.runner-jar-with-dependencies.jar") and not vim.endswith(bundle, "com.microsoft.java.test.runner.jar") then table.insert(bundles, bundle) end end
--Decompiler for _, bundle in ipairs(vim.split(vim.fn.glob(home .. "/.config/nvim/jars/vscode-java-decompiler/server/*.jar", 1), "\n")) do table.insert(bundles, bundle) end
-- Prepare on_attach and capabilities
-- Highlight symbol under cursor local function lsp_highlight(client, bufnr) if client.supports_method("textDocument/documentHighlight") then vim.api.nvim_create_augroup("lsp_document_highlight", { clear = false, }) vim.api.nvim_clear_autocmds({ buffer = bufnr, group = "lsp_document_highlight", }) vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, { group = "lsp_document_highlight", buffer = bufnr, callback = vim.lsp.buf.document_highlight, }) vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, { group = "lsp_document_highlight", buffer = bufnr, callback = vim.lsp.buf.clear_references, }) end end
local on_attach = function(client, bufnr) if client.name == "jdtls" then require("jdtls.setup").add_commands() require("jdtls").setup_dap({ hotcodereplace = "auto" }) require("jdtls.dap").setup_dap_main_class_configs() require("lsp_signature").on_attach({ bind = true, use_lspsaga = false, floating_window = true, fix_pos = true, hint_enable = false, hi_parameter = "Search", handler_opts = { border = "rounded", }, }) lsp_highlight(client, bufnr) end end
local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities.textDocument.completion.completionItem.snippetSupport = true
local extendedClientCapabilities = jdtls.extendedClientCapabilities extendedClientCapabilities.resolveAdditionalTextEditsSupport = true
-- Server settings
-- See
:help vim.lsp.start_client
for an overview of the supportedconfig
options. local config = { -- The command that starts the language server -- See: https://github.com/eclipse/eclipse.jdt.ls#running-from-the-command-line cmd = {}
vim.api.nvim_create_autocmd({ "BufWritePost" }, { pattern = { "*.java" }, callback = function() vim.lsp.codelens.refresh() end, })
-- This starts a new client & server, -- or attaches to an existing client & server depending on the
root_dir
. require("jdtls").start_or_attach(config)--JDTLS commands vim.cmd( "command! -buffer -nargs=? -complete=custom,v:lua.require'jdtls'._complete_compile JdtCompile lua require('jdtls').compile()"
)
vim.cmd(
"command! -buffer -nargs=? -complete=custom,v:lua.require'jdtls'._complete_set_runtime JdtSetRuntime lua require('jdtls').set_runtime()"
)
vim.cmd("command! -buffer JdtUpdateConfig lua require('jdtls').update_project_config()")
vim.cmd("command! -buffer JdtJol lua require('jdtls').jol()")
vim.cmd("command! -buffer JdtBytecode lua require('jdtls').javap()")
vim.cmd("command! -buffer JdtJshell lua require('jdtls').jshell()")
Eclipse.jdt.ls version
1.22
Steps to Reproduce
When I just enter in a *.java file I get the error of: Could not resolve java executable: Index 1 out of bounds for length 1.
This happens because of this command: require("jdtls.dap").setup_dap_main_class_configs()
So when I try to debug it says: No configuration found for
java
. You need to add configs todap.configurations.java
(See:h dap-configuration
)If I try your command JdtRefreshDebugConfigs the editor says: E492: Not an editor command: JdtRefreshDebugConfigs
Expected Result
The result should be debugging a .java file
Actual Result
LspLog
[START][2023-04-23 10:55:49] LSP logging initiated [ERROR][2023-04-23 10:55:49] .../vim/lsp/rpc.lua:734 "rpc" "java" "stderr" "WARNING: Using incubator modules: jdk.incubator.foreign, jdk.incubator.vector\n" [WARN][2023-04-23 10:55:51] ...lsp/handlers.lua:137 "The language server jdtls triggers a registerCapability handler despite dynamicRegistration set to false. Report upstream, this warning is harmless" [ERROR][2023-04-23 10:55:51] ...lsp/handlers.lua:535 "23/04/2023, 10:55:51 Command _java.reloadBundles.command not supported on client" [ERROR][2023-04-23 10:55:54] ...lsp/handlers.lua:535 '23/04/2023, 10:55:54 Problems occurred when invoking code from plug-in: "org.eclipse.jdt.ls.core".\nIndex 1 out of bounds for length 1\njava.lang.IndexOutOfBoundsException: Index 1 out of bounds for length 1\n\tat java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)\n\tat java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)\n\tat java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)\n\tat java.base/java.util.Objects.checkIndex(Objects.java:359)\n\tat java.base/java.util.ArrayList.get(ArrayList.java:427)\n\tat com.microsoft.java.debug.plugin.internal.ResolveJavaExecutableHandler.resolveJavaExecutable(ResolveJavaExecutableHandler.java:52)\n\tat com.microsoft.java.debug.plugin.internal.JavaDebugDelegateCommandHandler.executeCommand(JavaDebugDelegateCommandHandler.java:92)\n\tat org.eclipse.jdt.ls.core.internal.handlers.WorkspaceExecuteCommandHandler$1.run(WorkspaceExecuteCommandHandler.java:230)\n\tat org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)\n\tat org.eclipse.jdt.ls.core.internal.handlers.WorkspaceExecuteCommandHandler.executeCommand(WorkspaceExecuteCommandHandler.java:220)\n\tat org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$4(JDTLanguageServer.java:584)\n\tat org.eclipse.jdt.ls.core.internal.BaseJDTLanguageServer.lambda$0(BaseJDTLanguageServer.java:87)\n\tat java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:646)\n\tat java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:483)\n\tat java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)\n\tat java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)\n\tat java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)\n\tat java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)\n\tat java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)\n' [ERROR][2023-04-23 10:55:54] ...lsp/handlers.lua:535 "23/04/2023, 10:55:54 Error in calling delegate command handler\nIndex 1 out of bounds for length 1\njava.lang.IndexOutOfBoundsException: Index 1 out of bounds for length 1\n\tat java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)\n\tat java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)\n\tat java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)\n\tat java.base/java.util.Objects.checkIndex(Objects.java:359)\n\tat java.base/java.util.ArrayList.get(ArrayList.java:427)\n\tat com.microsoft.java.debug.plugin.internal.ResolveJavaExecutableHandler.resolveJavaExecutable(ResolveJavaExecutableHandler.java:52)\n\tat com.microsoft.java.debug.plugin.internal.JavaDebugDelegateCommandHandler.executeCommand(JavaDebugDelegateCommandHandler.java:92)\n\tat org.eclipse.jdt.ls.core.internal.handlers.WorkspaceExecuteCommandHandler$1.run(WorkspaceExecuteCommandHandler.java:230)\n\tat org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)\n\tat org.eclipse.jdt.ls.core.internal.handlers.WorkspaceExecuteCommandHandler.executeCommand(WorkspaceExecuteCommandHandler.java:220)\n\tat org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$4(JDTLanguageServer.java:584)\n\tat org.eclipse.jdt.ls.core.internal.BaseJDTLanguageServer.lambda$0(BaseJDTLanguageServer.java:87)\n\tat java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:646)\n\tat java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:483)\n\tat java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)\n\tat java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)\n\tat java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)\n\tat java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)\n\tat java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)\n"