Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: duplicate errors when PsiFile has several files. #924

Merged
merged 1 commit into from
Mar 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected AbstractLSPExternalAnnotator(Key<Boolean> appliedKey) {

@Override
public final void apply(@NotNull PsiFile file, @Nullable AnnotationResultType annotationResult, @NotNull AnnotationHolder holder) {
if (isAlreadyApplied(holder.getCurrentAnnotationSession())) {
if (isAlreadyApplied(file, holder.getCurrentAnnotationSession())) {
return;
}
try {
Expand All @@ -48,12 +48,20 @@ public final void apply(@NotNull PsiFile file, @Nullable AnnotationResultType an

/**
* Return true if the LSP external annotator has been already applied from the given session and false otherwise.
* @param session
*
* @param file
* @param session
* @return true if the LSP external annotator has been already applied from the given session and false otherwise.
*/
private boolean isAlreadyApplied(AnnotationSession session) {
return session.getUserData(appliedKey) != null;
private boolean isAlreadyApplied(@NotNull PsiFile file, @NotNull AnnotationSession session) {
if(session.getUserData(appliedKey) != null) {
return true;
}
var files = file.getViewProvider().getAllFiles();
if (files.size() > 1 && files.indexOf(file) > 0) {
return true;
}
return false;
}

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