@Override
  public @NotNull GlobalSearchScope getUseScope(@NotNull PsiElement element) {
    VirtualFile vDirectory;
    VirtualFile virtualFile;
    PsiFile containingFile;
    GlobalSearchScope allScope = GlobalSearchScope.allScope(myManager.getProject());
    if (element instanceof PsiDirectory) {
      vDirectory = ((PsiDirectory)element).getVirtualFile();
      virtualFile = null;
      containingFile = null;
    }
    else {
      containingFile = element.getContainingFile();
      if (containingFile == null) return allScope;
      virtualFile = containingFile.getVirtualFile();
      if (virtualFile == null) return allScope;
      if (virtualFile instanceof VirtualFileWindow) {
        return GlobalSearchScope.fileScope(myProject, ((VirtualFileWindow)virtualFile).getDelegate());
      }
      if (ScratchUtil.isScratch(virtualFile)) {
        return GlobalSearchScope.fileScope(myProject, virtualFile);
      }
      vDirectory = virtualFile.getParent();
    }

    if (vDirectory == null) return allScope;
    ProjectFileIndex projectFileIndex = myProjectRootManager.getFileIndex();
    VirtualFile notNullVFile = virtualFile != null ? virtualFile : vDirectory;
    Module module = projectFileIndex.getModuleForFile(notNullVFile);
    if (module == null) {
      List<OrderEntry> entries = projectFileIndex.getOrderEntriesForFile(notNullVFile);
      if (entries.isEmpty() &&
          (WorkspaceFileIndex.getInstance(myProject).findFileSet(notNullVFile, true, false, true, true, true) != null ||
           myAdditionalIndexableFileSet.isInSet(notNullVFile))) {
        return allScope;
      }

      GlobalSearchScope result = LibraryScopeCache.getInstance(myProject).getLibraryUseScope(entries);
      return containingFile == null || virtualFile.isDirectory() || result.contains(virtualFile)
             ? result : GlobalSearchScope.fileScope(containingFile).uniteWith(result);
    }
    boolean isTest = TestSourcesFilter.isTestSources(vDirectory, myProject);
    return isTest
           ? GlobalSearchScope.moduleTestsWithDependentsScope(module)
           : GlobalSearchScope.moduleWithDependentsScope(module);
  }
@Override
  public @NotNull GlobalSearchScope getUseScope(@NotNull PsiElement element)