intellij-community icon indicating copy to clipboard operation
intellij-community copied to clipboard

[kotlin][rfc] J2K: Add preprocessing extension point

Open ermattt opened this issue 1 year ago • 1 comments

Based on testing this extension point with two dummy preprocessors (see draft PR), this works as expected (i.e. it runs the preprocessors on a background thread, and successfully applies their changes before conversion) with one major caveat: changes due to conversion and changes due to preprocessing require two undo actions (i.e. Ctl + z).

I've tried a couple things to fix this problem, but so far none has worked:

  1. Running the custom preprocessors under a transparent global command (code). Maybe I was supposed to enable merging of global commands somehow?
  2. Using the same command group id to run the custom preprocessors and the committing new kotlin files + external code processing command (code)

You can see the example preprocessors in action (plus the suboptimal undo behavior) in the attached video zip. Screen Recording 2024-06-24 at 11.08.57 AM.zip

Once the issues with the preprocessing extension point are resolved, I'll add a postprocessing extension point by more or less copying this one.

KTIJ-29835

@abelkov @darthorimar @jocelynluizzi13

ermattt avatar Jun 24 '24 15:06 ermattt

Also, please add some tests

darthorimar avatar Jun 27 '24 09:06 darthorimar

Tests added and coroutines funkiness resolved! I probably need to clean up some k1/k2 test duplicates, but other than that I think this is ready for review again. If it looks good to you, @darthorimar, I'll expand upon these changes to handle postprocessing as well.

ermattt avatar Jul 11 '24 06:07 ermattt

@ermattt Awesome! Now tests behave more like production in JavaToKotlinAction.

The formatting changes in test data are definitely magic, but they seem to simulate the behavior in the real IntelliJ IDEA, so they are totally okay.

I'm ready to merge this PR as is, or do you want to have some modifications here?

If it looks good to you, @darthorimar, I'll expand upon these changes to handle postprocessing as well.

Definitely, thanks!

darthorimar avatar Jul 11 '24 09:07 darthorimar

Also, if it will be easier for you, you can also both of pre/post-processing reviews into a single one

darthorimar avatar Jul 11 '24 09:07 darthorimar

I'll add my postprocessing changes to this PR today, test 'em, and then re-request review from you 🥳

ermattt avatar Jul 11 '24 14:07 ermattt

@abelkov & @darthorimar, addressed comments and tested the example pre- and post-processor extensions together (see screen recording) preAndPostTogether.mov.zip

ermattt avatar Jul 12 '24 05:07 ermattt

@abelkov just addressed the last round of comments

ermattt avatar Jul 12 '24 16:07 ermattt