Thread
#ktfmt
    Colton Idle

    Colton Idle

    1 year ago
    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? 😄
    Javier

    Javier

    1 year ago
    I use it every day
    What IDE and IDE version are you using?
    Colton Idle

    Colton Idle

    1 year ago
    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.
    Javier

    Javier

    1 year ago
    It is easy, just add the next snipper:
    fun greetings() =
        println("hello")
    then press control L
    if it is reformat to
    fun greetings() = println("hello")
    , it works
    Colton Idle

    Colton Idle

    1 year ago
    Alright. Let me try. One sec to get on my laptop! Thank you so much @Javier
    It did work! Hm. Very weird that I thought it wasn't working!
    Actually. @Javier this seems like maybe a bug in ktfmt or the plugin?
    Javier

    Javier

    1 year ago
    Yeah, it looks like a bug, file an issue for it please 🙂
    Colton Idle

    Colton Idle

    1 year ago
    I'll reopen my previous issue I had just closed and I will attach the video.
    Carmi Grushko

    Carmi Grushko

    1 year ago
    @Colton Idle is there a compilation error in the file?
    Colton Idle

    Colton Idle

    1 year ago
    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.
    Carmi Grushko

    Carmi Grushko

    1 year ago
    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)
    Colton Idle

    Colton Idle

    1 year ago
    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.
    Carmi Grushko

    Carmi Grushko

    1 year ago
    What's the expected behavior? (sorry, it's hard for me to jump right into it)
    Colton Idle

    Colton Idle

    1 year ago
    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
    fun greetings() =
        println("hello")
    and I try to reformat in
    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.
    Carmi Grushko

    Carmi Grushko

    1 year ago
    Weird indeed. Please try the online formatter to isolate the problem to either IJ+Plugin or ktfmt itself. Thanks!
    Colton Idle

    Colton Idle

    1 year ago
    Confirmed that the online formatter formats everything as expected, so I'm assuming that it's ij + plugin
    Carmi Grushko

    Carmi Grushko

    1 year ago
    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)
    Colton Idle

    Colton Idle

    1 year ago
    @Carmi Grushko I think I figured it out. You cannot have "only vcs changed files" enabled!
    Carmi Grushko

    Carmi Grushko

    1 year ago
    Ah 😃 so you need to add the file to staging for it to work? Not related to the issue I mentioned above?
    Colton Idle

    Colton Idle

    1 year ago
    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".
    Carmi Grushko

    Carmi Grushko

    1 year ago
    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!!!
    Colton Idle

    Colton Idle

    1 year ago
    Do you care if I just attach this to the current issue?
    Carmi Grushko

    Carmi Grushko

    1 year ago
    If you have the time, it’s better for the project to have a separate issue 😃
    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!