Skip to content

Commit 8f96dc6

Browse files
committed
follow the API guidelines and only update when formatted file is changed
1 parent 25ba82d commit 8f96dc6

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatFormattingService.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,17 @@ public void run() {
8989
}
9090

9191
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));
96103
} catch (FormatterException e) {
97104
request.onError(
98105
Notifications.PARSING_ERROR_TITLE,

0 commit comments

Comments
 (0)