From 233cd0e02337ccb244ddca29ac5f89d96fc26973 Mon Sep 17 00:00:00 2001 From: Jack Dai Date: Mon, 18 Nov 2024 14:30:15 -0800 Subject: [PATCH] Fix over-including when view_project_root is set. https: //github.com/bazelbuild/intellij/pull/6767 introduces a regression. While it fixes the bug with overlapping directories, it causes too many directories to now become included. This happens because the change avoids excluding files under any root directory, however the project root itself is a root directory when `view_project_root` is set. This results in nothing getting excluded, which defeats the purpose of view_project_root (it behaves the same as just adding `.` into directories). The fix is to only avoid excluding files under any user-declared root directories. Change-Id: I7f082b46dd036afc0ba8cfe596e574b021cf27fb --- .../google/idea/blaze/base/sync/projectview/ImportRoots.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base/src/com/google/idea/blaze/base/sync/projectview/ImportRoots.java b/base/src/com/google/idea/blaze/base/sync/projectview/ImportRoots.java index 4dbd8320c3c..a260430c529 100644 --- a/base/src/com/google/idea/blaze/base/sync/projectview/ImportRoots.java +++ b/base/src/com/google/idea/blaze/base/sync/projectview/ImportRoots.java @@ -192,12 +192,13 @@ public ImportRoots build() { } private @NotNull List selectExcludes(ImmutableCollection rootDirectories) { + var userDeclaredRootDirectories = rootDirectories.stream().filter(rootDirectory -> !rootDirectory.isWorkspaceRoot()).collect(toImmutableSet()); Queue files = new LinkedList<>(Collections.singletonList(workspaceRoot.directory())); var result = new ArrayList(); while (!files.isEmpty()) { File file = files.poll(); if (rootDirectories.stream().anyMatch(d -> FileUtil.isAncestor(file, workspaceRoot.fileForPath(d), /*strict=*/ true)) && - rootDirectories.stream().noneMatch(d -> FileUtil.filesEqual(file, workspaceRoot.fileForPath(d))) + userDeclaredRootDirectories.stream().noneMatch(d -> FileUtil.filesEqual(file, workspaceRoot.fileForPath(d))) ) { var children = file.listFiles(File::isDirectory); if (children != null) {