diff --git a/gopls/internal/regtest/misc/definition_gox_test.go b/gopls/internal/regtest/misc/definition_gox_test.go index 63a45fc7c0a..00f58323266 100644 --- a/gopls/internal/regtest/misc/definition_gox_test.go +++ b/gopls/internal/regtest/misc/definition_gox_test.go @@ -10,7 +10,7 @@ const overloadDefinition1 = ` -- go.mod -- module mod.com -go 1.21.4 +go 1.19 -- def.gop -- func add = ( func(a, b int) int { @@ -22,6 +22,21 @@ func add = ( ) -- test.gop -- println add(100, 7) +-- gop_autogen.go -- +package main + +import "fmt" + +const _ = true +func add__0(a int, b int) int { + return a + b +} +func add__1(a string, b string) string { + return a + b +} +func main() { + fmt.Println(add__0(100, 7)) +} ` func TestOverloadDefinition1(t *testing.T) { @@ -43,7 +58,7 @@ const overloadDefinition2 = ` -- go.mod -- module mod.com -go 1.21.4 +go 1.19 -- def.gop -- func mulInt(a, b int) int { return a * b @@ -55,10 +70,32 @@ func mulFloat(a, b float64) float64 { func mul = ( mulInt + func(a, b string) string { + return a + b + } mulFloat ) -- test.gop -- println mul(100, 7) +-- gop_autogen.go -- +package main + +import "fmt" + +const _ = true +const Gopo_mul = "mulInt,,mulFloat" +func mulInt(a int, b int) int { + return a * b +} +func mul__1(a string, b string) string { + return a + b +} +func mulFloat(a float64, b float64) float64 { + return a * b +} +func main() { + fmt.Println(mulInt(100, 7)) +} ` func TestOverloadDefinition2(t *testing.T) { @@ -80,7 +117,7 @@ const overloadDefinition3 = ` -- go.mod -- module mod.com -go 1.21.4 +go 1.19 -- def.gop -- type foo struct { } @@ -100,6 +137,27 @@ func (foo).mul = ( -- test.gop -- var a *foo var c = a.mul(100) +-- gop_autogen.go -- +package main + +const _ = true + +type foo struct { +} + +const Gopo_foo_mul = ".mulInt,.mulFoo" +func (a *foo) mulInt(b int) *foo { + return a +} +func (a *foo) mulFoo(b *foo) *foo { + return a +} + +var a *foo +var c = a.mulInt(100) + +func main() { +} ` func TestOverloadDefinition3(t *testing.T) { @@ -121,29 +179,55 @@ const overloadDefinition4 = ` -- go.mod -- module mod.com -go 1.21.4 +go 1.19 -- def.go -- package main -type foo struct { + +const GopPackage = true + +type N struct { } -func (f *foo) Broadcast__0(msg string) bool { - return true +func (m *N) OnKey__0(a string, fn func()) { + fn() +} + +func (m *N) OnKey__1(a string, fn func(key string)) { + fn(a) +} + +func (m *N) OnKey__2(a []string, fn func()) { + fn() } -- test.gop -- -var a *foo -a.Broadcast("hhh") +n := &N{} + +n.onKey("hello", func() { + println("hello world") +}) +-- gop_autogen.go -- +package main + +import "fmt" + +const _ = true +func main() { + n := &N{} + n.OnKey__0("hello", func() { + fmt.Println("hello world") + }) +} ` func TestOverloadDefinition4(t *testing.T) { Run(t, overloadDefinition4, func(t *testing.T, env *Env) { env.OpenFile("test.gop") - loc := env.GoToDefinition(env.RegexpSearch("test.gop", "Broadcast")) + loc := env.GoToDefinition(env.RegexpSearch("test.gop", "onKey")) name := env.Sandbox.Workdir.URIToPath(loc.URI) if want := "def.go"; name != want { t.Errorf("GoToDefinition: got file %q, want %q", name, want) } - if want := env.RegexpSearch("def.go", `Broadcast__0`); loc != want { + if want := env.RegexpSearch("def.go", `OnKey__0`); loc != want { t.Errorf("GoToDefinition: got location %v, want %v", loc, want) } })