Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin doesn't work with if "Only VCS changed text" is selected from code-reformat settings #228

Closed
ColtonIdle opened this issue May 7, 2021 · 2 comments

Comments

@ColtonIdle
Copy link

Here is a snippet of code I had that was all formated by ktfmt

@Composable
fun Blah(blahBlah: Boolean = true, bloopBloop: () -> Unit) {
    IconButton(onClick = { bloopBloop.invoke() }, enabled = blahBlah) {
        Icon(
            painter = painterResource(id = R.drawable.beep),
            contentDescription = "",
            tint = if (blahBlah) MaterialTheme.colors.primary else MaterialTheme.colors.secondary,
        )
    }
}

@Composable
fun Bloop(blahBlah: Boolean = true, bloopBloop: () -> Unit) {
    IconButton(onClick = { bloopBloop.invoke() }, enabled = blahBlah) {
        Icon(
            painter = painterResource(id = R.drawable.beep),
            contentDescription = "",
            tint = if (blahBlah) MaterialTheme.colors.primary else MaterialTheme.colors.primary,
        )
    }
}

I added a line to the middle of it to make it this

@Composable
fun Blah(blahBlah: Boolean = true, bloopBloop: () -> Unit) {
    IconButton(onClick = { bloopBloop.invoke() }, enabled = blahBlah) {
        Icon(
            painter = painterResource(id = R.drawable.beep),
            contentDescription = "",
            tint = if (blahBlah) MaterialTheme.colors.primary else MaterialTheme.colors.secondary,
        )
    }
}

fun greetings() =
        println("hello")

@Composable
fun Bloop(blahBlah: Boolean = true, bloopBloop: () -> Unit) {
    IconButton(onClick = { bloopBloop.invoke() }, enabled = blahBlah) {
        Icon(
            painter = painterResource(id = R.drawable.beep),
            contentDescription = "",
            tint = if (blahBlah) MaterialTheme.colors.primary else MaterialTheme.colors.primary,
        )
    }
}

and now when I reformat with the plugin. It doesn't fix the added line. In other files, it will actually reformat other parts of the file instead of the lines I added (really weird) even though the other parts of the file already had ktfmt ran on it.

I stumbled upon the issue as being related to cmd opt shit L dialog being set to "Only VCS changed text"

Screen Shot 2021-05-07 at 11 57 19 AM

If I remove that and instead do "Whole file" then everything works as expected. Here is a video of the plugin not reformatting anything (which initially caused me to think the plugin wasn't triggered at all which made me open #223 )

Closing #223 in favor of this ticket

figureditout.mp4
@cgrushko
Copy link
Contributor

cgrushko commented May 7, 2021

@cushon, is this somehow related to google/google-java-format@69ba30f#diff-58c63abbc548a9eecf5ec08ea5e513d00cbc788ad90b7704ae8fe27ef3111fa0 ?

@cushon
Copy link

cushon commented May 7, 2021

@cgrushko I think so, Collections.singletonList(file.getTextRange()) looks like it should be using the ChangedRangesInfo instead

copybara-service bot pushed a commit to google/google-java-format that referenced this issue May 12, 2021
Related: facebook/ktfmt#228

Follow-up to 69ba30f

PiperOrigin-RevId: 372590998
copybara-service bot pushed a commit to google/google-java-format that referenced this issue May 12, 2021
Related: facebook/ktfmt#228

Follow-up to 69ba30f

PiperOrigin-RevId: 372590998
copybara-service bot pushed a commit to google/google-java-format that referenced this issue May 12, 2021
Related: facebook/ktfmt#228

Follow-up to 69ba30f

PiperOrigin-RevId: 372590998
copybara-service bot pushed a commit to google/google-java-format that referenced this issue May 12, 2021
Related: facebook/ktfmt#228

Follow-up to 69ba30f

PiperOrigin-RevId: 372590998
copybara-service bot pushed a commit to google/google-java-format that referenced this issue May 12, 2021
Related: facebook/ktfmt#228

Follow-up to 69ba30f

PiperOrigin-RevId: 373443663
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants