Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 3, 2026

WorkspaceTypeDiscovery.SearchDirectoryForTypeAsync was recursing into bin, obj, .git, and node_modules directories then filtering their files individually, causing unnecessary filesystem traversal.

Changes:

  • Implemented manual recursion in SearchDirectoryRecursiveAsync that checks directory names before descending, avoiding enumeration of excluded directories entirely
  • Moved excluded directories to a static readonly HashSet<string> to eliminate repeated allocations on each recursive call

Before:

var options = new EnumerationOptions { RecurseSubdirectories = true, IgnoreInaccessible = true };
foreach (var file in Directory.EnumerateFiles(directory, "*.cs", options))
{
    var pathSegments = fullPath.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
    if (pathSegments.Any(s => s is "bin" or "obj" or ".git" or "node_modules")) continue;
    // ...
}

After:

foreach (var subDir in Directory.EnumerateDirectories(directory, "*", new EnumerationOptions { IgnoreInaccessible = true }))
{
    if (ExcludedDirectories.Contains(Path.GetFileName(subDir))) continue;
    var result = await SearchDirectoryRecursiveAsync(subDir, typeName);
    // ...
}

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 3, 2026 14:54
Co-authored-by: HandyS11 <62420910+HandyS11@users.noreply.github.com>
…ocations

Co-authored-by: HandyS11 <62420910+HandyS11@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on code quality improvements Optimize directory traversal to skip excluded directories during enumeration Feb 3, 2026
Copilot AI requested a review from HandyS11 February 3, 2026 15:00
@HandyS11 HandyS11 marked this pull request as ready for review February 3, 2026 15:04
Copilot AI review requested due to automatic review settings February 3, 2026 15:04
@HandyS11 HandyS11 merged commit 4c650ca into refacto/ImproveCodeQuality Feb 3, 2026
6 checks passed
@HandyS11 HandyS11 deleted the copilot/sub-pr-12-yet-again branch February 3, 2026 15:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes workspace type discovery by avoiding unnecessary traversal into common non-source directories (e.g., bin/obj/.git/node_modules) and centralizes the exclusion logic. The core behavior of finding type-definition files remains the same, but with reduced filesystem overhead and cleaner directory filtering.

Changes:

  • Introduced a static ExcludedDirectories HashSet<string> with case-insensitive comparison to centralize and reuse directory-exclusion logic.
  • Replaced EnumerationOptions.RecurseSubdirectories usage with an explicit async recursive helper SearchDirectoryRecursiveAsync, which skips excluded directories before descending.
  • Adjusted file processing to use the path provided by Directory.EnumerateFiles directly (instead of Path.GetFullPath) while preserving existing Roslyn-based verification.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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