ClangFormatIJ
ClangFormatIJ copied to clipboard
Undo from disk every time using the plugin
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 ?
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?
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.
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.
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