mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 18:49:00 +01:00
Add logging for TS extension file watcher creation (#185813)
Add logging for extension file watcher creation
This commit is contained in:
@@ -46,24 +46,34 @@ function fromResource(extensionUri: URI, uri: URI) {
|
||||
}
|
||||
return `/${uri.scheme}/${uri.authority}${uri.path}`;
|
||||
}
|
||||
|
||||
function updateWatch(event: 'create' | 'change' | 'delete', uri: URI, extensionUri: URI) {
|
||||
const kind = event === 'create' ? ts.FileWatcherEventKind.Created
|
||||
: event === 'change' ? ts.FileWatcherEventKind.Changed
|
||||
: event === 'delete' ? ts.FileWatcherEventKind.Deleted
|
||||
: ts.FileWatcherEventKind.Changed;
|
||||
const kind = toTsWatcherKind(event);
|
||||
const path = fromResource(extensionUri, uri);
|
||||
if (watchFiles.has(path)) {
|
||||
watchFiles.get(path)!.callback(path, kind);
|
||||
|
||||
const fileWatcher = watchFiles.get(path);
|
||||
if (fileWatcher) {
|
||||
fileWatcher.callback(path, kind);
|
||||
return;
|
||||
}
|
||||
let found = false;
|
||||
|
||||
for (const watch of Array.from(watchDirectories.keys()).filter(dir => path.startsWith(dir))) {
|
||||
watchDirectories.get(watch)!.callback(path);
|
||||
found = true;
|
||||
return;
|
||||
}
|
||||
if (!found) {
|
||||
console.error(`no watcher found for ${path}`);
|
||||
|
||||
console.error(`no watcher found for ${path}`);
|
||||
}
|
||||
|
||||
function toTsWatcherKind(event: 'create' | 'change' | 'delete') {
|
||||
if (event === 'create') {
|
||||
return ts.FileWatcherEventKind.Created;
|
||||
} else if (event === 'change') {
|
||||
return ts.FileWatcherEventKind.Changed;
|
||||
} else if (event === 'delete') {
|
||||
return ts.FileWatcherEventKind.Deleted;
|
||||
}
|
||||
throw new Error(`Unknown event: ${event}`);
|
||||
}
|
||||
|
||||
type ServerHostWithImport = ts.server.ServerHost & { importPlugin(root: string, moduleName: string): Promise<ts.server.ModuleImportResult> };
|
||||
|
||||
Reference in New Issue
Block a user