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
100 stars 8 forks source link

How to do "evaluate expression"? #4

Closed richi1807 closed 4 years ago

richi1807 commented 4 years ago

Hello,

One thing I really miss about IntelliJ is the evaluate expression feature when I can run arbitrary code on variables in the current stack. Could you help me figure out how to do this (or point me to documentation where I can read more about it)?

dansomething commented 4 years ago

Unfortunately I've had mixed results with evaluating expressions in this setup so your mileage may vary. That said here are the tips I can offer.

1) Checkout :VimspectorEval. You can use the prompt buffer in Vim or call the command in Neovim. 2) For a multi-module project you will have to set the projectName in the launch config in .vimspector.json. 3) If its not working, take a look at the various :VimspectorShowOutput options. For example, :VimspectorShowOutput Vimspector-out 4) Look for some error message to help you troubleshoot the problem. 5) Lastly, I've had times where it works fine and then it stops working for no reason. Often restarting Vim and the Java process being debugged have fixed the problem.


Here's a sample project where I am able to evaluate an expression while debugging. coc-java-debug-sample.tar.gz

And here's a rough list of the steps I used. 1) Extract the tarball tar -xzvf coc-java-debug-sample.tar.gz 2) cd into the project directory cd coc-java-debug-sample 3) Open the test file. vi src/test/java/com/github/AppTest.java 4) Set a breakpoint on line 18 5) Run the test in debug mode. ./mvnw test -Dmaven.surefire.debug 6) Connect Vim/Vimspector to the debug server :CocCommand java.debug.vimspector.start 7) The debugger should break on line 19 8) Eval some Java code :VimspectorEval getClass().getName() 9) The result is some Vimspector console output

Evaluating: getClass().getName()
Evaluated: getClass().getName()
  Result: "com.github.AppTest"

8) Here's what I see in the tail of :VimspectorShowOutput Vimspector-out

2020-05-13 08:40:23,852 - DEBUG - Sending Message: {"command": "evaluate", "arguments": {"expression": "getClass().getName()", "context": "repl", "frameId": 1}, "seq": 10, "type": "request"}
2020-05-13 08:40:23,852 - DEBUG - Calling: vimspector#internal#channel#Send(g:vimspector_internal_arg_0)
2020-05-13 08:40:23,923 - DEBUG - Message received: {'success': True, 'request_seq': 10, 'command': 'evaluate', 'body': {'result': '"com.github.AppTest"', 'variablesReference': 32, 'type': 'String', 'indexedVariables': 0}, 'seq': 15, 'type': 'response'}
stale[bot] commented 4 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 4 years ago

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