https://kotlinlang.org logo
o

Oleg Yukhnevich

06/06/2023, 8:12 AM
not sure what is the best channel for such question 🙂 Yesterday on WWDC Apple showed how Swift Macros will work in Xcode (https://developer.apple.com/videos/play/wwdc2023/102/) - very similar idea of Kotlin compiler plugins The question is: does K2 compiler plugins will provide similar IDE experience, f.e.: 1. Showing which code will be generated inline 2. Quick fix support for inspections
2
and also step into generated code in debug
BTW, it’s 6-7 minute on the timeline of video
d

dmitriy.novozhilov

06/06/2023, 8:14 AM
cc @Ilya Kirillov [JB]
i

Ilya Kirillov [JB]

06/06/2023, 9:24 AM
cc @Roman Golyshev
r

Roman Golyshev

06/06/2023, 11:33 AM
Hi! Thanks for bringing this up, we definitely plan to investigate such possibilities for the K2 support in the Kotlin plugin. Unfortunately, it’s hard to promise anything particular though. Here is the tracking issue for that: https://youtrack.jetbrains.com/issue/KTIJ-21163/FIR-IDE-Investigate-how-we-can-show-declarations-generated-by-Kotlin-compiler-plugins-in-IDE
o

Oleg Yukhnevich

06/06/2023, 11:36 AM
Nice, thanks! And what about quick fixes? I know, that there are checkers in K2 compiler plugins, but will it be possible to provide some quick fixes to IDE?
s

shikasd

06/06/2023, 6:14 PM
I think there's some difference between Kotlin compiler plugins and macros here, as compiler plugins don't really generate source code. In a way, it is closer to what KSP does. The debugging feature looks really cool though, it would be very useful to see e.g. decompiled IR generated by plugins inline
o

Oleg Yukhnevich

06/06/2023, 7:14 PM
KSP is not able to transform existing declarations - Swift Macros and Kotlin compiler plugins can do it While implementation details are different, Im more concerned about how it will look from user perspective, and what Swift Macros provides is really cool
s

shikasd

06/06/2023, 7:16 PM
The implementation details matter in terms of UX here - Swift macros are closer to C style preprocessor which is easier to expand into readable source code. Kotlin compiler plugins generate IR, which is closer to bytecode - you won't be able to make readable sources out of that easily
I agree that the user experience is way better in the swift sample though, I certainly wish we could have the same
o

Oleg Yukhnevich

06/06/2023, 7:21 PM
We have FIR for something high-level, as well as IDE support So I believe, that showing generated declarations should be rather simple, as all info is available With bodies, it should be harder I beleive
s

shikasd

06/06/2023, 7:22 PM
Yeah, I was mostly thinking about bodies in particular, e.g. Compose doesn't really do anything in FIR outside of correctness checks. I'd love to see generated code right there in ide in cases like that
4 Views