Optimize directory traversal to skip excluded directories during enumeration#16
Merged
HandyS11 merged 3 commits intorefacto/ImproveCodeQualityfrom Feb 3, 2026
Merged
Conversation
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
Contributor
There was a problem hiding this comment.
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
ExcludedDirectoriesHashSet<string>with case-insensitive comparison to centralize and reuse directory-exclusion logic. - Replaced
EnumerationOptions.RecurseSubdirectoriesusage with an explicit async recursive helperSearchDirectoryRecursiveAsync, which skips excluded directories before descending. - Adjusted file processing to use the path provided by
Directory.EnumerateFilesdirectly (instead ofPath.GetFullPath) while preserving existing Roslyn-based verification.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WorkspaceTypeDiscovery.SearchDirectoryForTypeAsyncwas recursing into bin, obj, .git, and node_modules directories then filtering their files individually, causing unnecessary filesystem traversal.Changes:
SearchDirectoryRecursiveAsyncthat checks directory names before descending, avoiding enumeration of excluded directories entirelyHashSet<string>to eliminate repeated allocations on each recursive callBefore:
After:
💡 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.