Skip to content

Commit

Permalink
fix: Missing directories when view_project_root is on
Browse files Browse the repository at this point in the history
fixes #6492
  • Loading branch information
Tomasz Pasternak committed Jun 18, 2024
1 parent 15cfacb commit a985666
Showing 1 changed file with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,17 @@
import com.google.idea.common.experiments.BoolExperiment;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.io.FileUtil;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Set;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -148,10 +153,7 @@ public ImportRoots build() {
}

if (viewProjectRoot) {
Arrays.stream(Objects.requireNonNull(workspaceRoot.directory().listFiles()))
.filter(f -> f.isDirectory() && rootDirectoriesBuilder.build().stream().noneMatch(r -> FileUtil.filesEqual(workspaceRoot.fileForPath(r), f)))
.map(workspaceRoot::workspacePathFor)
.forEach(excludeDirectoriesBuilder::add);
selectExcludes(rootDirectoriesBuilder.build()).forEach(excludeDirectoriesBuilder::add);
}

ImmutableSet<WorkspacePath> minimalExcludes =
Expand All @@ -176,6 +178,20 @@ public ImportRoots build() {
return new ImportRoots(directories, targets);
}

private @NotNull List<WorkspacePath> selectExcludes(ImmutableCollection<WorkspacePath> rootDirectories) {
Queue<File> files = new LinkedList<>(Arrays.asList(workspaceRoot.directory().listFiles()));
var result = new ArrayList<File>();
while (!files.isEmpty()) {
File file = files.poll();
if (rootDirectories.stream().anyMatch(d -> FileUtil.isAncestor(file, workspaceRoot.fileForPath(d), /*strict=*/ true))) {
files.addAll(Arrays.asList(file.listFiles()));
} else if (rootDirectories.stream().noneMatch(d -> FileUtil.filesEqual(file, workspaceRoot.fileForPath(d)))) {
result.add(file);
}
}
return result.stream().map(workspaceRoot::workspacePathFor).toList();
}

private void excludeBuildSystemArtifacts() {
for (String dir :
BuildSystemProvider.getBuildSystemProvider(buildSystemName)
Expand Down

0 comments on commit a985666

Please sign in to comment.