golang.org/x/tools/gopls@v0.15.3/internal/test/integration/workspace/vendor_test.go (about) 1 // Copyright 2024 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package workspace 6 7 import ( 8 "testing" 9 10 . "golang.org/x/tools/gopls/internal/test/integration" 11 ) 12 13 func TestWorkspacePackagesExcludesVendor(t *testing.T) { 14 // This test verifies that packages in the vendor directory are not workspace 15 // packages. This would be an easy mistake for gopls to make, since mod 16 // vendoring excludes go.mod files, and therefore the nearest go.mod file for 17 // vendored packages is often the workspace mod file. 18 const proxy = ` 19 -- other.com/b@v1.0.0/go.mod -- 20 module other.com/b 21 22 go 1.18 23 24 -- other.com/b@v1.0.0/b.go -- 25 package b 26 27 type B int 28 29 func _() { 30 var V int // unused 31 } 32 ` 33 const src = ` 34 -- go.mod -- 35 module example.com/a 36 go 1.14 37 require other.com/b v1.0.0 38 39 -- go.sum -- 40 other.com/b v1.0.0 h1:ct1+0RPozzMvA2rSYnVvIfr/GDHcd7oVnw147okdi3g= 41 other.com/b v1.0.0/go.mod h1:bfTSZo/4ZtAQJWBYScopwW6n9Ctfsl2mi8nXsqjDXR8= 42 43 -- a.go -- 44 package a 45 46 import "other.com/b" 47 48 var _ b.B 49 50 ` 51 WithOptions( 52 ProxyFiles(proxy), 53 Modes(Default), 54 ).Run(t, src, func(t *testing.T, env *Env) { 55 env.RunGoCommand("mod", "vendor") 56 // Uncomment for updated go.sum contents. 57 // env.DumpGoSum(".") 58 env.OpenFile("a.go") 59 env.AfterChange( 60 NoDiagnostics(), // as b is not a workspace package 61 ) 62 env.GoToDefinition(env.RegexpSearch("a.go", `b\.(B)`)) 63 env.AfterChange( 64 Diagnostics(env.AtRegexp("vendor/other.com/b/b.go", "V"), WithMessage("not used")), 65 ) 66 }) 67 }