Skip to content

Commit 6e1a48d

Browse files
committed
refactor: simplify whitelist implementation based on review feedback
- Remove unnecessary complexity and manual gitignore parsing - Fix root cause: ripgrep's glob patterns filtering hidden directories - Delete unused files (ignore-utils.ts, RooIgnoreController.gitignore.spec.ts) - Simplify RooIgnoreController back to original implementation - Keep all whitelist logic contained in list-files.ts - Add isPathInIgnoredDirectory methods to scanner and file-watcher The implementation is now ~30 lines instead of ~100 lines, directly addressing the root cause identified by daniel-lxs where ripgrep's -g '!**/.*/**' pattern was filtering out hidden directories even when --no-ignore-vcs was used.
1 parent 02627aa commit 6e1a48d

File tree

6 files changed

+109
-475
lines changed

6 files changed

+109
-475
lines changed

src/core/ignore/RooIgnoreController.ts

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { fileExistsAtPath } from "../../utils/fs"
33
import fs from "fs/promises"
44
import ignore, { Ignore } from "ignore"
55
import * as vscode from "vscode"
6-
import { GITIGNORE_WHITELIST } from "../../services/glob/constants"
76

87
export const LOCK_TEXT_SYMBOL = "\u{1F512}"
98

@@ -15,9 +14,7 @@ export const LOCK_TEXT_SYMBOL = "\u{1F512}"
1514
export class RooIgnoreController {
1615
private cwd: string
1716
private ignoreInstance: Ignore
18-
private gitignoreInstance: Ignore | null = null
1917
private disposables: vscode.Disposable[] = []
20-
private whitelist = GITIGNORE_WHITELIST
2118
rooIgnoreContent: string | undefined
2219

2320
constructor(cwd: string) {
@@ -34,7 +31,6 @@ export class RooIgnoreController {
3431
*/
3532
async initialize(): Promise<void> {
3633
await this.loadRooIgnore()
37-
await this.loadGitignore()
3834
}
3935

4036
/**
@@ -83,75 +79,6 @@ export class RooIgnoreController {
8379
}
8480
}
8581

86-
/**
87-
* Load patterns from .gitignore if it exists
88-
*/
89-
async loadGitignore(): Promise<void> {
90-
try {
91-
this.gitignoreInstance = ignore()
92-
const gitignorePath = path.join(this.cwd, ".gitignore")
93-
if (await fileExistsAtPath(gitignorePath)) {
94-
const content = await fs.readFile(gitignorePath, "utf8")
95-
this.gitignoreInstance.add(content)
96-
}
97-
} catch (error) {
98-
console.error("Error loading .gitignore:", error)
99-
this.gitignoreInstance = null
100-
}
101-
}
102-
103-
/**
104-
* Check if a path is whitelisted
105-
* @param filePath - Path to check (relative to cwd)
106-
* @returns true if path is whitelisted
107-
*/
108-
isWhitelisted(filePath: string): boolean {
109-
// Convert to relative path if absolute
110-
let relativePath: string
111-
if (path.isAbsolute(filePath)) {
112-
relativePath = path.relative(this.cwd, filePath)
113-
} else {
114-
relativePath = filePath
115-
}
116-
117-
// Normalize the path
118-
const normalizedPath = path.normalize(relativePath).replace(/\\/g, "/")
119-
120-
return this.whitelist.some((pattern) => {
121-
const normalizedPattern = path.normalize(pattern).replace(/\\/g, "/")
122-
// Check if this is the whitelisted path or under it
123-
return (
124-
normalizedPath === normalizedPattern ||
125-
normalizedPath.startsWith(normalizedPattern + "/") ||
126-
// Check if this is a parent of the whitelisted path
127-
normalizedPattern.startsWith(normalizedPath + "/")
128-
)
129-
})
130-
}
131-
132-
/**
133-
* Check if a path is ignored by gitignore (considering whitelist)
134-
* @param filePath - Path to check (relative to cwd)
135-
* @returns true if path is ignored by gitignore and not whitelisted
136-
*/
137-
isGitignored(filePath: string): boolean {
138-
if (!this.gitignoreInstance) {
139-
return false
140-
}
141-
142-
// Check whitelist first
143-
if (this.isWhitelisted(filePath)) {
144-
return false
145-
}
146-
147-
try {
148-
const relativePath = path.relative(this.cwd, path.resolve(this.cwd, filePath)).replace(/\\/g, "/")
149-
return this.gitignoreInstance.ignores(relativePath)
150-
} catch (error) {
151-
return false
152-
}
153-
}
154-
15582
/**
15683
* Check if a file should be accessible to the LLM
15784
* @param filePath - Path to check (relative to cwd)

src/core/ignore/__tests__/RooIgnoreController.gitignore.spec.ts

Lines changed: 0 additions & 245 deletions
This file was deleted.

src/services/code-index/processors/file-watcher.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import {
2222
import { codeParser } from "./parser"
2323
import { CacheManager } from "../cache-manager"
2424
import { generateNormalizedAbsolutePath, generateRelativeFilePath } from "../shared/get-relative-path"
25-
import { isPathInIgnoredDirectory } from "../../glob/ignore-utils"
25+
import { DIRS_TO_IGNORE } from "../../glob/constants"
26+
import * as path from "path"
2627

2728
/**
2829
* Implementation of the file watcher interface
@@ -455,7 +456,7 @@ export class FileWatcher implements IFileWatcher {
455456
async processFile(filePath: string): Promise<FileProcessingResult> {
456457
try {
457458
// Check if file is in an ignored directory
458-
if (isPathInIgnoredDirectory(filePath)) {
459+
if (this.isPathInIgnoredDirectory(filePath)) {
459460
return {
460461
path: filePath,
461462
status: "skipped" as const,
@@ -543,4 +544,23 @@ export class FileWatcher implements IFileWatcher {
543544
}
544545
}
545546
}
547+
548+
/**
549+
* Check if a path is within an ignored directory
550+
*/
551+
private isPathInIgnoredDirectory(filePath: string): boolean {
552+
const normalizedPath = path.normalize(filePath)
553+
const pathParts = normalizedPath.split(path.sep)
554+
555+
return pathParts.some((part) => {
556+
// Check if any part of the path matches an ignored directory
557+
return DIRS_TO_IGNORE.some((dir) => {
558+
if (dir === ".*") {
559+
// Special case for hidden directories (starting with .)
560+
return part.startsWith(".") && part !== "."
561+
}
562+
return part === dir
563+
})
564+
})
565+
}
546566
}

0 commit comments

Comments
 (0)