Does anyone use the ktfmt intellij plugin? It does...
# ktfmt
c
Does anyone use the ktfmt intellij plugin? It doesn't seem to work and just curious what people are doing in the meantime while that gets resolved. Does no one else hit cmd ctrl L all the time like me? 😄
j
I use it every day
What IDE and IDE version are you using?
c
Android Studio canary 14. I filed this bug: https://github.com/facebookincubator/ktfmt/issues/223 I also don't know if it's maybe working but I don't think it is. There's no indication that the formatting was performed by ktfmt vs intellij.
j
It is easy, just add the next snipper:
Copy code
fun greetings() =
    println("hello")
then press control L
if it is reformat to
fun greetings() = println("hello")
, it works
c
Alright. Let me try. One sec to get on my laptop! Thank you so much @Javier
🙂 1
It did work! Hm. Very weird that I thought it wasn't working!
👍 1
Actually. @Javier this seems like maybe a bug in ktfmt or the plugin?
j
Yeah, it looks like a bug, file an issue for it please 🙂
c
I'll reopen my previous issue I had just closed and I will attach the video.
👍 1
c
@Colton Idle is there a compilation error in the file?
c
Nope. Just a regular file that I dropped in that function. Also weirdly enough. My entire project has had ktfmt run against it. And so it reformats 10 lines is very weird. and then it reformats 3.
c
It's hard for me to see what's going on in the screencast. Can you try formatting the code in https://facebookincubator.github.io/ktfmt/ ? it'll report any error that ktfmt runs into (if there's an error, the plugin won't format anything)
c
Will do. Look at this last video though.
By adding the greetings fun, and adding a line on top and below, it reformats my entire file below. lol.
c
What's the expected behavior? (sorry, it's hard for me to jump right into it)
c
Oooh. The online formatter (the link you shared) formats as expected. Basically what's expected is (imagine me narrating a video) 1. I'm showing a file that has already had ktfmt applied to the whole project. I press reformat shortcut and it reformats nothing. 2. I add
Copy code
fun greetings() =
    println("hello")
and I try to reformat in
Copy code
fun greetings() = println("hello")
but it doesn't 3. I add a line break above it, and reformat. and it doesn't reformat my greetings fun, it reformats the rest of my file.
c
Weird indeed. Please try the online formatter to isolate the problem to either IJ+Plugin or ktfmt itself. Thanks!
c
Confirmed that the online formatter formats everything as expected, so I'm assuming that it's ij + plugin
c
Ha! IJ says something about "changes since last snapshot", right? Sounds related to this fix in google-java-format's IJ plugin? https://github.com/google/google-java-format/commit/69ba30fd9242eb52446edf18655d190e653348b6#diff-58c63abbc548a9eecf5ec[…]8ad90b7704ae8fe27ef3111fa0 (ktfmt's plugin is a fork of the GJF one)
c
@Carmi Grushko I think I figured it out. You cannot have "only vcs changed files" enabled!
c
Ah :) so you need to add the file to staging for it to work? Not related to the issue I mentioned above?
c
Not related to adding the file to staging. If it's not in staging, or in staging, it produces the same effect. The only way to "fix" it is to always reformat whole file, and not the "only vcs changed text".
c
Can you file a new issue for this with as much detail as you can? I think the plug-in should have a better behavior.
Thanks!!!
c
Do you care if I just attach this to the current issue?
c
If you have the time, it’s better for the project to have a separate issue :)
👍 1
c
I just want to say that I'm so happy that we figured this out. This was driving me INSANE. As someone that presses cmd opt L like 100 times a minute... having all my code reformat in the specified way to pass ktfmt is amazing. Thank you all again!
❤️ 1
530 Views