Looking at some Compose compiler <code here>, I se...
# compiler
d
Looking at some Compose compiler code here, I see they’re doing some checks against
FirAnonymousFunction#psi
…I’m wondering if there’s a way to do an equivalent check without using `.psi`(or some other way to get around the fact that
PsiElement
is shaded and therefore needs different artifacts for Gradle vs the IDE)
d
If I understand correctly, this particular check is needed to distinguish lambda (
{ x -> ...}
) from anonymous function (
fun (x) {...}
) This can be done using plain fir by checking
firAnonymousFunction.isLambda
d
That’s what I was guessing. I’m not sure why compose does it like that 😅
(not being able to touch
PsiElement
is very annoying though)
d
> I’m not sure why compose does it like that Probably they just copied part of the K1 implementation during K2 prototyping and it left here since then > not being able to touch
PsiElement
is very annoying though You can get used to it I always considered PSI as terrible monstrosity, so it was so nice finally be able to operate something more useful
d
True, the only other place i’ve encountered needing it is for something like
val MY_ERROR by error0<PsiElement>()
d
Yeah, and this place is needed only to some verification on IDE side For IDE it's nice to know that some diagnostic might be reported only on specific
KtElement
(e.g. to avoid obvious casts)
d
my workaround was to make my own copy of
error0
and steal the
psiType
class from some built-in error 😅:
Copy code
private fun error0(strategy: AbstractSourceElementPositioningStrategy = SourceElementPositioningStrategies.DEFAULT) =
    DiagnosticFactory0DelegateProvider(
        Severity.ERROR,
        strategy,
        FirErrors.OTHER_ERROR.psiType,
    )
d
In the compiler there are still few places, which have specific implementation for PSI (and a separate for LT), but they all are in syntax checkers, which really care about the original syntax tree They could be written once for LT (as PSI is built on top of it), but writing the special PSI-based code is more effective
Do I understand correctly that you needed because of shaded/unshaded version of
PsiElement
class? You can just use
KtElement
instead of
PsiElement
. It is located in
org.jetbrains.kotlin
package, so it isn't affected by shading
d
Do I understand correctly that you needed because of shaded/unshaded version of
PsiElement
class?
That’s right
Let me try that, that’d be great. I’ve seen a variety of hacks for this but not that solution. lol
that works perfectly, thank you! 🙂
👍 1
d
Probably I need to update plugin-sandbox and plugin-template with it
d
yeah, those all use PsiElement there
d
👋 Came across this but
KtElement
doesn’t seem to be working for me—still seeing IDE errors when trying to trigger one of my diagnostics. Is there an example usage I can look at?