dansomething / coc-java-debug

An extension for coc.nvim to enable Java debugging via jdt.ls
https://www.npmjs.com/package/coc-java-debug
Eclipse Public License 2.0
99 stars 8 forks source link

can not get variable evalution work for single class program #36

Closed nbfhscl closed 2 years ago

nbfhscl commented 2 years ago

Describe the issue can not get evalution work when debuging single class program without maven or gradel support.

I found this in vscode doc

projectName - The preferred project in which the debugger searches for classes. There could be duplicated class names in different projects. It is required when the workspace has multiple Java projects, otherwise the expression evaluation and conditional breakpoint may not work.

and this in vscode-java-debug repo

projectName - The preferred project in which the debugger searches for classes. It's required for the evaluation feature. Most of the time, the debugger will auto generate the configuration for you. In case you want to manually configure it, here are the rules.

When you open a maven project, the project name is the artifactId. When you open a gradle project, the project name is the baseName or the root folder name. When you open other Java files, leave the launch.json empty and allow the debugger auto generates the project name for you. Pro Tip: The easiest way to get the project name is to install Java Dependency Viewer extension, the top node in the JAVA DEPENDENCIES view is your project name.

when debuging in vscode, the projectName will be automatically generated, something like "test_c3ac9756" for example.

I tried some possible projectNames, but none of them could work.

To Reproduce

  1. write a single class program
  2. start it with remote debugging enabled
  3. attatch to it using vimspector without "projectName" besing set
  4. step debug works fine and left top window shows some variables, but evaluate variable in left middle watches window results error " *- Result: Cannot evaluate because of java.lang.IllegalStateException: Project leetcode cannot be found.."

Expected behavior able to watch expression. maybe get the ${projectName) like ${adapterPort}.

Versions of relevant software

Relevant logs and error messages

[Error - 11:04:18 PM] May 5, 2022, 11:04:18 PM [error response][evaluate]: Cannot evaluate because of java.lang.IllegalStateException: Cannot evaluate, please specify projectName in launch.json.. Cannot evaluate because of java.lang.IllegalStateException: Cannot evaluate, please specify projectName in launch.json.. com.microsoft.java.debug.core.DebugException: Cannot evaluate because of java.lang.IllegalStateException: Cannot evaluate, please specify projectName in launch.json.. at com.microsoft.java.debug.core.adapter.AdapterUtils.createCompletionException(AdapterUtils.java:246) at com.microsoft.java.debug.core.adapter.handler.EvaluateRequestHandler.lambda$handle$0(EvaluateRequestHandler.java:147) at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700) at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1692) at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290) at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020) at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656) at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594) at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183) Caused by: java.lang.IllegalStateException: Cannot evaluate, please specify projectName in launch.json. at com.microsoft.java.debug.plugin.internal.eval.JdtEvaluationProvider.findJavaProjectByType(JdtEvaluationProvider.java:277) at com.microsoft.java.debug.plugin.internal.eval.JdtEvaluationProvider.ensureDebugTarget(JdtEvaluationProvider.java:405) at com.microsoft.java.debug.plugin.internal.eval.JdtEvaluationProvider.evaluate(JdtEvaluationProvider.java:140) at com.microsoft.java.debug.plugin.internal.eval.JdtEvaluationProvider.evaluate(JdtEvaluationProvider.java:115) at com.microsoft.java.debug.core.adapter.handler.EvaluateRequestHandler.lambda$handle$0(EvaluateRequestHandler.java:84) ... 7 more

dansomething commented 2 years ago

I haven't been able to reproduce this exact error. Instead, when I try to watch a variable while debugging a standalone class, I get this error:

Result: Cannot evaluate because of compilation error(s): args cannot be resolved to a variable.

What versions are you using?

nbfhscl commented 2 years ago

What versions are you using?

I finally find projectName from path ~/.config/coc/extensions/coc-java-data/jdt_ws_85743e4f846fbd6d835ffe5eb77b8e60/leetcode_fb720b0e/bin/, where all my source files in the same folder is automatically copied into.

after set projectName in .vimspector.json to "leetcode_fb720b0e", I get the same error as you do.

*- Result: Cannot evaluate because of compilation error(s): i cannot be resolved to a variable.

Maybe you should create one more standardalone main class in same folder and the coc-java extension will require you to provide projectName parameter to distinguish between different java projects.

dansomething commented 2 years ago

I had already tried the generated project name. The project name seems to be there for disambiguation when there are duplicate class names across multiple loaded projects. In the case of the standalone file the project name is derived from the parent directory name and appears to remain the same for each Java file.

I can replicate this same error while attaching with the remote debugger in VSCode under certain scenarios. That said it could still just be a missing config parameter. It will take more debugging to track it down.

nbfhscl commented 2 years ago

After update all my coc extentions, the variables windows displays all the local variables, which is not before in my case. So temporarily no big problem for small java program debuging.

But still wish the "projectName" problem and the " Cannot evaluate because of compilation error(s): Evaluations must contain either an expression or a block of well-formed statements" problem could be solved.

dansomething commented 2 years ago

What I've determined is that the scope and the watch get populated correctly when the classpath is specified while remote debugging a standalone Java file. This leads me to believe there may be a bug in jdt.ls or the java debug plugin when dealing with standalone files.

This works as expected:

java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=localhost:5005 -cp "/Users/dan/.config/coc/extensions/coc-java-data/jdt_ws_133853e2933a3936a61aee74e647f114/hello-standalone-debug_d082081e/bin" Hello foo

This results in "compilation" and other problems in the watch:

java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=localhost:5005 Hello.java foo
stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 2 years ago

This issue has been automatically closed due to lack of activity.