Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug junit classes or tests not working #31

Closed
jemag opened this issue Jan 24, 2021 · 8 comments
Closed

Debug junit classes or tests not working #31

jemag opened this issue Jan 24, 2021 · 8 comments

Comments

@jemag
Copy link

jemag commented Jan 24, 2021

Running lua require'jdtls'.test_nearest_method() only returns the following and does not execute any test:

image

Running the command does not generate new logs in lsp.log

Relevant config:

local on_attach_java = function(client)
    require'illuminate'.on_attach(client)
    require'completion'.on_attach(client)
    require('jdtls').setup_dap()
    require('jdtls').setup.add_commands()
    map('n', '<leader>lD','<cmd>lua vim.lsp.buf.declaration()<CR>')
    map('n', '<leader>ld','<cmd>lua vim.lsp.buf.definition()<CR>')
    map('n', '<C-q>','<cmd>lua vim.lsp.buf.hover()<CR>')
    map('n', '<leader>lh','<cmd>lua vim.lsp.buf.hover()<CR>')
    map('n', '<leader>lr','<cmd>lua vim.lsp.buf.references()<CR>')
    map('n', '<leader>ls','<cmd>lua vim.lsp.buf.signature_help()<CR>')
    map('n', '<leader>li','<cmd>lua vim.lsp.buf.implementation()<CR>')
    map('n', '<leader>lt','<cmd>lua vim.lsp.buf.type_definition()<CR>')
    map('n', '<leader>lw','<cmd>lua vim.lsp.buf.document_symbol()<CR>')
    map('n', '<leader>lW','<cmd>lua vim.lsp.buf.workspace_symbol()<CR>')
    -- ACTION mappings
    map('n', '<leader>la', "<Cmd>lua require'jdtls'.code_action()<CR>")
    map('v', '<leader>la', "<Esc><Cmd>lua require'jdtls'.code_action(true)<CR>")
    map('n', '<leader>lA', "<Cmd>lua require'jdtls'.code_action(false, 'refactor')<CR>")
    map('n', '<leader>lR',  '<cmd>lua vim.lsp.buf.rename()<CR>')
    -- Few language severs support these three
    map('n', '<leader>fF',  '<cmd>lua vim.lsp.buf.formatting()<CR>')
    -- Diagnostics mapping
    map('n', '<leader>ll', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>')
    map('n', '<leader>ln', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>')
    map('n', '<leader>lN', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>')

    map("n", "<leader>uo", "<Cmd>lua require'jdtls'.organize_imports()<CR>", opts)
    map("n", "<leader>ut", "<Cmd>lua require'jdtls'.test_class()<CR>", opts)
    map("n", "<leader>uT", "<Cmd>lua require'jdtls'.test_nearest_method()<CR>", opts)
    map("v", "<leader>ue", "<Esc><Cmd>lua require('jdtls').extract_variable(true)<CR>", opts)
    map("n", "<leader>ue", "<Cmd>lua require('jdtls').extract_variable()<CR>", opts)
    map("v", "<leader>um", "<Esc><Cmd>lua require('jdtls').extract_method(true)<CR>", opts)
end

local dap = require('dap')

dap.defaults.fallback.external_terminal = {
  command = '/usr/bin/alacritty';
  args = {'-e'};
}

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

function start_jdt()
    print("starting jdt")
    require('jdtls').start_or_attach({
    cmd = {'java-lsp.sh'},
    init_options = {
      bundles = bundles,
    },
    on_attach = function(client)
    --on_attach_common(client)
    on_attach_java(client)
    end
    })

end;

local autocmds = {
	lsp = {
		{"FileType",     "java",   "lua start_jdt()"};
	};
}

Full config at : https://gitlab.com/jemag/dotfiles/-/blob/nvim-lsp/neovim/.config/nvim/plugin-configs/nvim-lspconfig.vim

Checking lsp.log when opening a file from the project, I noticed the following error:

[ ERROR ] 2021-01-24T14:14:04-0500 ]
...neovim/build/share/nvim/runtime/lua/vim/lsp/handlers.lua:375 ]	"Jan 24,
  2021, 2:14:04 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:169)\n\tat
  org.eclipse.jdt.ls.core.internal.handlers.InitHandler.handleInitializationOptions(InitHandler.java:77)\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:230)\n\tat
  java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
      Method)\n\tat
  java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n\tat
  java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat
  java.base/java.lang.reflect.Method.invoke(Method.java:566)\n\tat
  org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$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$0(ParentProcessWatcher.java:123)\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:515)\n\tat
  java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)\n\tat
  java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\n\tat
  java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\n\tat
  java.base/java.lang.Thread.run(Thread.java:834)\nContains: Failed to get
  bundleInfo for bundle from
  /home/jemag/dev/vscode-java-test/server/com.microsoft.java.test.runner.jar\n"

