Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions tests/lsp/worker_map_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ function workerBootstrap() {
fs.watch = (directory, ...args) => {
const listener = args.pop();
const watcher = watch(directory, ...args, (event, filename) => {
// macOS FSEvents can drop a change made while the stream starts; the worker must not need it.
if (
directory === registrationParent &&
filename === path.basename(path.dirname(registrationDirectory))
) {
return;
}
const sibling = path.basename(workerData.ancestorNoise);
if (
directory === workerData.workspaceRoot &&
Expand Down
12 changes: 10 additions & 2 deletions tools/tsserver-hook-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const BUILD_FILES = new Set(['BUILD.bazel', 'BUILD']);

const DEBUG = !!process.env.TSSERVER_HOOK_DEBUG;
const directoryWatchers = new Map();
// Declared before the initial build, whose watch attachment may already schedule a rebuild.
let rebuildTimer = null;

function log(msg) {
if (DEBUG) {
Expand Down Expand Up @@ -315,8 +317,6 @@ parentPort.postMessage({ type: 'resolution-map', data: initialMap });

// ── File-system watchers ──────────────────────────────────────────────────────

let rebuildTimer = null;

function scheduleRebuild() {
if (rebuildTimer) return;
rebuildTimer = setTimeout(() => {
Expand Down Expand Up @@ -386,6 +386,14 @@ function watchDirectory(dir, root, watched, filename) {
scheduleRebuild();
}
});
// A directory replaced while its watch attaches may never send an event (macOS FSEvents).
let attached;
try {
attached = fs.statSync(canonical);
} catch (_) {}
if (!attached || attached.dev !== stat.dev || attached.ino !== stat.ino) {
scheduleRebuild();
}
} else {
current.filter = filter;
}
Expand Down
Loading