Skip to content

Commit 00f3a71

Browse files
committed
Simple documentation on various debug configurations
1 parent aee89d1 commit 00f3a71

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

CONFIGURATION.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Configuration examples
2+
On this page we will collect some configuration examples. This is meant to help you configure debug templates for your editor. The examples are provided in JSON format, but should be easily translatable to VSCode launch.json files, Emacs dap-mode templates, etc.
3+
4+
5+
**NOTE: Some editors like Emacs using lsp-mode will require you to set a `noDebug` argument to `false`/`nil` to start a debug process, if not you will simply run the code.**
6+
7+
8+
**NOTE 2: A general tip for working with the debug adapter is building your codebase before launching the debugger. A lot of people experiencing "class not found"-style issues, and they are in most cases caused by not building before debugging. A simple Maven or Gradle compile should suffice.**
9+
10+
11+
## launch
12+
### Regular main method
13+
Replace the `mainClassName` with your fully qualified class name where your main method resides (e.g, `com.example.MyApplicationKt`), and `projectRootPath` with the root of your project. If your main method resides in a file, the class name will be the package and name of the file (+ Kt at the end).
14+
15+
16+
**Note:** If you use [the VSCode Kotlin extension](https://github.com/fwcd/vscode-kotlin) or [Emacs lsp-mode](https://emacs-lsp.github.io/lsp-mode/), you will have the option to use code lenses in your editor to run or debug main methods. These will fill out the details below automatically for you.
17+
18+
19+
```json
20+
{
21+
"type": "kotlin",
22+
"request": "launch",
23+
"mainClass": mainClassName,
24+
"projectRoot": projectRootPath
25+
}
26+
```
27+
28+
29+
### Test
30+
Debugging or running tests using the debug adapter might seem a bit daunting at first. What should the `mainClass` be? Fortunately it is quite simple if you use JUnit, as it provides a [Console Launcher](https://junit.org/junit5/docs/current/user-guide/#running-tests-console-launcher) that we can utilize.
31+
32+
```json
33+
{
34+
"type": "kotlin",
35+
"request": "launch",
36+
"mainClass": "org.junit.platform.console.ConsoleLauncher --scan-class-path",
37+
"projectRoot": projectRootPath
38+
}
39+
```
40+
41+
42+
For this to work, you will need the console launcher in your classpath during tests. Some JUnit related dependencies may already provide it, but you can also add it explicitly if you get ClassNotFound style errors (Maven example):
43+
```xml
44+
<dependency>
45+
<groupId>org.junit.platform</groupId>
46+
<artifactId>junit-platform-console-standalone</artifactId>
47+
<version>1.9.2</version>
48+
<scope>test</scope>
49+
</dependency>
50+
```
51+
52+
53+
There is [a neat plugin for Neovim utilizing this way of running tests already](https://github.com/Mgenuit/nvim-dap-kotlin).
54+
55+
56+
57+
## attach (connecting to an existing debug process)
58+
`attach` configurations are meant for attaching to already running processes. These could be processes you start in the terminal, from your editor or something else.
59+
60+
61+
The setup will be the same whether you connect to a regular main method debugging session, or a test session.
62+
63+
```json
64+
{
65+
"type": "kotlin",
66+
"request": "attach",
67+
"projectRoot": projectRootPath,
68+
"hostName": "localhost",
69+
"port": 5005,
70+
"timeout": 2000
71+
}
72+
```
73+
(replace `projectRootPath` with the path to your project root)
74+
75+
If you connect to a process on an external machine, then replace `"localhost"` with your hostname. You can also tweak the port (5005 is the default for both Maven and Gradle).
76+
77+
78+
## General: Logging to file
79+
If you want to add Kotlin Debug Adapter logging (client and debug adapter communications) to file, you can also the following parameters to any of the examples above:
80+
```json
81+
{
82+
"enableJsonLogging": true,
83+
"jsonLogFile": pathToLogFile
84+
}
85+
```
86+
(where `pathToLogFile` is replaced with the actual path to your log file)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Any editor conforming to DAP is supported, including [VSCode](https://github.com
1414
## Getting Started
1515
* See [BUILDING.md](BUILDING.md) for build instructions
1616
* See [Editor Integration](EDITORS.md) for editor-specific instructions
17+
* See [CONFIGURATION.md](CONFIGURATION.md) for examples on debug configurations (mostly editor agnostic).
1718
* See [Kotlin Quick Start](https://github.com/fwcd/kotlin-quick-start) for a sample project
1819
* See [Kotlin Language Server](https://github.com/fwcd/kotlin-language-server) for smart code completion, diagnostics and more
1920

0 commit comments

Comments
 (0)