Skip to content

Commit

Permalink
follow the API guidelines and only update when formatted file is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarcaur committed Jan 9, 2025
1 parent d32aabe commit ae2a2c2
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ae2a2c2

Please sign in to comment.