Hi all, i have written a FIR compiler plugin that ...
# compiler
b
Hi all, i have written a FIR compiler plugin that generates some nested class very similar to the sandbox demo in kotlin's repository, when testing it, i can see at the bytecode level (javap over the classfiles) that the class is generated but intellij itself does not know about it and mark it in red whenever i try to access it the code still compiles, it is just intellij idea that cannot see these symbols should intellij be able to see the newly generated classes out of the box? are there any settings to enable it?
j
b
Thanks @Javier & @Johann Pardanaud, Yes, I did that - but it didnt change anything, tried to also restart idea and invalidate the caches - without any change
j
Have you changed the registry option?
b
@Javier, yes, also upgraded to the latest version of IDEA Ultimate
j
You can try another compiler plugin, if that plugin is working, maybe there is something wrong in your implementation
b
I'll try that now, are there any logs in Idea that can allow me to see the compiler output? I can print some messages while the compilation is running - just to make sure that my functions are being called by the ide - i will note though, that i am sure that the plugin itself is being used by gradle as i can see the generated .class files
j
If you throw an
error(...)
in your plugin you will see a popup on the IDE that will show the log.
b
@Javier, tried to throw an error, it did not show in IDEA while attempting to autocomplete or change the class, but when i try to actually run it - then gradle probably kicks in and i gets the error in the build window. one thing that may be the problem is that i am using an includeBuild to connect my project with the project that contains the plugin, maybe intellij dont support that - i will try to publish the plugin and see if something changes.. about installing a different plugin - tried to install kopy - but for some reason have trubles with downloading its dependencies - will work on it and post here if it worked
• Tried to publish and use my plugin directly from the repository - did not help • installed kopy - it works with autocomplete and everything so there must be a problem in the way that i am setting up the plugin, i will go over kopy source in hope to find the differences
After some more debugging, it seems that my plugin is actually being called but the getNestedClassifiersNames function return no names because this predicate: hasAnnotated({...}) returns a different result when it is run via the ide and gradle.. what i try to do is to generate nested classes for some methods that are annotated with some annotation, this is why i am using this predicate, is it not supported by the ide?
j
if it works via Gradle I see really weird it is not supported on the IDE, maybe @Roman Golyshev can confirm if that can happen
Are you using the official internal test framework?
b
internal test framework? no, i used dev.zacsweers.kctforkcore0.5.0-alpha08 for testing, and everything i run now is after the tests passed on an actual application code. what i did to discover that there was a change in the behavior between gradle and the ide is to dump all the evaluation requests and results to a local file, and compiled the code via gradle, and attempted autocomplete via the ide. Then, i compared the requests and the results between the two log files
i declared the predicate via:
Copy code
LookupPredicate.create {
    hasAnnotated(...)
}
i also noticed that there is another predicate type available for declarations, not sure what is the different between them as they seem to return the same results in my case and ofcourse i registered it using the:
Copy code
override fun FirDeclarationPredicateRegistrar.registerPredicates() {
    register(PREDICATE)
}
is there something else i need to do that i missed so that i can use the predicate? I looked at different plugin examples but did not see any other steps..
j
You need to use
DeclarationPredicate
.
LookupPredicate
is for checkers if I remember correctly
b
Sadly that did not help.. I will probably just have to annote the class itself in addition to the methods so i will be able to use different predicate, will check it soon - it is not optimal but hopefully it will work
j
Mmm, if you are looking for methods in a class maybe
getCallableNamesForClass
can help
b
It seems that if i am annotating the class itself and changing the predicate to 'annotated' everything works as expected, it means that the hasAnnotated predicate does not work when running from the IDE.. @Roman Golyshev is it intended? should i submit a bug?
@Javier, may i ask for a link for the internal testing framework that you mentioned? I am very sorry to be a bother but i tried searching the docs for any official test framework for compiler plugins but came out with nothing..
j
You can see its usage in this templae: • https://github.com/demiurg906/kotlin-compiler-plugin-template Kopy plugin is using it too.
b
Thanks @Javier for all your help!
😄 1