Skip to content

Conversation

@village-way
Copy link
Contributor

@village-way village-way commented Jun 19, 2025

Related GitHub Issue

Closes: #4833

Description

The listFilteredDirectories() function in src/services/glob/list-files.ts was ignoring the recursive parameter and only scanning immediate child directories. This caused:

  • @src search: Shows src/, src/components/, src/utils/, etc.
  • ❌ Click "Add Folder": Shows only src/, public/, missing all subdirectories

Test Procedure

Testing

Manual Testing Steps

  1. Open chat input and type @

  2. Click "Add Folder"

  3. Verify all directory levels are now visible:

    ✅ src/
    ✅ src/components/
    ✅ src/components/ui/
    ✅ src/utils/
    ✅ public/
    ✅ public/assets/
    
  4. Verify direct search still works: type @src and confirm same results

Edge Cases Tested

  • ✅ Respects .gitignore patterns
  • ✅ Honors built-in ignore directories (node_modules, etc.)
  • ✅ Handles permission errors gracefully
  • ✅ Maintains directory sorting (directories before files)
  • ✅ Works with spaces in directory names

Type of Change

  • 🐛 Bug Fix: Non-breaking change that fixes an issue.
  • New Feature: Non-breaking change that adds functionality.
  • 💥 Breaking Change: Fix or feature that would cause existing functionality to not work as expected.
  • ♻️ Refactor: Code change that neither fixes a bug nor adds a feature.
  • 💅 Style: Changes that do not affect the meaning of the code (white-space, formatting, etc.).
  • 📚 Documentation: Updates to documentation files.
  • ⚙️ Build/CI: Changes to the build process or CI configuration.
  • 🧹 Chore: Other changes that don't modify src or test files.

Changed Files

  • src/services/glob/list-files.ts

Key Changes

  1. Rewrote listFilteredDirectories() function to properly handle recursive directory scanning
  2. Added recursive scanning logic that respects the recursive parameter
  3. Maintained existing ignore patterns and gitignore rules
  4. Fixed TypeScript compilation issues with import statements

Technical Details

Before (Broken):

async function listFilteredDirectories(dirPath, recursive, gitignorePatterns) {
    // Only read immediate children - recursive parameter ignored!
    const entries = await fs.promises.readdir(absolutePath, { withFileTypes: true })
    const directories = entries.filter(entry => entry.isDirectory())
    return directories.map(entry => path.join(absolutePath, entry.name))
}

After (Fixed):

async function listFilteredDirectories(dirPath, recursive, gitignorePatterns) {
    const directories = []
    
    async function scanDirectory(currentPath, isRoot = false) {
        const entries = await fs.promises.readdir(currentPath, { withFileTypes: true })
        
        for (const entry of entries) {
            if (entry.isDirectory() && shouldIncludeDirectory(entry.name, recursive, gitignorePatterns)) {
                directories.push(fullDirPath + "/")
                
                // 🔑 KEY FIX: Actually use the recursive parameter!
                if (recursive && !isDirectoryExplicitlyIgnored(entry.name)) {
                    await scanDirectory(fullDirPath, false)
                }
            }
        }
    }
    
    await scanDirectory(absolutePath, true)
    return directories
}

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Code Quality:
    • My code adheres to the project's style guidelines.
    • There are no new linting errors or warnings (npm run lint).
    • All debug code (e.g., console.log) has been removed.
  • Testing:
    • New and/or updated tests have been added to cover my changes.
    • All tests pass locally (npm test).
    • The application builds successfully with my changes.
  • Branch Hygiene: My branch is up-to-date (rebased) with the main branch.
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Changeset: A changeset has been created using npm run changeset if this PR includes user-facing changes or dependency updates.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

Documentation Updates

Additional Notes

Get in Touch


Important

Fixes recursive directory scanning in listFilteredDirectories() in list-files.ts to ensure all directory levels are visible when using "Add Folder".

  • Behavior:
    • Fixes listFilteredDirectories() in list-files.ts to handle recursive directory scanning, ensuring all directory levels are visible when using "Add Folder".
    • Respects .gitignore patterns and built-in ignore directories (e.g., node_modules).
    • Maintains directory sorting (directories before files).
  • Technical Details:
    • Rewrites listFilteredDirectories() to use the recursive parameter correctly.
    • Handles permission errors gracefully and logs warnings.
    • Fixes TypeScript import issues with os in list-files.ts.

This description was created by Ellipsis for 85022e8236470c5f79933b84442bb9b83cdbd306. You can customize this summary. It will automatically update as commits are pushed.

@village-way village-way requested review from cte, jr and mrubens as code owners June 19, 2025 01:01
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Jun 19, 2025
@village-way village-way force-pushed the fix/recursive-directory-scanning branch 4 times, most recently from 6792a1b to 20f02de Compare June 19, 2025 01:09
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jun 19, 2025
…lity

- Fix listFilteredDirectories() to properly handle recursive parameter
- Ensure 'Add Folder' shows all directory levels like direct search
- Maintain existing ignore patterns and gitignore rules
- Resolve TypeScript compilation issues

Fixes inconsistency where clicking 'Add Folder' only showed first-level
directories while typing @query showed all levels recursively.

Signed-off-by: wangdepeng <[email protected]>
@village-way village-way force-pushed the fix/recursive-directory-scanning branch from 20f02de to d93fcc0 Compare June 19, 2025 01:43
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jun 19, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jun 19, 2025
Copy link
Member

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

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

Thank you @village-way, this looks good!

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jun 20, 2025
@daniel-lxs daniel-lxs removed the status in Roo Code Roadmap Jun 20, 2025
@daniel-lxs daniel-lxs moved this to PR [Needs Review] in Roo Code Roadmap Jun 20, 2025
@mrubens mrubens merged commit 5012922 into RooCodeInc:main Jun 20, 2025
19 checks passed
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jun 20, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Jun 20, 2025
@hannesrudolph
Copy link
Collaborator

@village-way I work for Roo Code. Do you have discord? If so would you be able to reach out to me (username hrudolph). Thank you!

@village-way
Copy link
Contributor Author

@village-way I work for Roo Code. Do you have discord? If so would you be able to reach out to me (username hrudolph). Thank you!

Hello, my username is devine_peng. I have already joined the Roo-Code Discord server and have been actively following the related updates. I’ve sent you a friend request. It’s a pleasure to meet you. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer PR - Needs Review size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

"Add Folder" in @ mentions only shows first-level directories while direct search shows all levels

4 participants