Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: will watch same folder multiple times #3831

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions packages/file-service/src/node/recursive/file-service-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ export interface WatcherOptions {
excludes: string[];
}

const watcherPlaceHolder = {
disposable: {
dispose: () => {},
},
handlers: [],
};

/**
* @deprecated
*/
Expand Down Expand Up @@ -88,18 +95,24 @@ export class FileSystemWatcherServer implements IFileSystemWatcherServer {
*/
async watchFileChanges(uri: string, options?: WatchOptions): Promise<number> {
const basePath = FileUri.fsPath(uri);
const exist = await fs.pathExists(basePath);

let watcherId = this.checkIsAlreadyWatched(basePath);
if (watcherId) {
return watcherId;
}

watcherId = FileSystemWatcherServer.WATCHER_SEQUENCE++;
this.WATCHER_HANDLERS.set(watcherId, {
...watcherPlaceHolder,
path: basePath,
});

const toDisposeWatcher = new DisposableCollection();
let watchPath;
let watchPath: string;

const exist = await fs.pathExists(basePath);
if (exist) {
const stat = await fs.lstatSync(basePath);
const stat = await fs.lstat(basePath);
if (stat && stat.isDirectory()) {
watchPath = basePath;
} else {
Expand All @@ -116,14 +129,16 @@ export class FileSystemWatcherServer implements IFileSystemWatcherServer {
}
events = this.trimChangeEvent(events);
for (const event of events) {
if (event.type === 'create') {
this.pushAdded(event.path);
}
if (event.type === 'delete') {
this.pushDeleted(event.path);
}
if (event.type === 'update') {
this.pushUpdated(event.path);
switch (event.type) {
case 'create':
this.pushAdded(event.path);
break;
case 'delete':
this.pushDeleted(event.path);
break;
case 'update':
this.pushUpdated(event.path);
break;
}
}
};
Expand Down
Loading