Skip to content

Refactor FindFileRecursively to skip excluded directories (bin/obj/.git/node_modules)#57

Closed
Copilot wants to merge 2 commits into012-mcp-integration-primitivesfrom
copilot/sub-pr-52-one-more-time
Closed

Refactor FindFileRecursively to skip excluded directories (bin/obj/.git/node_modules)#57
Copilot wants to merge 2 commits into012-mcp-integration-primitivesfrom
copilot/sub-pr-52-one-more-time

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 11, 2026

FindFileRecursively used Directory.GetFiles(..., SearchOption.AllDirectories) — eager, unbounded, and unaware of the project's standard skip list — making it expensive on large workspaces.

Changes

  • WorkspaceRootService.FindFileRecursively: replaced the single GetFiles call with an iterative stack-based DFS that applies DirectoryFilters.ShouldSkipDirectory before descending into any subdirectory
  • Switched to Directory.EnumerateFiles / EnumerateDirectories (lazy) over the eager GetFiles / GetDirectories
  • Separated exception handling for file and directory enumeration so an access failure on one doesn't suppress the other
// Before
var files = Directory.GetFiles(rootPath, fileName, SearchOption.AllDirectories);
return files.Length > 0 ? files[0] : null;

// After — skips bin/obj/.git/node_modules, lazy, per-directory error isolation
var stack = new Stack<string>();
stack.Push(rootPath);
while (stack.Count > 0)
{
    var currentDir = stack.Pop();
    foreach (var file in Directory.EnumerateFiles(currentDir, fileName))
        return file;
    foreach (var subDir in Directory.EnumerateDirectories(currentDir))
        if (!DirectoryFilters.ShouldSkipDirectory(subDir))
            stack.Push(subDir);
}
return null;

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…vely

Co-authored-by: HandyS11 <62420910+HandyS11@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on mcp integration primitives regarding folder exclusions Refactor FindFileRecursively to skip excluded directories (bin/obj/.git/node_modules) Mar 11, 2026
@HandyS11 HandyS11 closed this Mar 11, 2026
@HandyS11 HandyS11 deleted the copilot/sub-pr-52-one-more-time branch March 11, 2026 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants