Skip to content

Commit 08bd728

Browse files
committed
gopls/internal/test/integration: add a test for an inner go.work file
Add a test to verify that gopls now does the right thing in the scenario described by golang/go#63917, where the users has a go.work file inside a Go module. Gopls now behaves consistently with the go command. Fixes golang/go#63917 Change-Id: I0c9d251477e7403b4f2b75f0333e991a98c82ba4 Reviewed-on: https://go-review.googlesource.com/c/tools/+/562015 Reviewed-by: Hyang-Ah Hana Kim <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent aee2e76 commit 08bd728

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

gopls/internal/test/integration/workspace/workspace_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,51 @@ use (
818818
})
819819
}
820820

821+
func TestInnerGoWork(t *testing.T) {
822+
// This test checks that gopls honors a go.work file defined
823+
// inside a go module (golang/go#63917).
824+
const workspace = `
825+
-- go.mod --
826+
module a.com
827+
828+
require b.com v1.2.3
829+
-- a/go.work --
830+
go 1.18
831+
832+
use (
833+
..
834+
../b
835+
)
836+
-- a/a.go --
837+
package a
838+
839+
import "b.com/b"
840+
841+
var _ = b.B
842+
-- b/go.mod --
843+
module b.com/b
844+
845+
-- b/b.go --
846+
package b
847+
848+
const B = 0
849+
`
850+
WithOptions(
851+
// This doesn't work if we open the outer module. I'm not sure it should,
852+
// since the go.work file does not apply to the entire module, just a
853+
// subdirectory.
854+
WorkspaceFolders("a"),
855+
).Run(t, workspace, func(t *testing.T, env *Env) {
856+
env.OpenFile("a/a.go")
857+
loc := env.GoToDefinition(env.RegexpSearch("a/a.go", "b.(B)"))
858+
got := env.Sandbox.Workdir.URIToPath(loc.URI)
859+
want := "b/b.go"
860+
if got != want {
861+
t.Errorf("Definition(b.B): got %q, want %q", got, want)
862+
}
863+
})
864+
}
865+
821866
func TestNonWorkspaceFileCreation(t *testing.T) {
822867
const files = `
823868
-- work/go.mod --

0 commit comments

Comments
 (0)