@@ -6,13 +6,15 @@ package misc
6
6
7
7
import (
8
8
"fmt"
9
+ "os"
9
10
"sort"
10
11
"strings"
11
12
"testing"
12
13
13
14
"github.com/google/go-cmp/cmp"
14
15
"golang.org/x/tools/gopls/internal/lsp/protocol"
15
16
. "golang.org/x/tools/gopls/internal/lsp/regtest"
17
+ "golang.org/x/tools/internal/testenv"
16
18
)
17
19
18
20
func TestStdlibReferences (t * testing.T ) {
@@ -288,3 +290,88 @@ func _() {
288
290
}
289
291
})
290
292
}
293
+
294
+ // This is a regression test for Issue #56169, in which interface
295
+ // implementations in vendored modules were not found. The actual fix
296
+ // was the same as for #55995; see TestVendoringInvalidatesMetadata.
297
+ func TestImplementationsInVendor (t * testing.T ) {
298
+ testenv .NeedsGo1Point (t , 14 )
299
+ const proxy = `
300
+ -- other.com/[email protected] /go.mod --
301
+ module other.com/b
302
+ go 1.14
303
+
304
+ -- other.com/[email protected] /b.go --
305
+ package b
306
+ type B int
307
+ func (B) F() {}
308
+ `
309
+ const src = `
310
+ -- go.mod --
311
+ module example.com/a
312
+ go 1.14
313
+ require other.com/b v1.0.0
314
+
315
+ -- go.sum --
316
+ other.com/b v1.0.0 h1:9WyCKS+BLAMRQM0CegP6zqP2beP+ShTbPaARpNY31II=
317
+ other.com/b v1.0.0/go.mod h1:TgHQFucl04oGT+vrUm/liAzukYHNxCwKNkQZEyn3m9g=
318
+
319
+ -- a.go --
320
+ package a
321
+ import "other.com/b"
322
+ type I interface { F() }
323
+ var _ b.B
324
+
325
+ `
326
+ WithOptions (
327
+ ProxyFiles (proxy ),
328
+ Modes (Default ), // fails in 'experimental' mode
329
+ ).Run (t , src , func (t * testing.T , env * Env ) {
330
+ // Enable to debug go.sum mismatch, which may appear as
331
+ // "module lookup disabled by GOPROXY=off", confusingly.
332
+ if false {
333
+ env .DumpGoSum ("." )
334
+ }
335
+
336
+ checkVendor := func (locs []protocol.Location , wantVendor bool ) {
337
+ if len (locs ) != 1 {
338
+ t .Errorf ("got %d locations, want 1" , len (locs ))
339
+ } else if strings .Contains (string (locs [0 ].URI ), "/vendor/" ) != wantVendor {
340
+ t .Errorf ("got location %s, wantVendor=%t" , locs [0 ], wantVendor )
341
+ }
342
+ }
343
+
344
+ env .OpenFile ("a.go" )
345
+ refPos := env .RegexpSearch ("a.go" , "I" ) // find "I" reference
346
+
347
+ // Initially, a.I has one implementation b.B in
348
+ // the module cache, not the vendor tree.
349
+ checkVendor (env .Implementations ("a.go" , refPos ), false )
350
+
351
+ // Run 'go mod vendor' outside the editor.
352
+ if err := env .Sandbox .RunGoCommand (env .Ctx , "." , "mod" , []string {"vendor" }, true ); err != nil {
353
+ t .Fatalf ("go mod vendor: %v" , err )
354
+ }
355
+
356
+ // Synchronize changes to watched files.
357
+ env .Await (env .DoneWithChangeWatchedFiles ())
358
+
359
+ // Now, b.B is found in the vendor tree.
360
+ checkVendor (env .Implementations ("a.go" , refPos ), true )
361
+
362
+ // Delete the vendor tree.
363
+ if err := os .RemoveAll (env .Sandbox .Workdir .AbsPath ("vendor" )); err != nil {
364
+ t .Fatal (err )
365
+ }
366
+ // Notify the server of the deletion.
367
+ if err := env .Sandbox .Workdir .CheckForFileChanges (env .Ctx ); err != nil {
368
+ t .Fatal (err )
369
+ }
370
+
371
+ // Synchronize again.
372
+ env .Await (env .DoneWithChangeWatchedFiles ())
373
+
374
+ // b.B is once again defined in the module cache.
375
+ checkVendor (env .Implementations ("a.go" , refPos ), false )
376
+ })
377
+ }
0 commit comments