When generating declarations in FIR, is there anyt...
# compiler
z
When generating declarations in FIR, is there anything we need to do beyond enabling the K2 kotlin IDE plugin mode and setting the
kotlin.k2.only.bundled.compiler.plugins.enabled
registry to false? I'm finding that only warning/error diagnostics appear in the IDE but generated declarations appear to be absent (even though compilations of symbols referencing them will succeed)
d
cc @Roman Golyshev
z
Gentle nudge 🙂. Happy to file a bug report for this if it's something that's expected to work
d
Roman is on new year vacation this and next week
z
Cool, I’ll circle back after next week!
Also for reference, here's my IJ setup
Copy code
IntelliJ IDEA 2024.3.1.1 (Ultimate Edition)
Build #IU-243.22562.218, built on December 18, 2024
Licensed to Henri Sweers
Subscription is active until February 4, 2025.
Runtime version: 21.0.5+8-b631.28 aarch64 (JCEF 122.1.9)
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.lwawt.macosx.LWCToolkit
macOS 15.2
Kotlin plugin: K2 mode
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 2048M
Cores: 14
Metal Rendering is ON
Registry:
  debugger.new.tool.window.layout=true
  ide.experimental.ui=true
  idea.ignore.disabled.plugins=true
  i18n.locale=
  terminal.new.ui=true
  kotlin.k2.only.bundled.compiler.plugins.enabled=false
Non-Bundled Plugins:
  google-java-format (1.25.2.0)
  com.facebook.ktfmt_idea_plugin (1.2.0.53)
  com.intellij.ml.llm (243.22562.251.6)
  com.serranofp.fir (0.4.2)
  com.github.copilot (1.5.30-242)
  org.jetbrains.bsp (2024.3.4)
  org.jetbrains.bazel (2024.3.4)
Kotlin: 243.22562.218-IJ
Let me know if there's anything else I can send over!
r
Hi Zac! The problem that you’re describing seem to be caused by the fact that there are “shadowed” PSI classes used by your compiler plugin Notice how
org/jetbrains/kotlin/com/intellij/psi/PsiElement
is actually
org/jetbrains/kotlin
+
com/intellij/psi/PsiElement
This is most probably caused by the fact that you’re using
kotlin-compiler-embeddable
artifact as a dependency. Is that the case?
d
If it's really the case I suggest to get rid of all usages of shadowed API PsiElement, for example, could be replaced with KtElement
r
It should probably be possible to replace
kotlin-compiler-embeddable
to another dependency, like here: https://github.com/demiurg906/kotlin-compiler-plugin-template/blob/master/build.gradle.kts At least this advice has helped one of our colleagues in the past to deal with the same problem
d
The problem is that unshaded compiler is incompatible with Gradle
đź«  1
z
Hmm, but this seems to be inconsistent across IDEs with the same project. For example GitHub.com/bnorm/piecemeal works for @bnorm but when I test with the same IJ version it doesn’t for me 🤔
d
The incompatibility strikes only when you access the classes which are dependencies for the kotlin project itself, only them are shaded Note that with embeddable compiler you might see imported packages like org.jetbrains.kotlin.org.some.other.package.Declaration These are shaded
z
right but is there any reason a plugin like the one linked above would work in one IDE but not the other? Since it works in one I would assume it's not dealing with conflicting shaded APIs. My plugin where I tested this is using the same
compileOnly
+ compiler-embeddable pattern
d
Could you please share the plugin and the project with reproducer? I will try to investigate it locally
z
The one I linked above reproduces for me! Declarations don’t show up in my IDE but Brian said they do for him, and we compared and found our IDEs are identical versions and identical kotlin versions
d
Hm, in this case it's really strange Do you have the internal mode in IDE enabled? There might be some exceptions which are not shown without it
b
Just for proof:
However, I have noticed that to get new changes to show up in IntelliJ, I have to rebuild the project and reopen IntelliJ. Just to cover a foundation, @Zac Sweers, have you built the piecemeal project? (
./gradlew build
, for example)
d
This is also sounds strange Brian, will you send me a project to test? I'd like to debug the IDE tomorrow
b
Its the same repository, I'm just opening this file after building the root project.
d
Ah, the plugin and the source in the same repo In this case it makes sense
b
If I clean the project and reopen IntelliJ I start to see errors.
d
You cannot attach the plugin jar to the ide if there is no jar
b
Also, I don't need to reopen IntelliJ. Reimporting the Gradle project looks to be sufficient to refresh the compiler plugin for IntelliJ.
d
Yep, this is expected
z
Let me try again with the rebuild + reopen. I think that’s what I did before. My IDE isn’t running in internal mode though fwiw, I can try that too
hmm I'm able to use piecemeal now, though one thing that's different is it uses an included build setup exclusively for its sample whereas my other test project does not. Let me try again with this structure and see what happens
@bnorm when you develop in piecemeal, do you open the sample project or the root project in your IDE?
b
I open the root in IntelliJ but have both projects loaded as Gradle projects.
z
interesting, let me try that. I'm able to get it working if I open just the sample project
I've been able to get farther, though I'm often finding that autocomplete will see a generated declaration but IDE indexing will still show it red, and return types won't be resolved. I'm wondering if that's maybe related to this: https://kotlinlang.slack.com/archives/C7L3JB43G/p1737407547947799
I've just found that
kotlin.k2.only.bundled.compiler.plugins.enabled
doesn't exist in Android Studio. Is this a Jetbrains call or Google? (wondering which issue tracker I should file this on)
actually I see it's in the very very latest Android Studio Meerkat canary that came out this week, nice timing
d
AS is lagging from intellij by several months
👍 1