mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 12:21:13 -05:00
Use createFileSystemWatcher to more reliably watch for file system changes
This commit is contained in:
@@ -27,58 +27,36 @@ class WorkspaceTracker {
|
||||
}
|
||||
|
||||
private registerListeners() {
|
||||
// Create a file system watcher for all files
|
||||
const watcher = vscode.workspace.createFileSystemWatcher('**')
|
||||
|
||||
// Listen for file creation
|
||||
// .bind(this) ensures the callback refers to class instance when using this, not necessary when using arrow function
|
||||
this.disposables.push(vscode.workspace.onDidCreateFiles(this.onFilesCreated.bind(this)))
|
||||
this.disposables.push(
|
||||
watcher.onDidCreate(async (uri) => {
|
||||
await this.addFilePath(uri.fsPath)
|
||||
this.workspaceDidUpdate()
|
||||
})
|
||||
)
|
||||
|
||||
// Listen for file deletion
|
||||
this.disposables.push(vscode.workspace.onDidDeleteFiles(this.onFilesDeleted.bind(this)))
|
||||
|
||||
// Listen for file renaming
|
||||
this.disposables.push(vscode.workspace.onDidRenameFiles(this.onFilesRenamed.bind(this)))
|
||||
|
||||
/*
|
||||
An event that is emitted when a workspace folder is added or removed.
|
||||
**Note:** this event will not fire if the first workspace folder is added, removed or changed,
|
||||
because in that case the currently executing extensions (including the one that listens to this
|
||||
event) will be terminated and restarted so that the (deprecated) `rootPath` property is updated
|
||||
to point to the first workspace folder.
|
||||
*/
|
||||
// In other words, we don't have to worry about the root workspace folder ([0]) changing since the extension will be restarted and our cwd will be updated to reflect the new workspace folder. (We don't care about non root workspace folders, since cline will only be working within the root folder cwd)
|
||||
// this.disposables.push(vscode.workspace.onDidChangeWorkspaceFolders(this.onWorkspaceFoldersChanged.bind(this)))
|
||||
}
|
||||
|
||||
private async onFilesCreated(event: vscode.FileCreateEvent) {
|
||||
await Promise.all(
|
||||
event.files.map(async (file) => {
|
||||
await this.addFilePath(file.fsPath)
|
||||
}),
|
||||
)
|
||||
this.disposables.push(
|
||||
watcher.onDidDelete(async (uri) => {
|
||||
if (await this.removeFilePath(uri.fsPath)) {
|
||||
this.workspaceDidUpdate()
|
||||
}
|
||||
|
||||
private async onFilesDeleted(event: vscode.FileDeleteEvent) {
|
||||
let updated = false
|
||||
await Promise.all(
|
||||
event.files.map(async (file) => {
|
||||
if (await this.removeFilePath(file.fsPath)) {
|
||||
updated = true
|
||||
}
|
||||
}),
|
||||
})
|
||||
)
|
||||
if (updated) {
|
||||
this.workspaceDidUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
private async onFilesRenamed(event: vscode.FileRenameEvent) {
|
||||
await Promise.all(
|
||||
event.files.map(async (file) => {
|
||||
await this.removeFilePath(file.oldUri.fsPath)
|
||||
await this.addFilePath(file.newUri.fsPath)
|
||||
}),
|
||||
)
|
||||
// Listen for file changes (which could include renames)
|
||||
this.disposables.push(
|
||||
watcher.onDidChange(async (uri) => {
|
||||
await this.addFilePath(uri.fsPath)
|
||||
this.workspaceDidUpdate()
|
||||
})
|
||||
)
|
||||
|
||||
// Add the watcher itself to disposables
|
||||
this.disposables.push(watcher)
|
||||
}
|
||||
|
||||
private workspaceDidUpdate() {
|
||||
|
||||
Reference in New Issue
Block a user