Skip to content

Commit ff5dcd9

Browse files
committed
Fix .rooignore not working for nested project folders
- Modified DirectoryScanner to accept workspace root parameter - RooIgnoreController now uses workspace root instead of scan directory - This ensures .rooignore files in workspace root properly filter nested project files - Fixes issue #4647 where .next folders in nested Next.js projects were being indexed Changes: - src/services/code-index/processors/scanner.ts: Added workspaceRoot parameter - src/services/code-index/service-factory.ts: Pass workspacePath to scanner - src/services/code-index/processors/__tests__/scanner.spec.ts: Updated test constructor
1 parent ca0338a commit ff5dcd9

File tree

5 files changed

+827
-3
lines changed

5 files changed

+827
-3
lines changed

roo-code-messages.log

Lines changed: 760 additions & 0 deletions
Large diffs are not rendered by default.

src/services/code-index/processors/__tests__/scanner.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ describe("DirectoryScanner", () => {
102102
mockCodeParser,
103103
mockCacheManager,
104104
mockIgnoreInstance,
105+
"/mock/workspace", // Add workspace root parameter
105106
)
106107

107108
// Mock default implementations - create proper Stats object

src/services/code-index/processors/scanner.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export class DirectoryScanner implements IDirectoryScanner {
3030
private readonly codeParser: ICodeParser,
3131
private readonly cacheManager: CacheManager,
3232
private readonly ignoreInstance: Ignore,
33+
private readonly workspaceRoot?: string,
3334
) {}
3435

3536
/**
@@ -53,8 +54,10 @@ export class DirectoryScanner implements IDirectoryScanner {
5354
// Filter out directories (marked with trailing '/')
5455
const filePaths = allPaths.filter((p) => !p.endsWith("/"))
5556

56-
// Initialize RooIgnoreController if not provided
57-
const ignoreController = new RooIgnoreController(directoryPath)
57+
// Initialize RooIgnoreController with workspace root (not the directory being scanned)
58+
// This ensures .rooignore files are always looked for in the workspace root
59+
const rooIgnoreWorkingDirectory = this.workspaceRoot || directoryPath
60+
const ignoreController = new RooIgnoreController(rooIgnoreWorkingDirectory)
5861

5962
await ignoreController.initialize()
6063

src/services/code-index/service-factory.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,14 @@ export class CodeIndexServiceFactory {
110110
parser: ICodeParser,
111111
ignoreInstance: Ignore,
112112
): DirectoryScanner {
113-
return new DirectoryScanner(embedder, vectorStore, parser, this.cacheManager, ignoreInstance)
113+
return new DirectoryScanner(
114+
embedder,
115+
vectorStore,
116+
parser,
117+
this.cacheManager,
118+
ignoreInstance,
119+
this.workspacePath,
120+
)
114121
}
115122

116123
/**

test-rooignore-issue.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Test script to reproduce the .rooignore issue with nested project folders
2+
const path = require("path")
3+
4+
// Simulate the issue scenario
5+
const rootFolder = "/Users/test/Root Folder"
6+
const nextjsProject = "/Users/test/Root Folder/example-nextjs"
7+
const nextFolder = "/Users/test/Root Folder/example-nextjs/.next"
8+
9+
// Test the path normalization logic from RooIgnoreController
10+
function testPathNormalization(cwd, filePath) {
11+
console.log(`\nTesting path normalization:`)
12+
console.log(`CWD: ${cwd}`)
13+
console.log(`File path: ${filePath}`)
14+
15+
// This is the logic from RooIgnoreController.validateAccess()
16+
const absolutePath = path.resolve(cwd, filePath)
17+
console.log(`Absolute path: ${absolutePath}`)
18+
19+
const relativePath = path.relative(cwd, absolutePath)
20+
console.log(`Relative path: ${relativePath}`)
21+
22+
// Convert to POSIX (forward slashes)
23+
const posixPath = relativePath.replace(/\\/g, "/")
24+
console.log(`POSIX path: ${posixPath}`)
25+
26+
return posixPath
27+
}
28+
29+
// Test case 1: .rooignore in root folder, trying to ignore nested .next folder
30+
console.log("=== Test Case 1: .rooignore in Root Folder ===")
31+
const rooignorePattern = "example-nextjs/.next/"
32+
const fileToCheck = "example-nextjs/.next/server/pages/index.js"
33+
34+
const normalizedPath = testPathNormalization(rootFolder, fileToCheck)
35+
console.log(`\nPattern in .rooignore: ${rooignorePattern}`)
36+
console.log(`Normalized file path: ${normalizedPath}`)
37+
console.log(`Should match pattern: ${normalizedPath.startsWith(rooignorePattern.replace(/\/$/, ""))}`)
38+
39+
// Test case 2: What if the file path is already absolute?
40+
console.log("\n=== Test Case 2: Absolute file path ===")
41+
const absoluteFileToCheck = path.join(nextjsProject, ".next/server/pages/index.js")
42+
const normalizedPath2 = testPathNormalization(rootFolder, absoluteFileToCheck)
43+
console.log(`\nPattern in .rooignore: ${rooignorePattern}`)
44+
console.log(`Normalized file path: ${normalizedPath2}`)
45+
console.log(`Should match pattern: ${normalizedPath2.startsWith(rooignorePattern.replace(/\/$/, ""))}`)
46+
47+
// Test case 3: What if we're scanning from the nextjs project directory?
48+
console.log("\n=== Test Case 3: Scanning from nextjs project directory ===")
49+
const fileInNext = ".next/server/pages/index.js"
50+
const normalizedPath3 = testPathNormalization(nextjsProject, fileInNext)
51+
console.log(`\nIf .rooignore was in nextjs project with pattern: .next/`)
52+
console.log(`Normalized file path: ${normalizedPath3}`)
53+
console.log(`Should match pattern: ${normalizedPath3.startsWith(".next/")}`)

0 commit comments

Comments
 (0)