1111import com .google .common .collect .Lists ;
1212import com .google .common .collect .Maps ;
1313import com .google .common .collect .Sets ;
14+ import com .intellij .codeInsight .daemon .DaemonCodeAnalyzer ;
1415import com .intellij .json .psi .JsonStringLiteral ;
1516import com .intellij .lang .injection .InjectedLanguageManager ;
1617import com .intellij .lang .jsgraphql .GraphQLFileType ;
2627import com .intellij .lang .jsgraphql .psi .GraphQLFile ;
2728import com .intellij .lang .jsgraphql .psi .GraphQLFragmentDefinition ;
2829import com .intellij .lang .jsgraphql .psi .GraphQLPsiUtil ;
30+ import com .intellij .lang .jsgraphql .schema .GraphQLSchemaChangeTracker ;
2931import com .intellij .lang .jsgraphql .schema .library .GraphQLLibraryRootsProvider ;
3032import 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 ;
3136import com .intellij .openapi .components .ServiceManager ;
3237import com .intellij .openapi .fileTypes .FileType ;
3338import com .intellij .openapi .project .IndexNotReadyException ;
3439import com .intellij .openapi .project .Project ;
3540import 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 ;
3644import com .intellij .openapi .vfs .VirtualFile ;
3745import com .intellij .psi .*;
3846import com .intellij .psi .impl .AnyPsiChangeListener ;
5462 */
5563public 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