Skip to content

Commit a6ee617

Browse files
committed
fix(vscode): invalidate the standby on every rstack config event
The config watcher listened for content changes only, on the reasoning that a create or a delete moves the detection signature and arrives as a detection change instead. That holds for a real create or delete, not for the delete/create pair an editor emits when it saves by atomically replacing the file: the config path is gone and back within one scan, the signature records paths rather than content, and no detection change fires. Both halves were also ignored here, so nothing invalidated the standby and the parked process kept serving the config it had loaded at spawn — the same file then formatted one way hot and another way cold. Watch all three events. A redundant kill costs nothing: it is idempotent and the active editor re-arms through the usual debounce.
1 parent 54789e4 commit a6ee617

1 file changed

Lines changed: 12 additions & 15 deletions

File tree

packages/vscode/src/stacks/fmt/index.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,15 @@ class FmtController implements StackController {
128128
this.provideDocumentFormattingEdits(document, token),
129129
};
130130
// `rs fmt` loads the project config while it drains stdin, so a parked
131-
// process already carries the old config. Detection does not fire on config
132-
// *content* edits — its signature only tracks which files exist — so the
133-
// standby needs its own watcher over the same glob.
134-
// Create and delete already arrive as detection changes (the file set is
135-
// part of its signature), so this watcher covers only the content edits
136-
// detection cannot see — the same split `stacks/test/project.ts` uses.
137-
const configWatcher = vscode.workspace.createFileSystemWatcher(
138-
RSTACK_CONFIG_GLOB,
139-
true,
140-
false,
141-
true,
142-
);
131+
// process already carries the old config and every config event has to
132+
// invalidate it. Detection cannot stand in for this watcher: its signature
133+
// records only which config files exist, so it misses a content edit, and
134+
// it misses the delete/create pair an atomic save produces for one
135+
// unchanged path just the same.
136+
const configWatcher =
137+
vscode.workspace.createFileSystemWatcher(RSTACK_CONFIG_GLOB);
138+
const onConfigEvent = (uri: vscode.Uri): void =>
139+
this.invalidateStandby(`${uri.fsPath} changed`);
143140
this.#subscriptions.push(
144141
context.onDidChangeDetection((snapshot) => {
145142
this.#snapshot = snapshot;
@@ -156,9 +153,9 @@ class FmtController implements StackController {
156153
provider,
157154
),
158155
configWatcher,
159-
configWatcher.onDidChange((uri) =>
160-
this.invalidateStandby(`${uri.fsPath} changed`),
161-
),
156+
configWatcher.onDidCreate(onConfigEvent),
157+
configWatcher.onDidChange(onConfigEvent),
158+
configWatcher.onDidDelete(onConfigEvent),
162159
vscode.window.onDidChangeActiveTextEditor(() => this.scheduleArm()),
163160
);
164161
this.reportRunning(context, context.detection);

0 commit comments

Comments
 (0)