File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed
idea-plugin/src/main/java/com/palantir/javaformat/intellij Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -89,10 +89,17 @@ public void run() {
89
89
}
90
90
91
91
try {
92
- String formattedText = applyReplacements (
93
- request .getDocumentText (),
94
- formatterService .get ().getFormatReplacements (request .getDocumentText (), toRanges (request )));
95
- request .onTextReady (formattedText );
92
+ List <Replacement > replacements =
93
+ formatterService .get ().getFormatReplacements (request .getDocumentText (), toRanges (request ));
94
+
95
+ // The Javadoc of onTextReady API says that you should set it to null when the
96
+ // document is unchanged. But an even better version is to simply not attempt
97
+ // to format a document that is already formatted
98
+ if (replacements .isEmpty ()) {
99
+ return ;
100
+ }
101
+
102
+ request .onTextReady (applyReplacements (request .getDocumentText (), replacements ));
96
103
} catch (FormatterException e ) {
97
104
request .onError (
98
105
Notifications .PARSING_ERROR_TITLE ,
You can’t perform that action at this time.
0 commit comments