mfussenegger / nvim-jdtls

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

Running tests fails because of weirdly structured `launch_args` #436

Closed gudjonragnar closed 1 year ago

gudjonragnar commented 1 year ago

LSP client configuration

local config = {}
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/gudjon/.m2/repository/org/projectlombok/lombok/1.18.20/lombok-1.18.20.jar',

  '-jar', '/home/user/.eclipse.jdt.ls/1.20.0/plugins/org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar',
  '-configuration', '/home/user/.eclipse.jdt.ls/1.20.0/config_linux',
  '-data', workspace_dir
}

config.root_dir = require('jdtls.setup').find_root({ '.git', 'mvnw', 'gradlew', 'build.gradle', 'pom.xml' })

config.on_attach = function(client, bufnr)
  jdtls.setup_dap({ hotcodereplace = 'auto' })
  jdtls.setup.add_commands()
end

config.settings = {
  java = {
  }
}

local bundles = {
  vim.fn.glob(
    '/home/user/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-*.jar',
    1
  )
}

vim.list_extend(
  bundles,
  vim.split(vim.fn.glob('/home/user/vscode-java-test/server/*.jar', 1),
    '\n'
  )
)
config['init_options'] = {
  bundles = bundles,
}

require('jdtls').start_or_attach(config)

Eclipse.jdt.ls version

1.20.0

Steps to Reproduce

I have this issue in a gradle project using Gradle 7.3.2 and Java 17.

When I run :lua require'jdtls'.test_nearest_method() I get an error message saying:

Error executing vim.schedule lua callback: /home/user/.local/share/nvim/lazy/nvim-jdtls/lua/jdtls/dap.lua:307: bad argument #1 to 'concat' (table expected, got nil)
stack traceback:
    [C]: in function 'concat'
    /home/user/.local/share/nvim/lazy/nvim-jdtls/lua/jdtls/dap.lua:307: in function 'make_config'
    /home/user/.local/share/nvim/lazy/nvim-jdtls/lua/jdtls/dap.lua:447: in function 'on_launch_args'
    /home/user/.local/share/nvim/lazy/nvim-jdtls/lua/jdtls/dap.lua:253: in function 'handler'
    /usr/share/nvim/runtime/lua/vim/lsp.lua:1383: in function ''
    vim/_editor.lua: in function <vim/_editor.lua:0>

The line in question is (line numbers above are off by one because of a print statement i added):

    vmArgs = table.concat(launch_args.vmArguments, ' ');

I decided to print the launch_args object and got this table:

{
  body = {
    classpath = { ... },
    mainClass = "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner",
    modulepath = {},
    programArguments = { "-version", "3", "-port", "35301", "-testLoaderClass", "org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader", "-loaderpluginname", "org.eclipse.jdt.junit5.runtime", "-test", "path.to.test" },
    projectName = "project-name",
    vmArguments = { "-ea" },
    workingDirectory = "/home/user/dev/project-name"
  },
  classpath = { ... },
  status = 0
}

It seems like the launch_args are wrapped in this body table which messes things up. When I add

local launch_args = launch_args.body

on line 244 (on tag 0.2.0) before the classpath is extended everything works fine and the test passes.

I am not sure if I may be doing something wrong which causes the launch args to be wrapped in the body object or if there is a change in vscode.java.test that causes this.

Expected Result

Tests run and pass/fail

Actual Result

Error executing vim.schedule lua callback: /home/user/.local/share/nvim/lazy/nvim-jdtls/lua/jdtls/dap.lua:307: bad argument #1 to 'concat' (table expected, got nil)
stack traceback:
    [C]: in function 'concat'
    /home/user/.local/share/nvim/lazy/nvim-jdtls/lua/jdtls/dap.lua:307: in function 'make_config'
    /home/user/.local/share/nvim/lazy/nvim-jdtls/lua/jdtls/dap.lua:447: in function 'on_launch_args'
    /home/user/.local/share/nvim/lazy/nvim-jdtls/lua/jdtls/dap.lua:253: in function 'handler'
    /usr/share/nvim/runtime/lua/vim/lsp.lua:1383: in function ''
    vim/_editor.lua: in function <vim/_editor.lua:0>
mfussenegger commented 1 year ago

Thanks for the report.

Looks like https://github.com/microsoft/vscode-java-test/commit/5a78371ad60e86f858eace7726f0980926b6c31d changed the response format. After I updated it locally it also started failing for me with the same error.

Should be fixed with https://github.com/mfussenegger/nvim-jdtls/pull/437

gudjonragnar commented 1 year ago

Ye I was about to post a follow up with that same commit. Thanks for the quick turnaround :+1: