Skip to content

Commit de41d62

Browse files
authored
Add Kotlin documentation to configuration guide (#748)
1 parent 6852763 commit de41d62

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

docs/page/configuration.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,52 @@ settings.
7373
:env '(("DEV" . "1"))))
7474
```
7575
76+
## Kotlin
77+
78+
1. Installation
79+
To use dap-mode with Kotlin, you need to download the [kotlin-debug-adapter](https://github.com/fwcd/kotlin-debug-adapter).
80+
The releases are a bit infrequent, so it is recommended to build it from source yourself.
81+
You will also need to have installed `lsp-mode`, as `dap-kotlin` shares some configuration with it.
82+
After building it, point the variable `lsp-kotlin-debug-adapter-path ` to the path of the kotlin-debug-adapter executable.
83+
You will find this in the path `adapter/build/install/adapter/bin` (from the kotlin-debug-adapter root).
84+
You should also make sure that `lsp-kotlin-debug-adapter-enabled` is set to true.
85+
86+
2. Usage
87+
**First of all, each time you you want to debug, make sure you BUILD YOUR PROJECT FIRST!**
88+
Simply running your regular build with Maven or Gradle should be enough.
89+
90+
You can set up debug templates using Kotlin. `dap-kotlin`provides some sensible defaults,
91+
but there are one parameters you MUST give yourself:
92+
- `:mainClass`: The class name, including package for the main class you want to run. If the class takes argument, you can give them as well.
93+
If project root path needs to be different, you can give it using the parameter `:projectRoot`.
94+
Other parameters include:
95+
- `:type`: `launch` or `attach`
96+
- `:hostName`: If type is `attach`, you can specify a hostname to connect to. Defaults to `localhost`.
97+
- `:port`: If type is `attach`, you can specify a port to connect to. Defaults to `5005`.
98+
- `:noDebug`: Whether or not to use a debug session
99+
- `:enableJsonLogging`: Enable logging of adapter communication logs.
100+
- `:jsonLogFile`: File to log to.
101+
102+
103+
Thanks to interop with `lsp-kotlin`, you can have it set up code lenses with run/debug-options for main classes.
104+
For this to work, you need kotlin-langauge-server running, be in a file with a main method, and have activated `lsp-kotlin-lens-mode`
105+
106+
Sadly, there is no test-running functionality like in Java `dap-mode`. This can be combated by setting up a debug template with
107+
the Junit5 `ConsoleLauncher`. Remember that this class needs to be part of your classpath. Sometimes this is included in bigger frameworks
108+
testing utilities, but can also be included explicitly by adding the `junit-platform-console` dependency.
109+
110+
```elisp
111+
(dap-register-debug-template "Kotlin tests with launcher"
112+
(list :type "kotlin"
113+
:request "launch"
114+
:mainClass "org.junit.platform.console.ConsoleLauncher --scan-class-path"
115+
:enableJsonLogging nil
116+
:noDebug nil))
117+
```
118+
This will run all tests in the projects in debug mode, with no json logging. You can experiment with the
119+
arguments to `ConsoleLauncher`. Arguments are documented on [the official JUnit website](https://junit.org/junit5/docs/current/user-guide/#running-tests-console-launcher-options).
120+
121+
76122
## Python
77123

78124
1. Installation

0 commit comments

Comments
 (0)