@Override
    public @NotNull GlobalSearchScope uniteWith(@NotNull GlobalSearchScope scope) {
      if (equals(scope)) {
        return this;
      }
      if (scope instanceof DirectoryScope other) {
        if (myDirectories.contains(other.myDirectory) || VfsUtilCore.isUnder(other.myDirectory, myDirectoriesWithSubdirectories)) {
          return this;
        }
        Set<? extends VirtualFile> directories = myDirectories;
        Set<? extends VirtualFile> directoriesWithSubdirectories = myDirectoriesWithSubdirectories;
        if (other.myWithSubdirectories) {
          Set<VirtualFile> copy = new HashSet<>(directoriesWithSubdirectories);
          copy.add(other.myDirectory);
          directoriesWithSubdirectories = copy;
        }
        else {
          Set<VirtualFile> copy = new HashSet<>(directories);
          copy.add(other.myDirectory);
          directories = copy;
        }
        return new DirectoriesScope(Objects.requireNonNull(getProject()), directories, directoriesWithSubdirectories);
      }
      if (scope instanceof DirectoriesScope other) {
        Set<? extends VirtualFile> directories = myDirectories;
        Set<? extends VirtualFile> directoriesWithSubdirectories = myDirectoriesWithSubdirectories;
        if (!other.myDirectories.isEmpty()) {
          Set<VirtualFile> copy = new HashSet<>(directories);
          copy.addAll(other.myDirectories);
          directories = copy;
        }
        if (!other.myDirectoriesWithSubdirectories.isEmpty()) {
          Set<VirtualFile> copy = new HashSet<>(directoriesWithSubdirectories);
          copy.addAll(other.myDirectoriesWithSubdirectories);
          directoriesWithSubdirectories = copy;
        }
        return new DirectoriesScope(Objects.requireNonNull(getProject()), directories, directoriesWithSubdirectories);
      }
      return super.uniteWith(scope);
    }
@Override
    public @NotNull GlobalSearchScope uniteWith(@NotNull GlobalSearchScope scope)