fwcd / kotlin-debug-adapter

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

Ability to debug a Kotlin program (JVM, not Native), without gradle or maven #62

Open gandalfas opened 2 years ago

gandalfas commented 2 years ago

Suggestion

I would like to be able to debug (VS Code > Run > Start Debugging) a Kotlin/JVM program - without gradle or maven. Using VS Code's Run > Start Debugging, with a breakpoint set, the program simply runs to competion without stopping.

This is akin to #15. Ability to writing kotlin code without gradle or maven.

I am using your great extension (THANKS!!) in the experimental way - with a standalone Kotlin JVM compiler, no gradle, no maven. I hope to get this working - I am new at VS Code and Kotlin, but I love them both. I plan to write simple programs with it, so I don't want to use Gradle if I can avoid it. I am coming from the slow-starting IntelliJ IDEA (CE), and so far am loving the quick VS Code tool!

So if you can, please suggest any missing files, folders, or name changes I could do to get this working (short of installing Gradle and using it), and if possible, make fixes to your debug adapter where it might be expecting a gradle artifact.

Following are some details. Please let me know if you need anything else.

Thanks so much! Kim

1. SOURCE - Main.kt

    fun main() {
        println("main: hello world, it's Kotlin/JVM!")
        println()
    }

2. BUILDING - works

With VS Code, your extension, and a build task, I can successfully compile a simple program from VS Code.

    kotlinc-jvm "...\src\Main.kt"
      ->         ...\build\classes\kotlin\main\MainKt.class

3. EXECUTING - works

I started with source and .class files in the workspace root dir. There were errors in VS Code's Output Pane, Kotlin channel, that reported files missing from expected locations (dictated by gradle, I'm guessing). Based on those, I moved my source code to the 'src' subfolder and class files to the 'build\classes\kotlin\main' subfolder. That allowed me to execute the program from VS Code's Run > Run without Debugging. VS Code's Debug Console gave:

    main: hello world, it's Kotlin/JVM!

SIDE NOTE: It would be great if you could append a note to your "Support for Kotlin source files with a standalone compiler (kotlinc) is experimental." - the note could say to put your stuff into 'src' and 'build' folders.

4. DEBUGGING - fails to stop at breakpoint

The program simply runs to completion. I saw no errors that would lead me to a correct setup of files, folders, or other gradle-like setup.

Debug Console:

    [INFO] main      Connected to client
    [INFO] async1    Could not resolve kotlin-stdlib using Maven: null
    [INFO] async1    Could not resolve kotlin-stdlib using Gradle: C:\Users\Kim\.gradle\caches
    [INFO] async1    Found kotlinc.bat at C:\Program Files\Kotlin\kotlin-jvm-1.6.10\bin\kotlinc.bat
    [INFO] async1    Starting JVM debug session with main class MainKt
    main: hello world, it's Kotlin/JVM!

    [INFO] eventBus  Sent exit event
    [INFO] async0    Exiting JDI session

launch config:

        "configurations": [
            {
                "type": "kotlin",
                "request": "launch",
                "name": "Kotlin Launch",
                "projectRoot": "${workspaceFolder}",
                "mainClass": "MainKt"
                //"cwd": "${workspaceRoot}",
                //"stopOnEntry": "true"
            }
        ]

5. MY ENVIRONMENT

yingshaoxo commented 1 year ago

Same problem here.


My configurations:

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "kotlin",
            "request": "launch",
            "name": "Kotlin Launch",
            "projectRoot": "${workspaceFolder}/app",
            "mainClass": "kotlin_free_map_backend_system.KotlinApp",
            "preLaunchTask": "build"
        },
    ]
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "./gradlew build -x test",
            "problemMatcher": [],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "echo": true,
                "reveal": "silent",    // <== open only on problems
                "focus": false,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": false
            }
        },
        {
            "label": "run",
            "type": "shell",
            "command": "./gradlew run",
            "problemMatcher": []
        },
    ]
}