Skip to content

Commit d927652

Browse files
committed
fix: duplicate errors when PsiFile has several files.
Signed-off-by: azerr <[email protected]>
1 parent c5b7d62 commit d927652

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/main/java/com/redhat/devtools/lsp4ij/features/AbstractLSPExternalAnnotator.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected AbstractLSPExternalAnnotator(Key<Boolean> appliedKey) {
3434

3535
@Override
3636
public final void apply(@NotNull PsiFile file, @Nullable AnnotationResultType annotationResult, @NotNull AnnotationHolder holder) {
37-
if (isAlreadyApplied(holder.getCurrentAnnotationSession())) {
37+
if (isAlreadyApplied(file, holder.getCurrentAnnotationSession())) {
3838
return;
3939
}
4040
try {
@@ -48,12 +48,20 @@ public final void apply(@NotNull PsiFile file, @Nullable AnnotationResultType an
4848

4949
/**
5050
* Return true if the LSP external annotator has been already applied from the given session and false otherwise.
51-
* @param session
5251
*
52+
* @param file
53+
* @param session
5354
* @return true if the LSP external annotator has been already applied from the given session and false otherwise.
5455
*/
55-
private boolean isAlreadyApplied(AnnotationSession session) {
56-
return session.getUserData(appliedKey) != null;
56+
private boolean isAlreadyApplied(@NotNull PsiFile file, @NotNull AnnotationSession session) {
57+
if(session.getUserData(appliedKey) != null) {
58+
return true;
59+
}
60+
var files = file.getViewProvider().getAllFiles();
61+
if (files.size() > 1 && files.indexOf(file) > 0) {
62+
return true;
63+
}
64+
return false;
5765
}
5866

5967
public abstract void doApply(@NotNull PsiFile file, @Nullable AnnotationResultType annotationResult, @NotNull AnnotationHolder holder);

0 commit comments

Comments
 (0)