fwcd / kotlin-debug-adapter

Kotlin/JVM debugging for any editor/IDE using the Debug Adapter Protocol
MIT License
120 stars 24 forks source link

Debugging unit tests #84

Closed xsh005 closed 11 months ago

xsh005 commented 11 months ago

Is there any way I can debug tests without specifying a mainClass?

This doesn't work :( ```lua { type = "kotlin", request = "launch", name = "This test file", mainClass = function() local root = vim.fs.find("src", { path = vim.uv.cwd(), upward = true, stop = vim.env.HOME })[1] or "" local fname = vim.api.nvim_buf_get_name(0) return fname:gsub(root, ""):gsub("test/kotlin/", ""):gsub(".kt", "Kt"):gsub("/", "."):sub(2, -1) end, projectRoot = vim.fn.getcwd, jsonLogFile = "", enableJsonLogging = false, } ``` So `mainClass` gives `websearch.SomeTestKt` for `src/test/kotlin/websearch/SomeTest.kt`, `projectRoot` gives the project root with a `build.gradle`, `build/*` and stuff. But when I run a debug session, it told me `Error: Could not find or load main class websearch.SomeTestKt`, which is to be expected since there is no main class I have precompiled the project: ``` file build/classes/kotlin/test/websearch/SomeTest.class build/classes/kotlin/test/websearch/SomeTest.class : compiled Java class data, version 61.0 ( Java SE 17) ```

Any help is greatly appreciated!

xsh005 commented 11 months ago

Should have read the docs. sorry :(