However, unless I am missing something, the bundles seem to be properly configured when checking lua print(vim.inspect(vim.lsp.buf_get_clients()))

        bundles = { "/home/jemag/dev/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-0.29.0.jar", "/home/jemag/dev/vscode-java-test/server/com.micr
osoft.java.test.plugin-0.27.0.jar", "/home/jemag/dev/vscode-java-test/server/com.microsoft.java.test.runner.jar", "/home/jemag/dev/vscode-java-test/server/org.apiguardian_1.1.0.v201
90826-0900.jar", "/home/jemag/dev/vscode-java-test/server/org.eclipse.jdt.junit4.runtime_1.1.1200.v20200214-0716.jar", "/home/jemag/dev/vscode-java-test/server/org.eclipse.jdt.junit
5.runtime_1.0.900.v20200513-0617.jar", "/home/jemag/dev/vscode-java-test/server/org.junit.jupiter.api_5.6.0.v20200203-2009.jar", "/home/jemag/dev/vscode-java-test/server/org.junit.j
upiter.engine_5.6.0.v20200203-2009.jar", "/home/jemag/dev/vscode-java-test/server/org.junit.jupiter.migrationsupport_5.6.0.v20200203-2009.jar", "/home/jemag/dev/vscode-java-test/ser
ver/org.junit.jupiter.params_5.6.0.v20200203-2009.jar", "/home/jemag/dev/vscode-java-test/server/org.junit.platform.commons_1.6.0.v20200203-2009.jar", "/home/jemag/dev/vscode-java-t
est/server/org.junit.platform.engine_1.6.0.v20200203-2009.jar", "/home/jemag/dev/vscode-java-test/server/org.junit.platform.launcher_1.6.0.v20200203-2009.jar", "/home/jemag/dev/vsco
de-java-test/server/org.junit.platform.runner_1.6.0.v20200203-2009.jar", "/home/jemag/dev/vscode-java-test/server/org.junit.platform.suite.api_1.6.0.v20200203-2009.jar", "/home/jema
g/dev/vscode-java-test/server/org.junit.vintage.engine_5.6.0.v20200203-2009.jar", "/home/jemag/dev/vscode-java-test/server/org.opentest4j_1.2.0.v20190826-0900.jar" },

@mfussenegger
Copy link
Owner

Based on the screenshot it looks like the debug process is starting.
Do you see any output in the repl? (:lua require('dap').repl.open()).

The error in the logs should be harmless. It's coming from the com.microsoft.java.test.runner.jar which isn't a bundle and could be excluded from the bundles list.

@jemag
Copy link
Author

jemag commented Jan 24, 2021

My bad, I saw the terminal open with "Process exited 0" and I assumed the output was supposed to be there, I didn't even think of checking the REPL.

It does work with the REPL, although I think it may be misleading for new users to see that terminal open, especially since there doesn't seem to be any output in the REPL unless the test actually fails.

Is there any way to not trigger the opening of that terminal window?:
image

Do you also happen to know any way to be able to see whether the test pass or fails within the REPL window, instead of seeing only stacktrace in case of failure? For example, if I were to run the tests with gradle I would see something like:
image

@mfussenegger
Copy link
Owner

Although I think it may be misleading for new users to see that terminal open, especially since there doesn't seem to be any output in the REPL unless the test actually fails.

Yes I guess it should at least be mentioned in the documentation.

Is there any way to not trigger the opening of that terminal window?

Currently there isn't.
I think it would be possible to add some options to test_neareset_method to set the console option of the debug configuration. So you could choose between having the output of the debug process within a :term, within the repl or in an external terminal if configured.

Do you also happen to know any way to be able to see whether the test pass or fails within the REPL window, instead of seeing only stacktrace in case of failure? For example, if I were to run the tests with gradle I would see something like

It's currently not implemented. I wasn't sure how to best expose that.
I could add an option to load the failures into the quickfix list, but then you'd still not see the tests that passed. Bumping everything into the repl window may clutter too much? I'm not sure.

I'm open for suggestions.

@jemag
Copy link
Author

jemag commented Jan 28, 2021

I think it would be possible to add some options to test_neareset_method to set the console option of the debug configuration. So you could choose between having the output of the debug process within a :term, within the repl or in an external terminal if configured.

I think that could be nice.

It's currently not implemented. I wasn't sure how to best expose that.
I could add an option to load the failures into the quickfix list, but then you'd still not see the tests that passed. Bumping everything into the repl window may clutter too much? I'm not sure.

I haven't had too much time to look at how it all works behind the scenes (just trying to get a working setup for now) but, personally, I think having the success feedback is nice, and it might make it more intuitive for new users also. If the option above of outputting in terminal is implemented, could be something like the gradle output in the screenshot of my earlier comment.

Not sure how painful that would be to implement though.

@jlesquembre
Copy link

Would be possible to expose the generated command to run the test?
I'm thinking about playing a bit with a terminal plugin, I'd like to call test_nearest_method to get a command to run the tests (without executing it), and send it to a terminal

@mfussenegger
Copy link
Owner

#39 addresses the reporting.

I'll address the configuration options in a follow up PR

Would be possible to expose the generated command to run the test?

Yes I think that should be possible. I'll get back to this one I've addressed the other things

@mfussenegger
Copy link
Owner

mfussenegger commented Mar 16, 2021

Would be possible to expose the generated command to run the test?

#49 would make some of the methods accessible via require('jdtls.dap').experimental. Maybe you could have a look if that suites your needs.

@jemag

#49
Also adds the option to override the dap-configuration like this:

 test_nearest_method({ config = { console = 'console' }})

@jemag
Copy link
Author

jemag commented Mar 21, 2021

Just tested it and it works great. Thank you for that! Feel free to close the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants