-
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/lsp/cache: load modules by dir, not module path
As uncovered in golang/go#59458, loading modules by <modulepath>/... can be incorrect in cases where the package pattern matches more than one module in the module graph. In such cases, it is possible that we will query modules that do not have a corresponding entry in the go.sum file (due to pruning). Fix this by loading <dir>/... for each module root directory. Fixes golang/go#59458 Change-Id: Ia163f4ab18847289941385e4eb9233906a4363c6 Reviewed-on: https://go-review.googlesource.com/c/tools/+/485840 Run-TryBot: Robert Findley <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
- Loading branch information
Showing
6 changed files
with
111 additions
and
19 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
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 |
---|---|---|
|
@@ -179,3 +179,76 @@ func Hello() int { | |
} | ||
}) | ||
} | ||
|
||
// Test for golang/go#59458. With lazy module loading, we may not need | ||
// transitively required modules. | ||
func TestNestedModuleLoading_Issue59458(t *testing.T) { | ||
testenv.NeedsGo1Point(t, 17) // needs lazy module loading | ||
|
||
// In this test, module b.com/nested requires b.com/other, which in turn | ||
// requires b.com, but b.com/nested does not reach b.com through the package | ||
// graph. Therefore, b.com/nested does not need b.com on 1.17 and later, | ||
// thanks to graph pruning. | ||
// | ||
// We verify that we can load b.com/nested successfully. Previously, we | ||
// couldn't, because loading the pattern b.com/nested/... matched the module | ||
// b.com, which exists in the module graph but does not have a go.sum entry. | ||
|
||
const proxy = ` | ||
-- [email protected]/go.mod -- | ||
module b.com | ||
go 1.18 | ||
-- [email protected]/b/b.go -- | ||
package b | ||
func Hello() {} | ||
-- b.com/[email protected]/go.mod -- | ||
module b.com/other | ||
go 1.18 | ||
require b.com v1.2.3 | ||
-- b.com/[email protected]/go.sun -- | ||
b.com v1.2.3 h1:AGjCxWRJLUuJiZ21IUTByr9buoa6+B6Qh5LFhVLKpn4= | ||
-- b.com/[email protected]/bar/bar.go -- | ||
package bar | ||
import "b.com/b" | ||
func _() { | ||
b.Hello() | ||
} | ||
-- b.com/[email protected]/foo/foo.go -- | ||
package foo | ||
const Foo = 0 | ||
` | ||
|
||
const files = ` | ||
-- go.mod -- | ||
module b.com/nested | ||
go 1.18 | ||
require b.com/other v1.4.6 | ||
-- go.sum -- | ||
b.com/other v1.4.6 h1:pHXSzGsk6DamYXp9uRdDB9A/ZQqAN9it+JudU0sBf94= | ||
b.com/other v1.4.6/go.mod h1:T0TYuGdAHw4p/l0+1P/yhhYHfZRia7PaadNVDu58OWM= | ||
-- nested.go -- | ||
package nested | ||
import "b.com/other/foo" | ||
const C = foo.Foo | ||
` | ||
WithOptions( | ||
ProxyFiles(proxy), | ||
).Run(t, files, func(t *testing.T, env *Env) { | ||
env.OnceMet( | ||
InitialWorkspaceLoad, | ||
NoDiagnostics(), | ||
) | ||
}) | ||
} |