-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gopls/internal/cache: don't create Views for vendored modules
We should not create Views for vendored modules, just as we don't create Views for modules in the module cache. With this change, gopls behaves similarly to gopls@v0.14.2 when navigating around the Kubernetes repo. Also add some test coverage that vendored packages are not workspace packages. Fixes golang/go#65830 Change-Id: If9883dc9616774952bd49c395e1c0d37ad3c2a6a Reviewed-on: https://go-review.googlesource.com/c/tools/+/565458 Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
- Loading branch information
Showing
5 changed files
with
136 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2024 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package workspace | ||
|
||
import ( | ||
"testing" | ||
|
||
. "golang.org/x/tools/gopls/internal/test/integration" | ||
) | ||
|
||
func TestWorkspacePackagesExcludesVendor(t *testing.T) { | ||
// This test verifies that packages in the vendor directory are not workspace | ||
// packages. This would be an easy mistake for gopls to make, since mod | ||
// vendoring excludes go.mod files, and therefore the nearest go.mod file for | ||
// vendored packages is often the workspace mod file. | ||
const proxy = ` | ||
-- other.com/b@v1.0.0/go.mod -- | ||
module other.com/b | ||
go 1.18 | ||
-- other.com/b@v1.0.0/b.go -- | ||
package b | ||
type B int | ||
func _() { | ||
var V int // unused | ||
} | ||
` | ||
const src = ` | ||
-- go.mod -- | ||
module example.com/a | ||
go 1.14 | ||
require other.com/b v1.0.0 | ||
-- go.sum -- | ||
other.com/b v1.0.0 h1:ct1+0RPozzMvA2rSYnVvIfr/GDHcd7oVnw147okdi3g= | ||
other.com/b v1.0.0/go.mod h1:bfTSZo/4ZtAQJWBYScopwW6n9Ctfsl2mi8nXsqjDXR8= | ||
-- a.go -- | ||
package a | ||
import "other.com/b" | ||
var _ b.B | ||
` | ||
WithOptions( | ||
ProxyFiles(proxy), | ||
Modes(Default), | ||
).Run(t, src, func(t *testing.T, env *Env) { | ||
env.RunGoCommand("mod", "vendor") | ||
// Uncomment for updated go.sum contents. | ||
// env.DumpGoSum(".") | ||
env.OpenFile("a.go") | ||
env.AfterChange( | ||
NoDiagnostics(), // as b is not a workspace package | ||
) | ||
env.GoToDefinition(env.RegexpSearch("a.go", `b\.(B)`)) | ||
env.AfterChange( | ||
Diagnostics(env.AtRegexp("vendor/other.com/b/b.go", "V"), WithMessage("not used")), | ||
) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters