Skip to content

Commit

Permalink
Search the parent as well
Browse files Browse the repository at this point in the history
  • Loading branch information
guw committed Jul 30, 2023
1 parent c0ed9e9 commit 0800625
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ls.core.internal.StatusFactory;

import com.salesforce.bazel.eclipse.core.model.BazelWorkspace;

/**
* Fork of org.eclipse.jdt.ls.core.internal.managers.BasicFileDetector to skip Bazel symlinks.
*/
Expand All @@ -64,6 +66,9 @@ public class BazelFileDetector {
* Constructs a new BazelFileDetector for the given root directory, searching for fileNames. By default, the search
* depth is limited to 5. Sub-directories of a found directory will be walked through. The ".metadata" folder is
* excluded.
* <p>
* Parents are also checked in case the root folder is inside a workspace.
* </p>
*
* @param rootDir
* the root directory to search for files
Expand Down Expand Up @@ -188,6 +193,7 @@ public Collection<Path> scan(IProgressMonitor monitor) throws CoreException {
private void scanDir(Path dir, final IProgressMonitor monitor) throws IOException {
var hasInclusionPattern = exclusions.stream().anyMatch(e -> e.startsWith("!"));

// scan dir and subdir
FileVisitor<Path> visitor = new SimpleFileVisitor<>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
Expand Down Expand Up @@ -216,6 +222,24 @@ public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOExce

};
Files.walkFileTree(dir, FOLLOW_LINKS_OPTION, maxDepth, visitor);

// check parents if we still don't have anything
while ((dir != null) && directories.isEmpty()) {
var workspaceFile = BazelWorkspace.findWorkspaceFile(dir);
if (workspaceFile != null) {
directories.add(dir);
return;
}

if (dir.getNameCount() == 0) {
// we search everything including the root, give up
return;
}

// continue with parent
dir = dir.getParent(); // (needs null check in while condition)
}

}

}

0 comments on commit 0800625

Please sign in to comment.