coc-java-debug
Dan HansenJava langauage debugging extension for coc.nvim
Published Package Summary
coc-java-debug
An extension for coc.nvim to enable the Java Debug Server for the Java language server (jdt.ls) in Vim/Neovim.
It also provides an easy way to launch Vimspector and connect it to the Java debug server.
Features
- Integration with Vimspector.
- Launch Vimspector and connect to the Java debugger with a single command.
- Provide Vimspector config substitutions for the following Java project values:
- class paths
- main class
- module paths
- project name
- Configure Java debug settings.
Requirements
- Install the coc.nvim plugin.
- Install the Vimspector plugin.
- Install the coc-java extension.
Quick Start
Install the coc-java-debug extension.
:CocInstall coc-java-debug
Open a Java file with a main method in Vim.
Set a breakpoint in your main method.
Execute this Vim command.
:CocCommand java.debug.vimspector.start
Goals
- Provide a simple integration between Vimspector and the Java Debug Server.
- Provide Java-specific replacements for Vimspector's native config.
- See
java.debug.vimspector.substitution.*settings.
- See
- Support Vim and Neovim.
Non-Goals
- This project is not intended to be a clone of vscode-java-debug.
Usage and Setup
Debug a Main Method
This example will demonstrate how to load a Java program with a main method and debug it using Vimspector.
If you don't have a .vimspector.json file in the root directory of your Java project then coc-java-debug will create
one for you unless java.debug.vimspector.config.createIfNotExists is disabled.
If you already have a .vimspector.json file then add the config below.
{
"adapters": {
"coc-java-debug": {
"port": "${AdapterPort}"
}
},
"configurations": {
"javaLaunch": {
"default": true,
"adapter": "coc-java-debug",
"configuration": {
"args": "${args}",
"request": "launch",
"projectName": "${ProjectName}",
"mainClass": "${MainClass}",
"classPaths": ["*${ClassPaths}"]
},
"breakpoints": {
"exception": {
"caught": "N",
"uncaught": "N"
}
}
}
}
}
Next, open a Java file with a main method in Vim and set a breakpoint in your main method.
Execute the command to start debugging.
:CocCommand java.debug.vimspector.start
You will be prompted with
Enter value for args:
If you don't have any program arguments just press your enter key. Otherwise, type in your args just as you would from a terminal and then press your enter key.
At this point Vimspector should open and pause your Java program on the breakpoint you set.
That's it! You may now step debug your way through your Java program from within Vim.
Remote Debugging
This example will demonstrate attaching to a Java program that is running with remote debugging enabled. This is useful for debugging tests or running services.
Vimspector Attach Config
Add the following contents to the .vimspector.json file in the root directory of your Java project. Note, don't change
"${AdapterPort}". See issue #3 for an explanation of how this port value works.
{
"adapters": {
"coc-java-debug": {
"port": "${AdapterPort}"
}
},
"configurations": {
"javaAttach": {
"default": true,
"adapter": "coc-java-debug",
"configuration": {
"request": "attach",
"host": "127.0.0.1",
"port": "5005"
},
"breakpoints": {
"exception": {
"caught": "N",
"uncaught": "N"
}
}
}
}
}
Review the Vimspector config docs for what's possible within this file.
Configure Vim
This extension provides :CocCommand java.debug.vimspector.start to simplify launching Vimspector.
Note, it does not start your Java process in remote debug mode. An example of how to do that is covered below.
To further simplify, launching Vimspector, add the following config to your ~/.vimrc file or wherever appropriate for
your Vim setup.
" Press F1 key to launch Vimspector
nmap <F1> :CocCommand java.debug.vimspector.start<CR>
Start the Remote Debug Session
First, run a Java program with remote debugging enabled.
Be sure it is configured to pause and wait for a remote connection on port 5005 for this example work.
For a simple Java program. Create a Hello.java file with these contents.
public class Hello {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Next, run these commands from a shell to compile the program and then start it with remote debugging enabled.
javac -g Hello.java
java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=5005,suspend=y Hello
If everything works correctly you will see this message.
Listening for transport dt_socket at address: 5005
Now, open the file you want to debug in Vim and set a breakpoint with Vimspector.
Finally, start the debug session in Vim by pressing your F1 key or use your custom key mapping if you have altered the
config from this example. This should result in Vimspector opening in a new tab in Vim with your Java program paused at
the breakpoint you set.
That's it! You may now step debug your way through a Java program from within Vim.
Note, if you use a Java debug port different than 5005 you will need to change that value in your .vimspector.json
file. It is also possible to configure this port dynamically in Vimspector in the same manner as the debug adapter
port.
Also note, if you use Maven for builds you may start remote debugging for tests and then run Vimspector.
mvn test -Dmaven.surefire.debug
License
EPL 2.0, See LICENSE for more information.
- Java langauage debugging extension for coc.nvim
- onLanguage:java
Want to build, test, or contribute to coc.nvim extensions? Explore our official SDK and testing toolkits.
Open Developer GuideVersion History
This published npm package does not include a history.md or changelog.md file. Browse its npm versions or repository releases for available release information.
Contributed Commands
All contributes.commands entries from the published package manifest for coc-java-debug@1.0.0.
| Command (:CocCommand) | Description |
|---|---|
| java.debug.vimspector.start | Launch Vimspector and connect it to the Java Debug Server. |
| java.debug.settings.update | Update debug settings. |
| java.debug.resolveMainMethod | Show resolved main methods. |
| java.debug.resolveClasspath | Show resolved class paths. |
Configuration Schema
All contributes.configuration entries from the published package manifest, including each raw property schema for coc-settings.json.
Raw JSON Schema
{
"enum": [
"error",
"warn",
"info",
"verbose"
],
"type": "string",
"scope": "window",
"default": "warn",
"description": "minimum level of debugger logs that are sent to language server"
}Raw JSON Schema
{
"type": "boolean",
"scope": "window",
"default": false,
"description": "show numbers in hex format in `Variables` viewlet"
}Raw JSON Schema
{
"enum": [
"auto",
"on",
"off"
],
"type": "string",
"scope": "window",
"default": "off",
"description": "Experimental: Controls whether the debugger is allowed to send JDWP commands asynchronously"
}Raw JSON Schema
{
"type": "boolean",
"scope": "window",
"default": true,
"description": "show 'toString()' value for all classes that override 'toString' method in `Variables` viewlet"
}Raw JSON Schema
{
"enum": [
"auto",
"manual",
"never"
],
"type": "string",
"scope": "window",
"default": "manual",
"description": "Reload the changed Java classes during debugging"
}Raw JSON Schema
{
"type": "number",
"scope": "window",
"default": 0,
"description": "the maximum length of string displayed in `Variables` viewlet, the string longer than this length will be trimmed, defaults to 0 which means no trim is performed"
}Raw JSON Schema
{
"type": "number",
"scope": "window",
"default": 0,
"description": "the precision when formatting doubles in `Variables` viewlet"
}Raw JSON Schema
{
"type": "boolean",
"scope": "window",
"default": false,
"description": "show fully qualified class names in `Variables` viewlet"
}Raw JSON Schema
{
"type": "number",
"scope": "window",
"default": 3000,
"minimum": 100,
"description": "The timeout (ms) of JDWP request when the debugger communicates with the target JVM"
}Raw JSON Schema
{
"type": "boolean",
"scope": "window",
"default": false,
"description": "Show static variables in `Variables` viewlet"
}Raw JSON Schema
{
"type": "boolean",
"scope": "window",
"default": true,
"description": "show the logical structure for the Collection and Map classes in `Variables` viewlet"
}Raw JSON Schema
{
"type": "array",
"items": {
"anyOf": [
{
"enum": [
"$JDK",
"$Libraries",
"java.lang.ClassLoader",
""
],
"enumDescriptions": [
"Skip the JDK classes from the default system bootstrap classpath, such as rt.jar, jrt-fs.jar",
"Skip the classes from application libraries, such as Maven, Gradle dependencies",
"Skip the classloaders",
"Skip the specified classes. Wildcard is supported"
]
},
"string"
]
},
"scope": "window",
"default": [],
"description": "Skip the specified classes when stepping"
}Raw JSON Schema
{
"type": "boolean",
"scope": "window",
"default": false,
"description": "Skip synthetic methods when stepping"
}Raw JSON Schema
{
"type": "string",
"scope": "window",
"default": "MainClass",
"description": "Specifies the main class substitution name in `.vimspector.json`. The actual Java main class will replace this value in the Vimspector config."
}Raw JSON Schema
{
"type": "boolean",
"scope": "window",
"default": false,
"description": "Skip constructor methods when stepping"
}Raw JSON Schema
{
"type": "string",
"scope": "window",
"default": "ClassPaths",
"description": "Specifies the class paths substitution name in `.vimspector.json`. The actual Java class paths will replace this value in the Vimspector config."
}Raw JSON Schema
{
"type": "boolean",
"scope": "window",
"default": "true",
"description": "Determines if a .vimspector.json config should be created in the workspace if one doesn't already exist."
}Raw JSON Schema
{
"type": "string",
"scope": "window",
"default": "AdapterPort",
"description": "Specifies the adapter port substitution name in `.vimspector.json`. The actual port number will replace this value in the Vimspector config when the Java debug server is started."
}Raw JSON Schema
{
"type": "string",
"scope": "window",
"default": "ModulePaths",
"description": "Specifies the module paths substitution name in `.vimspector.json`. The actual Java module paths will replace this value in the Vimspector config."
}Raw JSON Schema
{
"type": "string",
"scope": "window",
"default": "ProjectName",
"description": "Specifies the project name substitution name in `.vimspector.json`. The actual Java project name will replace this value in the Vimspector config."
}Raw JSON Schema
{
"enum": [
"on",
"off"
],
"type": "string",
"scope": "window",
"default": "off",
"description": "Experimental: Enable debugging support on the decompiled source code"
}Raw JSON Schema
{
"type": "array",
"items": {
"anyOf": [
{
"enum": [
"$JDK",
"$Libraries",
"java.lang.ClassLoader",
""
],
"enumDescriptions": [
"Skip the JDK classes from the default system bootstrap classpath, such as rt.jar, jrt-fs.jar",
"Skip the classes from application libraries, such as Maven, Gradle dependencies",
"Skip the classloaders",
"Skip the specified classes. Wildcard is supported"
]
},
"string"
]
},
"scope": "window",
"default": [],
"description": "Skip the specified classes when breaking on exception"
}Raw JSON Schema
{
"type": "boolean",
"scope": "window",
"default": false,
"description": "Skip static initializer methods when stepping"
}Raw JSON Schema
{
"type": "array",
"scope": "window",
"default": [],
"description": "Specifies the allowed locations where the exception breakpoint can break on. Wildcard is supported, e.g. java.*, *.Foo"
}Raw JSON Schema
{
"type": "array",
"scope": "window",
"default": [],
"description": "Specifies a set of exception types you want to break on"
}Raw JSON Schema
{
"type": "number",
"scope": "window",
"default": 100,
"minimum": 1,
"description": "The maximum number of variables or fields that can be requested in one JDWP request"
}