Skip to content

Commit

Permalink
Ensure check of named scope is run as a read action (#595)
Browse files Browse the repository at this point in the history
  • Loading branch information
jshiell committed Dec 12, 2022
1 parent 655ed64 commit 5040930
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.infernus.idea.checkstyle.model;

import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.project.Project;
import com.intellij.packageDependencies.DependencyValidationManager;
import com.intellij.psi.PsiFile;
Expand All @@ -9,6 +10,7 @@
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Stream;

public final class NamedScopeHelper {
Expand Down Expand Up @@ -48,13 +50,15 @@ public static NamedScope getDefaultScope(@NotNull final Project project) {
}

public static boolean isFileInScope(final PsiFile psiFile, @NotNull final NamedScope namedScope) {
final PackageSet packageSet = namedScope.getValue();
if (packageSet == null) {
return true;
}
return ReadAction.compute(() -> {
final PackageSet packageSet = namedScope.getValue();
if (packageSet == null) {
return true;
}

return packageSet.contains(
psiFile,
DependencyValidationManager.getInstance(psiFile.getProject()));
return packageSet.contains(
psiFile,
DependencyValidationManager.getInstance(psiFile.getProject()));
});
}
}

0 comments on commit 5040930

Please sign in to comment.