com.intellij.psi.search.GlobalSearchScopesCore Java Examples

The following examples show how to use com.intellij.psi.search.GlobalSearchScopesCore. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GraphQLPsiSearchHelper.java    From js-graphql-intellij-plugin with MIT License 6 votes vote down vote up
/**
 * Uses custom editable scopes to limit the schema and reference resolution of a GraphQL psi element
 */
public GlobalSearchScope getSchemaScope(PsiElement element) {

    return fileNameToSchemaScope.computeIfAbsent(getFileName(element.getContainingFile()), fileName -> {

        final VirtualFile virtualFile = getVirtualFile(element.getContainingFile());
        final NamedScope schemaScope = graphQLConfigManager.getSchemaScope(virtualFile);
        if (schemaScope != null) {
            final GlobalSearchScope filterSearchScope = GlobalSearchScopesCore.filterScope(myProject, schemaScope);
            return searchScope.intersectWith(filterSearchScope.union(allBuiltInSchemaScopes));
        }

        // default is entire project limited by relevant file types
        return searchScope;

    });

}
 
Example #2
Source File: ScopeChooserCombo.java    From IntelliJDeodorant with MIT License 5 votes vote down vote up
private void browseCustomScope(Project project) {
    EditScopesDialog dialog = EditScopesDialog.showDialog(project, null);
    if (dialog.isOK()) {
        if (dialog.getSelectedScope() != null) {
            customScope = new AnalysisScope(GlobalSearchScopesCore.filterScope(project, dialog.getSelectedScope()), project);
            configureComboBox(customScope.getDisplayName());
        }
    }
}
 
Example #3
Source File: JSGraphQLEndpointPsiUtil.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
/**
 * Creates a search scope for finding import files based on the endpoint entry file, falling back to
 * project scope in case no entry file has been configured.
 * @param project      project to search
 * @param entryFile    the entry file, or null to look it up
    */
@NotNull
public static GlobalSearchScope getImportScopeFromEntryFile(Project project, @Nullable VirtualFile entryFile, PsiElement scopedElement) {
	if(entryFile == null) {
		entryFile = JSGraphQLConfigurationProvider.getService(project).getEndpointEntryFile(scopedElement.getContainingFile());
	}
	final GlobalSearchScope scope;
	if(entryFile != null) {
		scope = GlobalSearchScopesCore.directoriesScope(project, true, entryFile.getParent());
	} else {
		scope = GlobalSearchScope.projectScope(project);
	}
	return scope;
}
 
Example #4
Source File: CoverageSuitesBundle.java    From consulo with Apache License 2.0 5 votes vote down vote up
private GlobalSearchScope getSearchScopeInner(Project project) {
  final RunConfigurationBase configuration = getRunConfiguration();
  if (configuration instanceof ModuleBasedConfiguration) {
    final Module module = ((ModuleBasedConfiguration)configuration).getConfigurationModule().getModule();
    if (module != null) {
      return GlobalSearchScope.moduleRuntimeScope(module, isTrackTestFolders());
    }
  }
  return isTrackTestFolders() ? GlobalSearchScope.projectScope(project) : GlobalSearchScopesCore.projectProductionScope(project);
}
 
Example #5
Source File: DirectoryPathMatcher.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
GlobalSearchScope narrowDown(@Nonnull GlobalSearchScope fileSearchScope) {
  if (myFiles == null) return fileSearchScope;

  VirtualFile[] array = ContainerUtil.map2Array(myFiles, VirtualFile.class, p -> p.first);
  return GlobalSearchScopesCore.directoriesScope(myModel.getProject(), true, array).intersectWith(fileSearchScope);

}
 
Example #6
Source File: AnalysisScope.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public SearchScope toSearchScope() {
  switch (myType) {
    case CUSTOM:
      return myScope;
    case DIRECTORY:
      return GlobalSearchScopesCore.directoryScope((PsiDirectory)myElement, true);
    case FILE:
      return new LocalSearchScope(myElement);
    case INVALID:
      return LocalSearchScope.EMPTY;
    case MODULE:
      GlobalSearchScope moduleScope = GlobalSearchScope.moduleScope(myModule);
      return myIncludeTestSource ? moduleScope : GlobalSearchScope.notScope(GlobalSearchScopesCore.projectTestScope(myModule.getProject())).intersectWith(moduleScope);
    case MODULES:
      SearchScope scope = GlobalSearchScope.EMPTY_SCOPE;
      for (Module module : myModules) {
        scope = scope.union(GlobalSearchScope.moduleScope(module));
      }
      return scope;
    case PROJECT:
      return myIncludeTestSource ? GlobalSearchScope.projectScope(myProject) : GlobalSearchScopesCore.projectProductionScope(myProject);
    case VIRTUAL_FILES:
      return new GlobalSearchScope() {
        @Override
        public boolean contains(@Nonnull VirtualFile file) {
          return myFilesSet.contains(file);
        }

        @Override
        public int compare(@Nonnull VirtualFile file1, @Nonnull VirtualFile file2) {
          return 0;
        }

        @Override
        public boolean isSearchInModuleContent(@Nonnull Module aModule) {
          return false;
        }

        @Override
        public boolean isSearchInLibraries() {
          return false;
        }
      };
    default:
      LOG.error("invalid type " + myType);
      return GlobalSearchScope.EMPTY_SCOPE;
  }
}