1

In Kotlin KSP, I try to debug the processor

internal class ListedProcessor(
    private val fileGenerator: FileWriter,
) : SymbolProcessor {

    override fun process(resolver: Resolver): List<KSAnnotated> {

        val listedFunctions: Sequence<KSFunctionDeclaration> =
            resolver.findAnnotations(Listed::class)
        val arrayedFunctions: Sequence<KSFunctionDeclaration> =
            resolver.findAnnotations(Arrayed::class)

        return (listedFunctions + arrayedFunctions).filterNot { it.validate() }.toList()
    }
}

I try to use println but don't know where the output goes to. How can I dump out log for Kotlin KSP?

David Rawson
  • 20,912
  • 7
  • 88
  • 124
Elye
  • 53,639
  • 54
  • 212
  • 474

1 Answers1

1

As per the conversation in Kotlin Slack, please use the KSPLogger to perform logging. For example:

logger.warn(allFiles.toList().toString())

You can get a handle on the KSPLogger through the environment parameter in the create function of your SymbolProcessorProvider:

class TestProcessorProvider : SymbolProcessorProvider {
    override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor {
        return TestProcessor(environment.codeGenerator, environment.logger)
    }
}
David Rawson
  • 20,912
  • 7
  • 88
  • 124
  • Thanks David. Where does it log out to? I try to run using ./gradlew but not seeing it shown on the terminal. – Elye Feb 14 '23 at 01:14
  • Thanks. I manage to see the Warning and Error. But not the Info yet. Where can I set the `--verbose` in IntelliJ or Android Studio setting? I post a StackOverflow on this question in https://stackoverflow.com/questions/75601653/how-to-set-verbose-in-intellij-android-studio-for-ksp-debugging-purposes Thanks! – Elye Mar 01 '23 at 09:20