@Override
  public @NotNull SearchCostResult isCheapEnoughToSearch(@NotNull String name,
                                                         @NotNull GlobalSearchScope scope,
                                                         @Nullable PsiFile fileToIgnoreOccurrencesIn) {
    if (!ReadAction.compute(() -> scope.getUnloadedModulesBelongingToScope().isEmpty())) {
      return SearchCostResult.TOO_MANY_OCCURRENCES;
    }

    AtomicInteger filesCount = new AtomicInteger();
    AtomicLong filesSizeToProcess = new AtomicLong();

    Processor<VirtualFile> processor = new Processor<>() {
      private final VirtualFile virtualFileToIgnoreOccurrencesIn =
        fileToIgnoreOccurrencesIn == null ? null : fileToIgnoreOccurrencesIn.getVirtualFile();
      private final int maxFilesToProcess = Registry.intValue("ide.unused.symbol.calculation.maxFilesToSearchUsagesIn", 10);
      private final int maxFilesSizeToProcess = Registry.intValue("ide.unused.symbol.calculation.maxFilesSizeToSearchUsagesIn", 524288);

      @Override
      public boolean process(VirtualFile file) {
        ProgressManager.checkCanceled();
        if (Comparing.equal(file, virtualFileToIgnoreOccurrencesIn)) return true;
        int currentFilesCount = filesCount.incrementAndGet();

        //noinspection deprecation
        VirtualFile frontFile = file.getUserData(BackFileViewProvider.FRONT_FILE_KEY);
        file = frontFile != null ? frontFile : file;

        assert file != null;
        long fileLength = file.isDirectory() ? 0 : file.getLength();
        //Backed files can have different front file and back file size.
        // For instance, notebook can be 1mb but there jsut 2 short lines inside where we will search.
        //noinspection deprecation
        Float ratio = file.getCopyableUserData(BackFileViewProvider.FRONT_FILE_SIZE_RATIO_KEY);
        long estimatedLength = ratio != null ? Math.round(fileLength * ratio) : fileLength;

        long accumulatedFileSizeToProcess = filesSizeToProcess.addAndGet(estimatedLength);
        return currentFilesCount < maxFilesToProcess && accumulatedFileSizeToProcess < maxFilesSizeToProcess;
      }
    };
    TextIndexQuery query = TextIndexQuery.fromWord(name, true, null);
    boolean cheap = processFilesContainingAllKeys(myManager.getProject(), scope, processor, query);

    if (!cheap) {
      return SearchCostResult.TOO_MANY_OCCURRENCES;
    }

    return filesCount.get() == 0 ? SearchCostResult.ZERO_OCCURRENCES : SearchCostResult.FEW_OCCURRENCES;
  }
@Override
  public @NotNull SearchCostResult isCheapEnoughToSearch(@NotNull String name,
                                                         @NotNull GlobalSearchScope scope,
                                                         @Nullable PsiFile fileToIgnoreOccurrencesIn)