fix(watcher): cap startup wait
This commit is contained in:
@@ -1,8 +1,3 @@
|
||||
// Watcher Integration Test — proves the FS-watcher → LSP wiring works
|
||||
// end-to-end against gopls: a stale "undefined symbol" diagnostic clears
|
||||
// after the missing file is created externally (no LSP query touches it).
|
||||
//
|
||||
// This is the canonical staleness scenario from `_scratch/plan-fs-watching.md`.
|
||||
import { describe, it, before, after } from "node:test";
|
||||
import * as assert from "node:assert/strict";
|
||||
import * as fs from "node:fs";
|
||||
@@ -17,10 +12,6 @@ import {
|
||||
|
||||
const skip = requireServer("gopls");
|
||||
|
||||
// Poll Until - Runs `fn` repeatedly until `predicate(result)` is true or
|
||||
// the timeout elapses. We need this because gopls reanalysis after a
|
||||
// workspace/didChangeWatchedFiles is asynchronous; diagnostics arrive on
|
||||
// a `textDocument/publishDiagnostics` push that we then re-fetch.
|
||||
async function pollUntil<T>(
|
||||
fn: () => Promise<T>,
|
||||
predicate: (v: T) => boolean,
|
||||
@@ -53,12 +44,9 @@ describe("watcher: gopls picks up externally-created files", { skip: skip ?? und
|
||||
await stopTestDaemon(env);
|
||||
|
||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "pi-lsp-gopls-watch-"));
|
||||
// Minimal Go Module - go.mod is gopls's primary root marker.
|
||||
fs.writeFileSync(path.join(tmpDir, "go.mod"), "module example.com/wtest\n\ngo 1.21\n");
|
||||
mainFile = path.join(tmpDir, "main.go");
|
||||
helperFile = path.join(tmpDir, "helper.go");
|
||||
// main.go references Helper() which doesn't exist yet \u2014 should produce
|
||||
// an "undefined: Helper" diagnostic.
|
||||
fs.writeFileSync(
|
||||
mainFile,
|
||||
"package main\n\nfunc main() {\n\tHelper()\n}\n",
|
||||
@@ -72,9 +60,6 @@ describe("watcher: gopls picks up externally-created files", { skip: skip ?? und
|
||||
});
|
||||
|
||||
it("initially reports undefined symbol", async () => {
|
||||
// Poll - gopls's workspace load on a fresh tmp dir takes a beat; the
|
||||
// first diagnostics call can return "No active builds contain ..."
|
||||
// before the real analysis lands. Wait up to 15s for it to settle.
|
||||
const result = await pollUntil(
|
||||
async () =>
|
||||
(await runCliJson(
|
||||
@@ -103,16 +88,11 @@ describe("watcher: gopls picks up externally-created files", { skip: skip ?? und
|
||||
});
|
||||
|
||||
it("clears the diagnostic after helper.go is created externally", async () => {
|
||||
// Create The Missing File Without Touching It Via LSP - This is the
|
||||
// whole point: only chokidar + workspace/didChangeWatchedFiles can tell
|
||||
// gopls about helper.go's existence.
|
||||
fs.writeFileSync(
|
||||
helperFile,
|
||||
"package main\n\nfunc Helper() {}\n",
|
||||
);
|
||||
|
||||
// Poll - Allow up to 15s for the watcher to fire, gopls to reanalyze,
|
||||
// and the diagnostic to clear. Re-query the same file (main.go) only.
|
||||
const result = await pollUntil(
|
||||
async () =>
|
||||
(await runCliJson(
|
||||
|
||||
Reference in New Issue
Block a user