Skip to content

Commit 7bf1d85

Browse files
authored
refactor(workspace): optimize file watching and ignore patterns (#400)
* refactor(workspace): optimize file watching and ignore patterns * refactor: update ignore patterns for directories
1 parent 3c94150 commit 7bf1d85

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/core/costrict/codebase-index/workspace-event-monitor.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { getWorkspacePath } from "../../../utils/path"
1111
import * as path from "path"
1212
import type { ClineProvider } from "../../webview/ClineProvider"
1313
import { LRUCache } from "lru-cache"
14+
import { isPathInIgnoredDirectory } from "../../../services/glob/ignore-utils"
15+
import { scannerExtensions } from "../../../services/code-index/shared/supported-extensions"
1416

1517
type FileEventHandler = (uri: vscode.Uri) => void
1618
type RenameEventHandler = (oldPath: vscode.Uri, newPath: vscode.Uri) => void
@@ -231,7 +233,10 @@ export class WorkspaceEventMonitor {
231233

232234
try {
233235
watchPaths.forEach((watchPath) => {
234-
const relPattern = new vscode.RelativePattern(vscode.Uri.file(watchPath), "**/*")
236+
const relPattern = new vscode.RelativePattern(
237+
vscode.Uri.file(watchPath),
238+
`**/*{${scannerExtensions.map((e) => e.substring(1)).join(",")}}`,
239+
)
235240
const watcher = vscode.workspace.createFileSystemWatcher(relPattern)
236241

237242
watcher.onDidCreate((uri) => {
@@ -308,18 +313,15 @@ export class WorkspaceEventMonitor {
308313
}
309314

310315
// Then, check against our built-in patterns
311-
if (/(^|[\/\\])\../.test(filePath)) {
316+
if (isPathInIgnoredDirectory(filePath)) {
312317
return true
313318
}
314319

315320
// Additional checks based on file stats if available
316321
// Ignore directories that match certain patterns
317322
if (stats.isDirectory()) {
318323
const dirName = path.basename(filePath)
319-
if (
320-
dirName.startsWith(".") ||
321-
["node_modules", "dist", "build", "out", "coverage", "tests", "mocks"].includes(dirName)
322-
) {
324+
if (["tests", "mocks"].includes(dirName)) {
323325
return true
324326
}
325327
}

src/services/glob/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,9 @@ export const DIRS_TO_IGNORE = [
2121
"pkg",
2222
"Pods",
2323
".git",
24+
"coverage",
25+
".history",
26+
".turbo",
27+
".cache",
2428
".*",
2529
]

0 commit comments

Comments
 (0)