fwcd / kotlin-debug-adapter

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

Debug a library #57

Open bibble235 opened 3 years ago

bibble235 commented 3 years ago

1/ When you build a gradle project with a library I cannot find a way to debug the library. In the default project this is utilities. My pointer to an approach below

2/ It is also a tad annoying to have to quite rightly specify the /app in the configuration. It is the well named just easy to forget when context switching.

    "version": "0.2.0",
    "configurations": [
        {
            "type": "kotlin",
            "request": "launch",
            "name": "Kotlin Launch",
            "projectRoot": "${workspaceFolder}/app",
            "dependantProjectRoots": "utilities;list",
            "mainClass": "test.app.AppKt",
        }
    ]

Looking at the code it appears that the sourcesRootsOf does not add the dependant project so it cannot find the source. I may well be wrong :) about my approach

    private fun sourcesRootsOf(projectRoot: Path, dependantProjectRoots: String): Set<Path> { 

        var paths = projectRoot.resolve("src")
        .let(Files::list) // main, test
        .filter { Files.isDirectory(it) }
        .flatMap(Files::list) // kotlin, java
        .filter { Files.isDirectory(it) }
        .collect(Collectors.toSet())

        val projectRootNames = dependantProjectRoots.split(';');

        for(projectRootName in projectRootNames) {

            val path = Paths.get(projectRoot.getParent().toString(),projectRootName)
            val dependantProjectPaths = path.resolve("src")
            .let(Files::list) // main, test
            .filter { Files.isDirectory(it) }
            .flatMap(Files::list) // kotlin, java
            .filter { Files.isDirectory(it) }
            .collect(Collectors.toSet())

            paths = paths.plus(dependantProjectPaths)
        }
        return paths
    }

I have modified mine to take a semicolon delimited list to pass the project names and it appears to work. Probably could write better code but just wanted to not use the slowness the is Android Studio.

Any chance you could clarify my findings.

bibble235 commented 3 years ago

Put my temporary fix in my own fork https://github.com/bibble235/kotlin-debug-adapter/commit/aca69735d6835a9506362f87514ae4b1cecbf2a9