fix(watcher): close deleted open documents
This commit is contained in:
@@ -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)}`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user