mfussenegger / nvim-jdtls

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

Only `JdtShowLogs` and `JdtWipeAndRestart` editor commands are available #542

Closed dibalikpohon closed 10 months ago

dibalikpohon commented 11 months ago

LSP client configuration

local bundles = {}
local mason_path = vim.fn.glob(vim.fn.stdpath "data" .. "/mason/")
vim.list_extend(bundles, vim.split(vim.fn.glob(mason_path .. "packages/java-test/extension/server/*.jar"), "\n"))
vim.list_extend(
  bundles,
  vim.split(
    vim.fn.glob(mason_path .. "packages/java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-*.jar"),
    "\n"
  )
)
local config = {
  cmd = {
    "java",
    "-Declipse.application=org.eclipse.jdt.ls.core.id1",
    "-Dosgi.bundles.defaultStartLevel=4",
    "-Declipse.product=org.eclipse.jdt.ls.core.product",
    "-Dlog.protocol=true",
    "-Dlog.level=ALL",
    "-Xms1g",
    "--add-modules=ALL-SYSTEM",
    "--add-opens",
    "java.base/java.util=ALL-UNNAMED",
    "--add-opens",
    "java.base/java.lang=ALL-UNNAMED",
    "-javaagent:" .. home .. "/.local/share/nvim/mason/packages/jdtls/lombok.jar",
    "-jar",
    vim.fn.glob(home .. "/.local/share/nvim/mason/packages/jdtls/plugins/org.eclipse.equinox.launcher_*.jar"),
    "-configuration",
    home .. "/.local/share/nvim/mason/packages/jdtls/config_" .. os_config,
    "-data",
    workspace_dir,
  },
  root_dir = require("jdtls.setup").find_root { ".git", "mvnw", "gradlew", "pom.xml", "build.gradle", "settings.gradle" },
  capabilities = capabilities,

  settings = {
    java = {
      eclipse = {
        downloadSources = true,
      },
      configuration = {
        updateBuildConfiguration = "interactive",
        runtimes = {
          {
            name = "JavaSE-20",
            path = "~/.sdkman/candidates/java/20.0.1-zulu",
          },
          {
            name = "JavaSE-19",
            path = "~/.sdkman/candidates/java/19.0.2-zulu",
          },
          {
            name = "JavaSE-17",
            path = "~/.sdkman/candidates/java/17.0.7-zulu"
          }
        },
      },
      maven = {
        downloadSources = true,
      },
      referencesCodeLens = {
        enabled = true,
      },
      references = {
        includeDecompiledSources = true,
      },
      inlayHints = {
        parameterNames = {
          enabled = "all", -- literals, all, none
        },
      },
      format = {
        enabled = false,
      },
    },
    signatureHelp = { enabled = true },
    extendedClientCapabilities = extendedClientCapabilities,
  },
  init_options = {
    bundles = bundles,
  },
}

config.on_attach = function(client, bufnr)
  local _, _ = pcall(vim.lsp.codelens.refresh)
  require("jdtls").setup_dap({ hotcodereplace = "auto" })
  require("lvim.lsp").on_attach(client, bufnr)
  require('jdtls.setup').add_commands()
  local status_ok, jdtls_dap = pcall(require, "jdtls.dap")
  if status_ok then
    jdtls_dap.setup_dap_main_class_configs()
  end
end

Eclipse.jdt.ls version

v1.26.0

Steps to Reproduce

  1. Followed this tutorial except google-java-format
  2. Open any java project (gradle-based, or maven-based)
  3. Wait until Log shows ServiceReady
  4. Type :Jdt then TAB

What have I done

I am having the similar issue as #393 but with different error log, followed the solution by adding require('jdtls.setup').add_commands() but nothing changed. Realizing that the latest commit already called add_commands() function inside start_or_attach()

Expected Result

Editor commands, such as JdtCompile, JdtSetRuntime, JdtUpdateConfig, JdtBytecode, JdtJol, JdtShell, JdtRestart are available

Actual Result

  1. Only editor command: JdtShowLogs, JdtWipeDataAndRestart are exists.

jdtls-workspace project log

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:39:28.644
!MESSAGE >> shutdown

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:39:28.680
!MESSAGE >> exit

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:39:28.816
!MESSAGE Shutdown received... waking up main thread

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:39:28.830
!MESSAGE class org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin is stopping:
!SESSION 2023-08-13 19:39:57.586 -----------------------------------------------
eclipse.buildId=unknown
java.version=20.0.1
java.vendor=Azul Systems, Inc.
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Command-line arguments:  -data /home/user/.local/share/lunarvim/jdtls-workspace/penjualan

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:40:00.736
!MESSAGE class org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin is started

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:40:01.315
!MESSAGE Main thread is waiting

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:40:01.464
!MESSAGE >> initialize

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:40:01.471
!MESSAGE Initializing Java Language Server 1.26.0.202307271613

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:40:01.473
!MESSAGE Started org.eclipse.m2e.core 0ms

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:40:03.142
!MESSAGE ProjectRegistryRefreshJob finished 1668ms

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:40:03.304
!MESSAGE Started org.eclipse.buildship.core 159ms

