fix(watcher): close deleted open documents

This commit is contained in:
2026-05-20 00:22:30 -04:00
parent 62fc80c70f
commit 14749a6449
3 changed files with 59 additions and 1 deletions

View File

@@ -32,7 +32,7 @@ interface DiagResult {
[serverId: string]: { diagnostics?: { message: string }[] };
}
describe("watcher: gopls picks up externally-created files", { skip: skip ?? undefined }, () => {
describe("watcher: gopls picks up external file changes", { skip: skip ?? undefined }, () => {
let tmpDir: string;
let mainFile: string;
let helperFile: string;
@@ -122,4 +122,48 @@ describe("watcher: gopls picks up externally-created files", { skip: skip ?? und
`Expected diagnostic to clear after creating helper.go, still got: ${JSON.stringify(finalDiags)}`,
);
});
it("closes an opened file when it is deleted externally", async () => {
fs.writeFileSync(
helperFile,
"package main\n\nfunc Helper(x int) {}\n",
);
await runCliJson([helperFile, "diagnostics", '{"timeoutMs":3000}'], env);
await pollUntil(
async () =>
(await runCliJson(
[mainFile, "diagnostics", '{"timeoutMs":3000}'],
env,
)) as DiagResult,
(r) => {
const diags = r["gopls"]?.diagnostics ?? [];
return diags.some((d) => d.message.includes("not enough arguments"));
},
15000,
500,
);
fs.rmSync(helperFile);
const result = await pollUntil(
async () =>
(await runCliJson(
[mainFile, "diagnostics", '{"timeoutMs":3000}'],
env,
)) as DiagResult,
(r) => {
const diags = r["gopls"]?.diagnostics ?? [];
return diags.some((d) => d.message.toLowerCase().includes("undefined"));
},
15000,
500,
);
const finalDiags = result["gopls"]?.diagnostics ?? [];
assert.ok(
finalDiags.some((d) => d.message.toLowerCase().includes("undefined")),
`Expected undefined-symbol diagnostic after deleting opened helper.go, got: ${JSON.stringify(finalDiags)}`,
);
});
});