mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Watch events enhancements (#57950)
This commit is contained in:
1 parent
6b4eec4aca
commit
c87b5bcab9
6 files changed
+1192
-135
No files matched your search
@@ -933,7 +933,16 @@ function createWatchFactoryHostUsingWatchEvents(service: ProjectService, canUseW
|
||||
recursive ? watchedDirectoriesRecursive : watchedDirectories,
|
||||
path,
|
||||
callback,
|
||||
id => ({ eventName: CreateDirectoryWatcherEvent, data: { id, path, recursive: !!recursive } }),
|
||||
id => ({
|
||||
eventName: CreateDirectoryWatcherEvent,
|
||||
data: {
|
||||
id,
|
||||
path,
|
||||
recursive: !!recursive,
|
||||
// Special case node_modules as we watch it for changes to closed script infos as well
|
||||
ignoreUpdate: !path.endsWith("/node_modules") ? true : undefined,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
function getOrCreateFileWatcher<T>(
|
||||
@@ -963,37 +972,32 @@ function createWatchFactoryHostUsingWatchEvents(service: ProjectService, canUseW
|
||||
},
|
||||
};
|
||||
}
|
||||
function onWatchChange({ id, path, eventType }: protocol.WatchChangeRequestArgs) {
|
||||
// console.log(`typescript-vscode-watcher:: Invoke:: ${id}:: ${path}:: ${eventType}`);
|
||||
onFileWatcherCallback(id, path, eventType);
|
||||
onDirectoryWatcherCallback(watchedDirectories, id, path, eventType);
|
||||
onDirectoryWatcherCallback(watchedDirectoriesRecursive, id, path, eventType);
|
||||
function onWatchChange(args: protocol.WatchChangeRequestArgs | readonly protocol.WatchChangeRequestArgs[]) {
|
||||
if (isArray(args)) args.forEach(onWatchChangeRequestArgs);
|
||||
else onWatchChangeRequestArgs(args);
|
||||
}
|
||||
|
||||
function onFileWatcherCallback(
|
||||
id: number,
|
||||
eventPath: string,
|
||||
eventType: "create" | "delete" | "update",
|
||||
) {
|
||||
watchedFiles.idToCallbacks.get(id)?.forEach(callback => {
|
||||
const eventKind = eventType === "create" ?
|
||||
FileWatcherEventKind.Created :
|
||||
eventType === "delete" ?
|
||||
FileWatcherEventKind.Deleted :
|
||||
FileWatcherEventKind.Changed;
|
||||
callback(eventPath, eventKind);
|
||||
});
|
||||
function onWatchChangeRequestArgs({ id, created, deleted, updated }: protocol.WatchChangeRequestArgs) {
|
||||
onWatchEventType(id, created, FileWatcherEventKind.Created);
|
||||
onWatchEventType(id, deleted, FileWatcherEventKind.Deleted);
|
||||
onWatchEventType(id, updated, FileWatcherEventKind.Changed);
|
||||
}
|
||||
|
||||
function onDirectoryWatcherCallback(
|
||||
{ idToCallbacks }: HostWatcherMap<DirectoryWatcherCallback>,
|
||||
function onWatchEventType(id: number, paths: readonly string[] | undefined, eventKind: FileWatcherEventKind) {
|
||||
if (!paths?.length) return;
|
||||
forEachCallback(watchedFiles, id, paths, (callback, eventPath) => callback(eventPath, eventKind));
|
||||
forEachCallback(watchedDirectories, id, paths, (callback, eventPath) => callback(eventPath));
|
||||
forEachCallback(watchedDirectoriesRecursive, id, paths, (callback, eventPath) => callback(eventPath));
|
||||
}
|
||||
|
||||
function forEachCallback<T>(
|
||||
hostWatcherMap: HostWatcherMap<T>,
|
||||
id: number,
|
||||
eventPath: string,
|
||||
eventType: "create" | "delete" | "update",
|
||||
eventPaths: readonly string[],
|
||||
cb: (callback: T, eventPath: string) => void,
|
||||
) {
|
||||
if (eventType === "update") return;
|
||||
idToCallbacks.get(id)?.forEach(callback => {
|
||||
callback(eventPath);
|
||||
hostWatcherMap.idToCallbacks.get(id)?.forEach(callback => {
|
||||
eventPaths.forEach(eventPath => cb(callback, eventPath));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1849,13 +1849,13 @@ export interface CloseRequest extends FileRequest {
|
||||
|
||||
export interface WatchChangeRequest extends Request {
|
||||
command: CommandTypes.WatchChange;
|
||||
arguments: WatchChangeRequestArgs;
|
||||
arguments: WatchChangeRequestArgs | readonly WatchChangeRequestArgs[];
|
||||
}
|
||||
|
||||
export interface WatchChangeRequestArgs {
|
||||
id: number;
|
||||
path: string;
|
||||
eventType: "create" | "delete" | "update";
|
||||
created?: string[];
|
||||
deleted?: string[];
|
||||
updated?: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2656,6 +2656,7 @@ export interface CreateDirectoryWatcherEventBody {
|
||||
readonly id: number;
|
||||
readonly path: string;
|
||||
readonly recursive: boolean;
|
||||
readonly ignoreUpdate?: boolean;
|
||||
}
|
||||
|
||||
export type CloseFileWatcherEventName = "closeFileWatcher";
|
||||
|
||||
Reference in new issue
Block a user