!ENTRY org.eclipse.jdt.ls.core 4 0 2023-08-13 19:40:03.338
!MESSAGE Failed to load extension bundles 
!STACK 1
org.eclipse.core.runtime.CoreException: Load bundle list
    at org.eclipse.jdt.ls.core.internal.handlers.BundleUtils.loadBundles(BundleUtils.java:172)
    at org.eclipse.jdt.ls.core.internal.handlers.InitHandler.handleInitializationOptions(InitHandler.java:109)
    at org.eclipse.jdt.ls.core.internal.handlers.BaseInitHandler.initialize(BaseInitHandler.java:64)
    at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.initialize(JDTLanguageServer.java:275)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:578)
    at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$recursiveFindRpcMethods$0(GenericEndpoint.java:65)
    at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.request(GenericEndpoint.java:120)
    at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleRequest(RemoteEndpoint.java:261)
    at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:190)
    at org.eclipse.jdt.ls.core.internal.ParentProcessWatcher.lambda$1(ParentProcessWatcher.java:144)
    at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:194)
    at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:94)
    at org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:113)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:577)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
    at java.base/java.lang.Thread.run(Thread.java:1623)
Contains: Failed to get bundleInfo for bundle from /home/user/.local/share/nvim/mason/packages/java-test/extension/server/com.microsoft.java.test.runner-jar-with-dependencies.jar
!SUBENTRY 1 org.eclipse.jdt.ls.core 4 0 2023-08-13 19:40:03.341
!MESSAGE Load bundle list
!SUBENTRY 2 org.eclipse.jdt.ls.core 4 0 2023-08-13 19:40:03.341
!MESSAGE Failed to get bundleInfo for bundle from /home/user/.local/share/nvim/mason/packages/java-test/extension/server/com.microsoft.java.test.runner-jar-with-dependencies.jar

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:40:03.391
!MESSAGE Static Commands: []

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:40:03.393
!MESSAGE Non-Static Commands: [java.project.import, java.navigate.openTypeHierarchy, java.project.resolveStackTraceLocation, java.edit.handlePasteEvent, java.edit.stringFormatting, java.project.getSettings, java.project.resolveWorkspaceSymbol, java.project.upgradeGradle, java.project.createModuleInfo, java.edit.organizeImports, java.project.refreshDiagnostics, java.project.removeFromSourcePath, java.project.listSourcePaths, java.project.getAll, java.reloadBundles, java.project.isTestFile, java.project.getClasspaths, java.navigate.resolveTypeHierarchy, java.edit.smartSemicolonDetection, java.project.updateSourceAttachment, java.decompile, java.protobuf.generateSources, java.project.resolveSourceAttachment, java.project.addToSourcePath, java.completion.onDidSelect]

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:40:03.395
!MESSAGE Static Commands: []

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:40:03.396
!MESSAGE Non-Static Commands: [vscode.java.test.findJavaProjects, vscode.java.test.findTestPackagesAndTypes, vscode.java.test.findTestTypesAndMethods, vscode.java.test.resolvePath, vscode.java.test.findTestLocation, vscode.java.test.get.testpath, vscode.java.test.findDirectTestChildrenForClass, vscode.java.test.navigateToTestOrTarget, vscode.java.test.junit.argument, vscode.java.test.generateTests]

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:40:03.398
!MESSAGE Static Commands: []

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:40:03.400
!MESSAGE Non-Static Commands: [vscode.java.checkProjectSettings, vscode.java.isOnClasspath, vscode.java.fetchUsageData, vscode.java.validateLaunchConfig, vscode.java.resolveInlineVariables, vscode.java.resolveClassFilters, vscode.java.resolveMainMethod, vscode.java.resolveClasspath, vscode.java.resolveBuildFiles, vscode.java.resolveMainClass, vscode.java.updateDebugSettings, vscode.java.resolveSourceUri, vscode.java.fetchPlatformSettings, vscode.java.buildWorkspace, vscode.java.startDebugSession, vscode.java.inferLaunchCommandLength, vscode.java.resolveElementAtSelection, vscode.java.resolveJavaExecutable]

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:40:03.462
!MESSAGE >> initialized

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:40:03.465
!MESSAGE RepositoryRegistryUpdateJob finished 1ms

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:40:04.613
!MESSAGE Importing Gradle project(s)

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:40:07.640
!MESSAGE Workspace initialized in 4176ms

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:40:07.710
!MESSAGE >> initialization job finished

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:40:07.720
!MESSAGE >> registerWatchers'

