Skip to content

Before commit reformatting option in IntelliJ does invoke plugin #228

Closed

Description

@mqzry

I have the IntelliJ plugin installed and reformatting works as expected. If I select 'Reformat code' option in commit window, then it will take my currently selected Code Style sheet and not use google-java-format. It sets indentation to 4 spaces instead of 2 for example. Reformatting after committing then immediately gives local changes.

Is this a known issue? Will this be solved?

Activity

  1. mqzry commented on Jan 17, 2018

    @mqzry
    Author

    What's the status? Should I try to fix it myself?

  2. plumpy commented on Jun 4, 2018

    @plumpy
    Collaborator

    Hey there,

    I tried to reproduce this, but was not able to. It's very old, though, so maybe it got fixed in some interim version.

    Can you still reproduce it? What version of the plugin do you have and what version of the IDE?

    Thanks and sorry for the delay...

  3. codahale commented on Jun 4, 2018

    @codahale

    This is still a problem with 1.6.0 of the plugin and the latest version of IntelliJ (2018.1.4/IU-181.5087.20).

    To reproduce:

    1. Enter some malformatted code into a file.
    2. Commit the change with the Reformat code checkbox enabled.
    3. The code will not be changed.
    4. Run Reformat Code from the Code menu.
    5. The code will be changed.
  4. mqzry commented on Jun 16, 2018

    @mqzry
    Author

    I tried it out again and it seems to be fixed.

    My setup is:
    IntelliJ @ IU-173.4548.28
    google-java-format plugin @ 1.6.0

    You are describing a different problem @codahale. Apparently 'Reformat code' in the commit dialog is doing nothing for you. My problem was that 'Reformat code' in the commit dialog was actually changing the files but without using the google-java-format plugin, hence falling back to my Code Style Sheet.

    That should probably be filed as a separate issue, but that is not my call to make. This issue can be closed for my part.

  5. codahale commented on Jun 16, 2018

    @codahale

    Well, now I can’t reproduce my problem either, so I assume this is fixed.

  6. codahale commented on Jun 16, 2018

    @codahale

    Actually, no — I can confirm w/ 2018.1.5/IU-181.5281.24 that it uses the Code Style settings and not google-java-format. This was always the problem I was experiencing, but perhaps I didn’t describe it well.

  7. codahale commented on Jun 16, 2018

    @codahale

    To reproduce:

    1. Change a project’s Java code style to the IntelliJ default.
    2. Join a series of statements in a class on a single line.
    3. Commit the code, making sure the Reformat code checkbox is checked.
    4. Observe that the changed code was refomatted using the default IntelliJ style
  8. rymach commented on Jul 30, 2018

    @rymach

    I'm also seeing this issue (version 1.6.1 of the plugin)

  9. alexbde commented on Aug 6, 2018

    @alexbde

    We're also experiencing this issue. Is there any progress on this?

    Reproducable on Windows 7 and macOS 10.13 with IntelliJ IDEA 2017.3, 2018.1 and 2018.2 using plugin 1.5.0 and 1.6.1.

  10. YanzheL commented on Mar 31, 2019

    @YanzheL

    Same issue with IntelliJ 2019.1 (IU-191.6183.87), google-java-format v1.7.0.1
    Environment:

    1. macOS 10.14.3, openjdk-8 and openjdk-11
    2. Ubuntu 18.04 LTS, openjdk-8 and openjdk-11
  11. YanzheL commented on Mar 31, 2019

    @YanzheL

    It has been two years since this issue was posted, any progress?

  12. mleonhard commented on May 1, 2019

    @mleonhard

    I really wish I could use the automatic formatter.

    IntelliJ IDEA 2019.1.1 (Community Edition)
    Build #IC-191.6707.61, built on April 16, 2019
    JRE: 1.8.0_202-release-1483-b44 x86_64
    JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
    macOS 10.14.4
    google-java-format v1.7.0.1

    @plumpy Please fix? This issue and #264 are assigned to you and have been ignored for 2 years.

  13. YanzheL commented on May 1, 2019

    @YanzheL

    My current workaround is to use XML based intellij-java-google-style file instead of this google-java-format plugin.

    It works fine, but the formatted code is slightly different from the output of this plugin.

  14. alexbde commented on Jun 5, 2019

    @alexbde

    @YanzheL We're doing the same as workaround. We used plugin google-java-format for a while but not being able to use before commit action is confusing and frustrating our developers. This is a show stopper for us.

    Last tested on
    IntelliJ IDEA 2019.1.3 (Ultimate Edition)
    Build #IU-191.7479.19, built on May 28, 2019
    JRE: 1.8.0_202-release-1483-b58 amd64
    JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
    Windows 10 10.0

  15. krasa commented on Oct 16, 2019

    @krasa

    This should be just a matter of overriding public void reformatTextWithContext(PsiFile psiFile, ChangedRangesInfo changedRangesInfo)

  16. denniseffing commented on Jul 14, 2020

    @denniseffing

    Are there any plans to support this in the future?

  17. stonelazy commented on Jul 20, 2020

    @stonelazy

    Am having this exact same issue, any work arounds possible ? We face many merge conflicts due to this.

  18. Tommy544 commented on Nov 23, 2020

    @Tommy544

    I am having the same issue, any update on this?

  19. Agraphie commented on Nov 27, 2020

    @Agraphie

    Also observing the same issue. The workaround with the codestyle.xml is nice, but the formatting can be wildly different. Especially regarding annotations (on single line, annotation indentation, ...) so the workaround is in the end not really sufficient as you still have to always apply the style either manually or via a maven plugin.

  20. vshamrai commented on Feb 22, 2024

    @vshamrai

    We faced the same issue. Can we expect that it will be fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions