mprobst / ClangFormatIJ

clang-format for IntelliJ based IDEs
Apache License 2.0
15 stars 9 forks source link

Undo from disk every time using the plugin #2

Open islam-taha opened 7 years ago

islam-taha commented 7 years ago

Every time i format the code using the plugin then undo, "undo from disk" alert is fired in the IDE. Is there any way to prevent such behaviour ?

mprobst commented 7 years ago

I have to admit I don't really use IntelliJ much these days. I think the plugin is calling the IJ APIs correctly, it's issuing a replacement of the buffer contents and never touches the file on disk, so I'm not sure what I could change to fix the issue.

Are you sure you don't have an additional program / external process change the file behind your back?

islam-taha commented 7 years ago

What is happening is that the plugin is calling clang-format from a command and format the needed file(s), so IntelliJ see that change as external one and on undo it fire an alert that the last change was from disk.

No, no external program/process is changing the file behind my back.

mprobst commented 7 years ago

That's why I'm confused: this plugin does shell out to clang-format, but it does not use clang-format to write the file on disk. It receives the replacements in an XML format and then applies them step by step:

https://github.com/mprobst/ClangFormatIJ/blob/master/src/io/probst/idea/clangformat/ClangFormatAction.java#L122

So from the perspective of IJ, there should not be anything writing the file on disk in this plugin.

george-harness commented 6 years ago

This works for me without undo from disk on IntelliJ IDEA 2017.3 (Community Edition) Build #IC-173.3727.127, built on November 27, 2017 JRE: 1.8.0_152-release-1024-b6 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Mac OS X 10.13.1