!ENTRY org.eclipse.jdt.ls.core 4 0 2023-08-13 19:40:09.171
!MESSAGE Command _java.reloadBundles.command not supported on client

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:40:09.191
!MESSAGE >> build jobs finished

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:40:09.614
!MESSAGE Reconciled 1. Took 1 ms

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:40:10.691
!MESSAGE begin problem for /App.java

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:40:10.692
!MESSAGE 0 problems reported for /App.java

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-13 19:40:10.694
!MESSAGE Validated 1. Took 474 ms

lsp.log on nvim

[START][2023-08-13 19:39:57] LSP logging initiated
[ERROR][2023-08-13 19:39:57] .../vim/lsp/rpc.lua:733    "rpc"   "java"  "stderr"    "WARNING: Using incubator modules: jdk.incubator.vector, jdk.incubator.concurrent\n"
[ERROR][2023-08-13 19:40:03] ...lsp/handlers.lua:485    "Aug 13, 2023, 7:40:03 PM Failed to load extension bundles \nLoad bundle list\norg.eclipse.core.runtime.CoreException: Load bundle list\n\tat org.eclipse.jdt.ls.core.internal.handlers.BundleUtils.loadBundles(BundleUtils.java:172)\n\tat org.eclipse.jdt.ls.core.internal.handlers.InitHandler.handleInitializationOptions(InitHandler.java:109)\n\tat org.eclipse.jdt.ls.core.internal.handlers.BaseInitHandler.initialize(BaseInitHandler.java:64)\n\tat org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.initialize(JDTLanguageServer.java:275)\n\tat java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)\n\tat java.base/java.lang.reflect.Method.invoke(Method.java:578)\n\tat org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$recursiveFindRpcMethods$0(GenericEndpoint.java:65)\n\tat org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.request(GenericEndpoint.java:120)\n\tat org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleRequest(RemoteEndpoint.java:261)\n\tat org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:190)\n\tat org.eclipse.jdt.ls.core.internal.ParentProcessWatcher.lambda$1(ParentProcessWatcher.java:144)\n\tat org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:194)\n\tat org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:94)\n\tat org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:113)\n\tat java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:577)\n\tat java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)\n\tat java.base/java.lang.Thread.run(Thread.java:1623)\nContains: Failed to get bundleInfo for bundle from /home/user/.local/share/nvim/mason/packages/java-test/extension/server/com.microsoft.java.test.runner-jar-with-dependencies.jar\n"
[WARN][2023-08-13 19:40:07] ...lsp/handlers.lua:113 "The language server jdtls triggers a registerCapability handler despite dynamicRegistration set to false. Report upstream, this warning is harmless"
[ERROR][2023-08-13 19:40:09] ...lsp/handlers.lua:485    "Aug 13, 2023, 7:40:09 PM Command _java.reloadBundles.command not supported on client"

Update

I can run command lua require('jdtls').* from the editor and it works. It seems like the commands JdtUpdateConfig and the others gets deleted somewhere probably in my config (i'm not good at lua, so just guessing)

kojogadget commented 11 months ago

I had the same issue, but seems I just places the config in the wrong file. After moving the config to $HOME/.config/nvim/ftplugin/java.lua it worked as expected. I guess the plugin is looking for this file and then overwriting your config related to jdtls if you place it else where

resticDOG commented 10 months ago

Same issue here. Just remove require("lvim.lsp").on_attach(client, bufnr) and It works.

mfussenegger commented 10 months ago

I guess the plugin is looking for this file and then overwriting your config related to jdtls if you place it else where

As the readme explains the ftplugin/ location is important. Read :help filetype-plugin to learn more on why.

Realizing that the latest commit already called add_commands() function inside start_or_attach()

Yes, but it does so only if your on_attach doesn't raise any errors. Try with an empty on_attach, or wrap more of the calls in pcall to ensure they don't fail. E.g.:

config.on_attach = function(client, bufnr)
  pcall(require("lvim.lsp").on_attach, client, bufnr)
end

Calling add_commands or setup_dap shouldn't be necessary anymore on the latest nvim-jdtls version.

apechinsky commented 8 months ago

Awesome!

I've moved entire 'on_attach' function body to another function and called it with pcall. As a result the error in on_attach_delegate became visible. Now everything works!

local function on_attach_delegate(_, bufnr)
    -- actual on_attach body
end
config.on_attach = function(client, bufnr)
    local res, err = pcall(on_attach_delegate, client, bufnr)
    if not res then
        vim.notify("Error: " .. err)
    end
end

It seems that start_or_attach silently swallows the errors. I suggest to add similar handler to the start_or_attach() function.