Skip to content

Commit 5dbffeb

Browse files
committed
Add a registry key to disable searching in META-INF libraries
1 parent 3d743a5 commit 5dbffeb

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

resources/META-INF/plugin.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@
202202

203203
<errorHandler implementation="com.intellij.lang.jsgraphql.GraphQLGithubErrorReporter"/>
204204

205+
<!-- Keys -->
206+
<registryKey key="graphql.search.scope.libraries" defaultValue="true"
207+
description="Whether to search for schema definitions in libraries"/>
208+
205209
<!-- Inspections -->
206210
<localInspection language="GraphQL" key="graphql.inspection.display.name.unresolved.reference"
207211
enabledByDefault="true"

src/main/com/intellij/lang/jsgraphql/ide/search/GraphQLPsiSearchHelper.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.google.common.collect.Lists;
1212
import com.google.common.collect.Maps;
1313
import com.google.common.collect.Sets;
14+
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
1415
import com.intellij.json.psi.JsonStringLiteral;
1516
import com.intellij.lang.injection.InjectedLanguageManager;
1617
import com.intellij.lang.jsgraphql.GraphQLFileType;
@@ -26,13 +27,20 @@
2627
import com.intellij.lang.jsgraphql.psi.GraphQLFile;
2728
import com.intellij.lang.jsgraphql.psi.GraphQLFragmentDefinition;
2829
import com.intellij.lang.jsgraphql.psi.GraphQLPsiUtil;
30+
import com.intellij.lang.jsgraphql.schema.GraphQLSchemaChangeTracker;
2931
import com.intellij.lang.jsgraphql.schema.library.GraphQLLibraryRootsProvider;
3032
import com.intellij.openapi.Disposable;
33+
import com.intellij.openapi.application.Application;
34+
import com.intellij.openapi.application.ApplicationManager;
35+
import com.intellij.openapi.application.ModalityState;
3136
import com.intellij.openapi.components.ServiceManager;
3237
import com.intellij.openapi.fileTypes.FileType;
3338
import com.intellij.openapi.project.IndexNotReadyException;
3439
import com.intellij.openapi.project.Project;
3540
import com.intellij.openapi.util.Ref;
41+
import com.intellij.openapi.util.registry.Registry;
42+
import com.intellij.openapi.util.registry.RegistryValue;
43+
import com.intellij.openapi.util.registry.RegistryValueListener;
3644
import com.intellij.openapi.vfs.VirtualFile;
3745
import com.intellij.psi.*;
3846
import com.intellij.psi.impl.AnyPsiChangeListener;
@@ -54,6 +62,8 @@
5462
*/
5563
public class GraphQLPsiSearchHelper implements Disposable {
5664

65+
private static final String GRAPHQL_SEARCH_SCOPE_LIBRARIES_KEY = "graphql.search.scope.libraries";
66+
5767
private final Project myProject;
5868
private final GlobalSearchScope myDefaultProjectFileScope;
5969
private final GraphQLConfigManager myConfigManager;
@@ -63,6 +73,8 @@ public class GraphQLPsiSearchHelper implements Disposable {
6373
private final PsiManager myPsiManager;
6474
private final @Nullable GraphQLInjectionSearchHelper myInjectionSearchHelper;
6575
private final InjectedLanguageManager myInjectedLanguageManager;
76+
// enabled by default, can be disabled using the registry key in case of any problems on the user's side
77+
private volatile boolean myShouldSearchInLibraries;
6678

6779
public static GraphQLPsiSearchHelper getInstance(@NotNull Project project) {
6880
return ServiceManager.getService(project, GraphQLPsiSearchHelper.class);
@@ -80,6 +92,20 @@ public GraphQLPsiSearchHelper(@NotNull final Project project) {
8092
GraphQLLanguage.INSTANCE, "");
8193
myDefaultProjectFileScope = GlobalSearchScope.fileScope(myDefaultProjectFile);
8294

95+
myShouldSearchInLibraries = Registry.is(GRAPHQL_SEARCH_SCOPE_LIBRARIES_KEY);
96+
Registry.get(GRAPHQL_SEARCH_SCOPE_LIBRARIES_KEY).addListener(new RegistryValueListener() {
97+
@Override
98+
public void afterValueChanged(@NotNull RegistryValue value) {
99+
Application app = ApplicationManager.getApplication();
100+
app.invokeLater(() -> app.runWriteAction(() -> {
101+
myShouldSearchInLibraries = value.asBoolean();
102+
PsiManager.getInstance(myProject).dropPsiCaches();
103+
DaemonCodeAnalyzer.getInstance(myProject).restart();
104+
GraphQLSchemaChangeTracker.getInstance(myProject).schemaChanged();
105+
}), ModalityState.NON_MODAL, myProject.getDisposed());
106+
}
107+
}, this);
108+
83109
project.getMessageBus().connect(this).subscribe(PsiManagerImpl.ANY_PSI_CHANGE_TOPIC, new AnyPsiChangeListener() {
84110
@Override
85111
public void beforePsiChanged(boolean isPhysical) {
@@ -103,9 +129,12 @@ private GlobalSearchScope createScope(@Nullable GlobalSearchScope configRestrict
103129
// these scopes are used unconditionally, both for global and config filtered scopes
104130
scope = scope
105131
.union(myDefaultProjectFileScope)
106-
.union(new GraphQLMetaInfSchemaSearchScope(myProject))
107132
.union(createExternalDefinitionsLibraryScope());
108133

134+
if (myShouldSearchInLibraries) {
135+
scope = scope.union(new GraphQLMetaInfSchemaSearchScope(myProject));
136+
}
137+
109138
// filter all the resulting scopes by file types, we don't want some child scope to override this
110139
FileType[] fileTypes = GraphQLFindUsagesUtil.getService().getIncludedFileTypes().toArray(FileType.EMPTY_ARRAY);
111140
return GlobalSearchScope.getScopeRestrictedByFileTypes(scope, fileTypes);

0 commit comments

Comments
 (0)