fix(watcher): stabilize daemon readiness and tests
This commit is contained in:
@@ -104,7 +104,7 @@ async function getOrCreateEntry(
|
||||
entries.delete(key);
|
||||
throw err;
|
||||
}
|
||||
attachWatcher(entry);
|
||||
await attachWatcher(entry);
|
||||
bumpIdle(entry);
|
||||
return entry;
|
||||
}
|
||||
@@ -113,9 +113,9 @@ async function getOrCreateEntry(
|
||||
// The first non-empty registration lazily creates the WorkspaceWatcher;
|
||||
// subsequent register/unregister calls update its pattern set in place.
|
||||
// Honors PI_LSP_DISABLE_WATCHERS for emergency rollback.
|
||||
function attachWatcher(entry: ClientEntry): void {
|
||||
async function attachWatcher(entry: ClientEntry): Promise<void> {
|
||||
if (process.env.PI_LSP_DISABLE_WATCHERS) return;
|
||||
const sync = () => {
|
||||
const sync = async () => {
|
||||
const patterns = entry.client.getFileWatchers();
|
||||
if (patterns.length === 0 && !entry.watcher) return;
|
||||
if (!entry.watcher) {
|
||||
@@ -128,11 +128,13 @@ function attachWatcher(entry: ClientEntry): void {
|
||||
log(`watcher patterns`, entry.server.id, JSON.stringify(patterns));
|
||||
}
|
||||
entry.watcher.setPatterns(patterns);
|
||||
if (patterns.length > 0) await entry.watcher.ready();
|
||||
};
|
||||
entry.unsubscribeWatchers = entry.client.onWatchersChanged(sync);
|
||||
entry.unsubscribeWatchers = entry.client.onWatchersChanged(() => void sync());
|
||||
// Initial Sync - Server may have already sent registerCapability during
|
||||
// initialize before we subscribed.
|
||||
sync();
|
||||
// initialize before we subscribed. Wait for chokidar's initial scan so
|
||||
// externally-created files are not swallowed as ignoreInitial events.
|
||||
await sync();
|
||||
}
|
||||
|
||||
// Forward Events - Sends a batched workspace/didChangeWatchedFiles to the
|
||||
|
||||
Reference in New Issue
Block a user