diff --git a/gopls/internal/goxls/testdata/overload/c/add.gop b/gopls/internal/goxls/testdata/overload/c/add.gop new file mode 100644 index 00000000000..1ccda63f069 --- /dev/null +++ b/gopls/internal/goxls/testdata/overload/c/add.gop @@ -0,0 +1,10 @@ +package c + +func Add = ( + func(a, b int) int { + return a + b + } + func(a, b string) string { + return a + b + } +) diff --git a/gopls/internal/goxls/testdata/overload/c/gop_autogen.go b/gopls/internal/goxls/testdata/overload/c/gop_autogen.go new file mode 100644 index 00000000000..111e6a11eab --- /dev/null +++ b/gopls/internal/goxls/testdata/overload/c/gop_autogen.go @@ -0,0 +1,3 @@ +// Code generated by gop (Go+); DO NOT EDIT. + +package c diff --git a/gopls/internal/goxls/testdata/overload/c/method.gop b/gopls/internal/goxls/testdata/overload/c/method.gop new file mode 100644 index 00000000000..e53f489ed90 --- /dev/null +++ b/gopls/internal/goxls/testdata/overload/c/method.gop @@ -0,0 +1,19 @@ +package c + +type Foo struct { +} + +func (a *Foo) MulInt(b int) *Foo { //@mark(c_foo_mulInt,"MulInt") + println "mulInt" + return a +} + +func (a *Foo) MulFoo(b *Foo) *Foo { //@mark(c_foo_mulFoo,"MulFoo") + println "mulFoo" + return a +} + +func (Foo).Mul = ( + (Foo).MulInt + (Foo).MulFoo +) diff --git a/gopls/internal/goxls/testdata/overload/c/mul.gop b/gopls/internal/goxls/testdata/overload/c/mul.gop new file mode 100644 index 00000000000..8ca7de64ea6 --- /dev/null +++ b/gopls/internal/goxls/testdata/overload/c/mul.gop @@ -0,0 +1,14 @@ +package c + +func MulInt(a, b int) int { //@mark(c_mulInt,"MulInt") + return a * b +} + +func MulFloat(a, b float64) float64 { //@mark(c_mulFloat,"MulFloat") + return a * b +} + +func Mul = ( + MulInt + MulFloat +) diff --git a/gopls/internal/goxls/testdata/overload/d/utils.go b/gopls/internal/goxls/testdata/overload/d/utils.go new file mode 100644 index 00000000000..e466ad0b3f9 --- /dev/null +++ b/gopls/internal/goxls/testdata/overload/d/utils.go @@ -0,0 +1,33 @@ +package d + +const GopPackage = true + +type Foo struct { +} + +const Gopo_Foo_Mul = ".MulInt,.MulFoo" +const Gopo_Mul = "MulInt,MulFloat" + +func Add__0(a int, b int) int { //@mark(d_add__0,"Add__0") + return a + b +} + +func Add__1(a string, b string) string { //@mark(d_add__1,"Add__1") + return a + b +} + +func (a *Foo) MulInt(b int) *Foo { //@mark(d_foo_mulInt,"MulInt") + return a +} + +func (a *Foo) MulFoo(b *Foo) *Foo { //@mark(d_foo_mulFoo,"MulFoo") + return a +} + +func MulInt(a int, b int) int { //@mark(d_mulInt,"MulInt") + return a * b +} + +func MulFloat(a float64, b float64) float64 { //@mark(d_mulFloat,"MulFloat") + return a * b +} diff --git a/gopls/internal/goxls/testdata/overload/gop_autogen.go b/gopls/internal/goxls/testdata/overload/gop_autogen.go index 26751cdc203..79cb0375e98 100644 --- a/gopls/internal/goxls/testdata/overload/gop_autogen.go +++ b/gopls/internal/goxls/testdata/overload/gop_autogen.go @@ -5,4 +5,6 @@ package main import ( "golang.org/lsptests/overload/a" "golang.org/lsptests/overload/b" + "golang.org/lsptests/overload/c" + "golang.org/lsptests/overload/d" ) diff --git a/gopls/internal/goxls/testdata/overload/overload.gop b/gopls/internal/goxls/testdata/overload/overload.gop index 32a305086a3..ccc0faec882 100644 --- a/gopls/internal/goxls/testdata/overload/overload.gop +++ b/gopls/internal/goxls/testdata/overload/overload.gop @@ -1,6 +1,8 @@ import ( "golang.org/lsptests/overload/a" "golang.org/lsptests/overload/b" + "golang.org/lsptests/overload/c" + "golang.org/lsptests/overload/d" ) Demo //@godef("Demo",Demo__0) @@ -30,3 +32,23 @@ b.demo "hello" //@godef("demo",b_demo__3) var n2 b.N n2.add 100 //@godef("add",b_add__0) n2.add "hello" //@godef("add",b_add__1) + +c.mul 100, 200 //@godef("mul",c_mulInt) +c.mul 100.1, 200 //@godef("mul",c_mulFloat) + +c.add 100, 200 +c.add "hello", "world" + +var foo c.Foo +foo.mul 100 //@godef("mul",c_foo_mulInt) +foo.mul new(c.Foo) //@godef("mul",c_foo_mulFoo) + +d.mul 100, 200 //@godef("mul",d_mulInt) +d.mul 100.1, 200 //@godef("mul",d_mulFloat) + +d.add 100, 200 //@godef("add",d_add__0) +d.add "hello", "world" //@godef("add",d_add__1) + +var foo2 d.Foo +foo2.mul 100 //@godef("mul",d_foo_mulInt) +foo2.mul new(d.Foo) //@godef("mul",d_foo_mulFoo) diff --git a/gopls/internal/goxls/testdata/overload/overload.gop.golden b/gopls/internal/goxls/testdata/overload/overload.gop.golden index c190441b1a6..6f4d4cf0639 100644 --- a/gopls/internal/goxls/testdata/overload/overload.gop.golden +++ b/gopls/internal/goxls/testdata/overload/overload.gop.golden @@ -108,6 +108,102 @@ func b.GopDemo() ``` [`b.GopDemo` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/b#GopDemo) +-- c_add-hoverdef -- +```go +func c.Add__1(a string, b string) string +``` + +[`c.Add__1` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/c#Add__1) +-- c_add__0-hoverdef -- +```go +func c.Add__0(a int, b int) int +``` + +[`c.Add__0` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/c#Add__0) +-- c_foo_mulFoo-hoverdef -- +```go +func (*c.Foo).MulFoo(b *c.Foo) *c.Foo +``` + +[`(c.Foo).MulFoo` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/c#Foo.MulFoo) +-- c_foo_mulInt-hoverdef -- +```go +func (*c.Foo).MulInt(b int) *c.Foo +``` + +[`(c.Foo).MulInt` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/c#Foo.MulInt) +-- c_foo_mul__0-hoverdef -- +```go +func (*c.Foo).MulInt(b int) *c.Foo +``` + +[`(c.Foo).MulInt` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/c#Foo.MulInt) +-- c_foo_mul__1-hoverdef -- +```go +func (*c.Foo).MulFoo(b *c.Foo) *c.Foo +``` + +[`(c.Foo).MulFoo` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/c#Foo.MulFoo) +-- c_mulFloat-hoverdef -- +```go +func c.MulFloat(a float64, b float64) float64 +``` + +[`c.MulFloat` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/c#MulFloat) +-- c_mulInt-hoverdef -- +```go +func c.MulInt(a int, b int) int +``` + +[`c.MulInt` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/c#MulInt) +-- c_mul__0-hoverdef -- +```go +func c.MulInt(a int, b int) int +``` + +[`c.MulInt` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/c#MulInt) +-- c_mul__1-hoverdef -- +```go +func c.MulFloat(a float64, b float64) float64 +``` + +[`c.MulFloat` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/c#MulFloat) +-- d_add__0-hoverdef -- +```go +func d.Add__0(a int, b int) int +``` + +[`d.Add__0` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/d#Add__0) +-- d_add__1-hoverdef -- +```go +func d.Add__1(a string, b string) string +``` + +[`d.Add__1` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/d#Add__1) +-- d_foo_mulFoo-hoverdef -- +```go +func (*d.Foo).MulFoo(b *d.Foo) *d.Foo +``` + +[`(d.Foo).MulFoo` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/d#Foo.MulFoo) +-- d_foo_mulInt-hoverdef -- +```go +func (*d.Foo).MulInt(b int) *d.Foo +``` + +[`(d.Foo).MulInt` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/d#Foo.MulInt) +-- d_mulFloat-hoverdef -- +```go +func d.MulFloat(a float64, b float64) float64 +``` + +[`d.MulFloat` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/d#MulFloat) +-- d_mulInt-hoverdef -- +```go +func d.MulInt(a int, b int) int +``` + +[`d.MulInt` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/d#MulInt) -- pkg_add__0-hoverdef -- ```go func (*pkg.N).Add__0(a int) diff --git a/gopls/internal/goxls/testdata/overload/overload_unimport.gop.in b/gopls/internal/goxls/testdata/overload/overload_unimport.gop.in new file mode 100644 index 00000000000..502f6aeb9a0 --- /dev/null +++ b/gopls/internal/goxls/testdata/overload/overload_unimport.gop.in @@ -0,0 +1,24 @@ +func _() { + c.add //@unimported("add", c_add_unimported) + c.mul //@unimported("mul", c_mul_unimported) + c.mulInt //@unimported("mulInt", c_mulInt_unimported) + c.MulInt //@unimported("MulInt", c_MulInt_unimported) +} + +func _() { + d.add //@unimported("add", d_add_unimported) + d.mul //@unimported("mul", d_mul_unimported) + d.mulInt //@unimported("mulInt", d_mulInt_unimported) + d.MulInt //@unimported("MulInt", d_MulInt_unimported) +} + + +/* c.add */ //@item(c_add_unimported, "add", "Go+ overload func\n\nfunc (from \"golang.org/lsptests/overload/c\")", "func") +/* c.mul */ //@item(c_mul_unimported, "mul", "Go+ overload func\n\nfunc (from \"golang.org/lsptests/overload/c\")", "func") +/* c.mulInt */ //@item(c_mulInt_unimported, "mulInt", "Go+ alias func\n\nfunc (from \"golang.org/lsptests/overload/c\")", "func") +/* c.MulInt */ //@item(c_MulInt_unimported, "MulInt", "func (from \"golang.org/lsptests/overload/c\")", "func") + +/* d.add */ //@item(d_add_unimported, "add", "Go+ overload func\n\nfunc (from \"golang.org/lsptests/overload/d\")", "func") +/* d.mul */ //@item(d_mul_unimported, "mul", "Go+ overload func\n\nfunc (from \"golang.org/lsptests/overload/d\")", "func") +/* d.mulInt */ //@item(d_mulInt_unimported, "mulInt", "Go+ alias func\n\nfunc (from \"golang.org/lsptests/overload/d\")", "func") +/* d.MulInt */ //@item(d_MulInt_unimported, "MulInt", "func (from \"golang.org/lsptests/overload/d\")", "func") diff --git a/gopls/internal/goxls/testdata/summary.txt.golden b/gopls/internal/goxls/testdata/summary.txt.golden index 03b9aba21ba..7ee2de39051 100644 --- a/gopls/internal/goxls/testdata/summary.txt.golden +++ b/gopls/internal/goxls/testdata/summary.txt.golden @@ -3,7 +3,7 @@ CallHierarchyCount = 0 CodeLensCount = 4 CompletionsCount = 36 CompletionSnippetCount = 12 -UnimportedCompletionsCount = 0 +UnimportedCompletionsCount = 8 DeepCompletionsCount = 0 FuzzyCompletionsCount = 1 RankedCompletionsCount = 15 @@ -13,7 +13,7 @@ FoldingRangesCount = 0 SemanticTokenCount = 0 SuggestedFixCount = 0 MethodExtractionCount = 0 -DefinitionsCount = 23 +DefinitionsCount = 33 TypeDefinitionsCount = 2 HighlightsCount = 0 InlayHintsCount = 0 diff --git a/gopls/internal/goxls/testdata/summary_go1.18.txt.golden b/gopls/internal/goxls/testdata/summary_go1.18.txt.golden index 03b9aba21ba..7ee2de39051 100644 --- a/gopls/internal/goxls/testdata/summary_go1.18.txt.golden +++ b/gopls/internal/goxls/testdata/summary_go1.18.txt.golden @@ -3,7 +3,7 @@ CallHierarchyCount = 0 CodeLensCount = 4 CompletionsCount = 36 CompletionSnippetCount = 12 -UnimportedCompletionsCount = 0 +UnimportedCompletionsCount = 8 DeepCompletionsCount = 0 FuzzyCompletionsCount = 1 RankedCompletionsCount = 15 @@ -13,7 +13,7 @@ FoldingRangesCount = 0 SemanticTokenCount = 0 SuggestedFixCount = 0 MethodExtractionCount = 0 -DefinitionsCount = 23 +DefinitionsCount = 33 TypeDefinitionsCount = 2 HighlightsCount = 0 InlayHintsCount = 0 diff --git a/gopls/internal/goxls/testdata/summary_go1.21.txt.golden b/gopls/internal/goxls/testdata/summary_go1.21.txt.golden index 03b9aba21ba..7ee2de39051 100644 --- a/gopls/internal/goxls/testdata/summary_go1.21.txt.golden +++ b/gopls/internal/goxls/testdata/summary_go1.21.txt.golden @@ -3,7 +3,7 @@ CallHierarchyCount = 0 CodeLensCount = 4 CompletionsCount = 36 CompletionSnippetCount = 12 -UnimportedCompletionsCount = 0 +UnimportedCompletionsCount = 8 DeepCompletionsCount = 0 FuzzyCompletionsCount = 1 RankedCompletionsCount = 15 @@ -13,7 +13,7 @@ FoldingRangesCount = 0 SemanticTokenCount = 0 SuggestedFixCount = 0 MethodExtractionCount = 0 -DefinitionsCount = 23 +DefinitionsCount = 33 TypeDefinitionsCount = 2 HighlightsCount = 0 InlayHintsCount = 0 diff --git a/gopls/internal/goxls/testdata/unimported/export_test.gop b/gopls/internal/goxls/testdata/unimported/export_test.gop deleted file mode 100644 index 707768e1da2..00000000000 --- a/gopls/internal/goxls/testdata/unimported/export_test.gop +++ /dev/null @@ -1,3 +0,0 @@ -package unimported - -var TestExport int //@item(testexport, "TestExport", "var (from \"golang.org/lsptests/unimported\")", "var") diff --git a/gopls/internal/goxls/testdata/unimported/unimported.gop.in b/gopls/internal/goxls/testdata/unimported/unimported.gop.in deleted file mode 100644 index 74d51ffe82a..00000000000 --- a/gopls/internal/goxls/testdata/unimported/unimported.gop.in +++ /dev/null @@ -1,23 +0,0 @@ -package unimported - -func _() { - http //@unimported("p", nethttp) - // container/ring is extremely unlikely to be imported by anything, so shouldn't have type information. - ring.Ring //@unimported("Ring", ringring) - signature.Foo //@unimported("Foo", signaturefoo) - - context.Bac //@unimported(" //", contextBackground) -} - -// Create markers for unimported std lib packages. Only for use by this test. -/* http */ //@item(nethttp, "http", "\"net/http\"", "package") - -/* ring.Ring */ //@item(ringring, "Ring", "(from \"container/ring\")", "var") - -/* signature.Foo */ //@item(signaturefoo, "Foo", "func (from \"golang.org/lsptests/signature\")", "func") - -/* context.Background */ //@item(contextBackground, "Background", "func (from \"context\")", "func") - -// Now that we no longer type-check imported completions, -// we don't expect the context.Background().Err method (see golang/go#58663). -/* context.Background().Err */ //@item(contextBackgroundErr, "Background().Err", "func (from \"context\")", "method") diff --git a/gopls/internal/goxls/testdata/unimported/unimported_cand_type.gop b/gopls/internal/goxls/testdata/unimported/unimported_cand_type.gop deleted file mode 100644 index 554c426a998..00000000000 --- a/gopls/internal/goxls/testdata/unimported/unimported_cand_type.gop +++ /dev/null @@ -1,16 +0,0 @@ -package unimported - -import ( - _ "context" - - "golang.org/lsptests/baz" - _ "golang.org/lsptests/signature" // provide type information for unimported completions in the other file -) - -func _() { - foo.StructFoo{} //@item(litFooStructFoo, "foo.StructFoo{}", "struct{...}", "struct") - - // We get the literal completion for "foo.StructFoo{}" even though we haven't - // imported "foo" yet. - baz.FooStruct = f //@snippet(" //", litFooStructFoo, "foo.StructFoo{$0\\}", "foo.StructFoo{$0\\}") -} diff --git a/gopls/internal/goxls/testdata/unimported/x_test.gop b/gopls/internal/goxls/testdata/unimported/x_test.gop deleted file mode 100644 index 681dcb2536d..00000000000 --- a/gopls/internal/goxls/testdata/unimported/x_test.gop +++ /dev/null @@ -1,9 +0,0 @@ -package unimported_test - -import ( - "testing" -) - -func TestSomething(t *testing.T) { - _ = unimported.TestExport //@unimported("TestExport", testexport) -} diff --git a/gopls/internal/lsp/source/completion/completion_gox.go b/gopls/internal/lsp/source/completion/completion_gox.go index 4c01a547f8e..08489c96e38 100644 --- a/gopls/internal/lsp/source/completion/completion_gox.go +++ b/gopls/internal/lsp/source/completion/completion_gox.go @@ -2471,7 +2471,7 @@ func gopForEachPackageMember(content []byte, f func(tok token.Token, id *ast.Ide break FindType } } - f(token.FUNC, decl.Name, typ, false) + f(token.FUNC, decl.Name, typ, true) } } }