| @@ -111,6 +111,27 @@ func (f *fakeServer) awaitDoc(t *testing.T, u uri.URI, version int32) string { |
| 111 | } | 111 | } |
| 112 | } | 112 | } |
| 113 | | 113 | |
| | 114 | +// awaitPublication waits until the client has received the server's first |
| | 115 | +// publication for path. |
| | 116 | +// |
| | 117 | +// The fake publishes on didOpen from a goroutine, so the publication for a |
| | 118 | +// file opened by an earlier call can still be in flight when the next call |
| | 119 | +// starts. A Diagnostics call that reads its "before" counter in that window |
| | 120 | +// sees the late publication as fresh and drops the "(as last published)" |
| | 121 | +// label — correct behaviour, but not the case the test means to check. It |
| | 122 | +// failed that way on a GitHub runner (2026-10-16). |
| | 123 | +func awaitPublication(t *testing.T, c *Client, path string) { |
| | 124 | + t.Helper() |
| | 125 | + s, err := c.serverFor(context.Background(), path) |
| | 126 | + if err != nil { |
| | 127 | + t.Fatal(err) |
| | 128 | + } |
| | 129 | + fresh, err := s.waitPublication(context.Background(), uri.File(mustAbs(path)), 0, 2*time.Second) |
| | 130 | + if err != nil || !fresh { |
| | 131 | + t.Fatalf("no publication received for %s: %v", path, err) |
| | 132 | + } |
| | 133 | +} |
| | 134 | + |
| 114 | func (f *fakeServer) Definition(_ context.Context, p *protocol.DefinitionParams) (protocol.DefinitionResult, error) { | 135 | func (f *fakeServer) Definition(_ context.Context, p *protocol.DefinitionParams) (protocol.DefinitionResult, error) { |
| 115 | return protocol.LocationSlice{{URI: p.TextDocument.URI, Range: span(2, 5, 2, 10)}}, nil | 136 | return protocol.LocationSlice{{URI: p.TextDocument.URI, Range: span(2, 5, 2, 10)}}, nil |
| 116 | } | 137 | } |
| @@ -205,6 +226,7 @@ func TestOperationsOverAFakeServer(t *testing.T) { |
| 205 | } | 226 | } |
| 206 | // main.go was opened by the calls above and has not changed since: no | 227 | // main.go was opened by the calls above and has not changed since: no |
| 207 | // new publication comes, the last one is reported as such. | 228 | // new publication comes, the last one is reported as such. |
| | 229 | + awaitPublication(t, c, "main.go") |
| 208 | got, err = c.Diagnostics(ctx, "main.go") | 230 | got, err = c.Diagnostics(ctx, "main.go") |
| 209 | if err != nil || got != "1 diagnostic(s) in main.go (as last published):\nwarning main.go:3:6 unused function [fake]" { | 231 | if err != nil || got != "1 diagnostic(s) in main.go (as last published):\nwarning main.go:3:6 unused function [fake]" { |
| 210 | t.Errorf("diagnostics on an open file: %q, %v", got, err) | 232 | t.Errorf("diagnostics on an open file: %q, %v", got, err) |