Skip to content

Commit f049227

Browse files
Making sure the error will not happen again
1 parent d9094e3 commit f049227

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/main/java/pl/thedeem/intellij/dql/style/DQLPostFormatProcessor.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ private void processComments(@NotNull PsiFile hostFile, @NotNull TextRange range
5555
String text = comment.getText().replaceFirst("//", "");
5656
if (!text.startsWith(" ") && dqlSettings.SPACES_BETWEEN_COMMENT_TOKENS) {
5757
PsiComment updatedComment = DQLElementFactory.createInlineComment(hostFile.getProject(), " " + text);
58-
comment.replace(updatedComment);
58+
if (updatedComment.isValid()) {
59+
comment.replace(updatedComment);
60+
}
5961
}
6062
} else if (comment.getNode().getElementType() == DQLTypes.ML_COMMENT) {
6163
String text = comment.getText().replaceFirst("/\\*", "").replaceAll("\\*/$", "");
@@ -71,7 +73,9 @@ private void processComments(@NotNull PsiFile hostFile, @NotNull TextRange range
7173
}
7274
if (update) {
7375
PsiComment updatedComment = DQLElementFactory.createMultiLineComment(hostFile.getProject(), text);
74-
comment.replace(updatedComment);
76+
if (updatedComment.isValid()) {
77+
comment.replace(updatedComment);
78+
}
7579
}
7680
}
7781
}
@@ -112,9 +116,11 @@ private void processInjectedHosts(
112116
return;
113117
}
114118
CommandProcessor.getInstance().runUndoTransparentAction(() -> {
115-
injectionHost.updateText(formatted);
116-
documentManager.doPostponedOperationsAndUnblockDocument(document);
117-
documentManager.commitDocument(document);
119+
if (injectionHost.isValid()) {
120+
injectionHost.updateText(formatted);
121+
documentManager.doPostponedOperationsAndUnblockDocument(document);
122+
documentManager.commitDocument(document);
123+
}
118124
});
119125
});
120126
}

0 commit comments

Comments
 (0)