kotlin-debug-adapter icon indicating copy to clipboard operation
kotlin-debug-adapter copied to clipboard

Debug a library

Open bibble235 opened this issue 3 years ago • 1 comments

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 avatar May 07 '21 14:05 bibble235

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

bibble235 avatar May 09 '21 03:05 bibble235