diff --git a/idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatFormattingService.java b/idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatFormattingService.java index e28a716b..ec4ccef7 100644 --- a/idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatFormattingService.java +++ b/idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatFormattingService.java @@ -88,11 +88,21 @@ public void run() { return; } + String preFormatText = request.getDocumentText(); + try { String formattedText = applyReplacements( request.getDocumentText(), formatterService.get().getFormatReplacements(request.getDocumentText(), toRanges(request))); - request.onTextReady(formattedText); + + // The Javadoc of this API says that you should set it to null when the document is unchanged + // We should not be trying to format a document that is already formatted + if (preFormatText.equals(formattedText)) { + request.onTextReady(null); + } else { + request.onTextReady(formattedText); + } + } catch (FormatterException e) { request.onError( Notifications.PARSING_ERROR_TITLE,