Hi there, I’ve been experimenting with Kotlin AA,...
# compiler
a
Hi there, I’ve been experimenting with Kotlin AA, but I’ve found the lack of documentation to be a bit challenging. I was curious whether it was possible to add new files/source roots to an existing
StandaloneAnalysisAPISession
without having to completely rebuild it? The way I tried to do it looks like this:
Copy code
kotlin
session.project.getService(KotlinPackageProviderFactory::class.java).let { service ->
    service.createPackageProvider(
        GlobalSearchScope.fileScope(newKtFileFromPsiFileFactory)
    ).let { provider ->
        project.mergePackageProviders(listOf(provider))
    }
}
But this doesn't seem to update the session sources. It looks like analyzing a file without attaching a
KaModule
to it might not be possible, and I haven’t figured out how attach one either without constructing the said session. Any insights would be greatly appreciated. Thanks!
d
The standalone part is still in the development state https://kotlin.github.io/analysis-api/index_md.html#using-in-command-line-tools It has been designed as an immutable view on the code, so it is not supposed to react on changes (at least yet)
y
The Standalone mode indeed doesn't support file mutation now. Still, would you be able to provide your use-case? We are going to activate the Standalone platform development, so now we are interested in popular use-cases.
a
Thanks, I'm really looking forward to it. I've been working on building a Kotlin language server using the AA. The lack of documentation, however, has been a bit of a struggle.
m
Hey folks, apologies for reviving an old thread like this. I wanted to start working on a Kotlin LSP server leveraging the Analysis API, but unfortunately not having easy ways to mutate things hurts. So I guess this would be one use-case for this: LSP servers 🙂 Small side notes: with LSP servers, I need to be able to edit "range changes within Kotlin files", even if those changes aren't on disk right away in order to apply change events sent to the LSP server. I tried using
BlockSupport.replaceRange
and
Document
functions but hit several obscure errors which I believe are related to the compiler not running a real "full" IntelliJ IDE, so that doesn't sound like a viable solution. It also wouldn't solve the problem of adding entirely new files.