aboutsummaryrefslogtreecommitdiff
path: root/gopls/internal/lsp/testdata/signature
diff options
context:
space:
mode:
Diffstat (limited to 'gopls/internal/lsp/testdata/signature')
-rw-r--r--gopls/internal/lsp/testdata/signature/signature.go85
-rw-r--r--gopls/internal/lsp/testdata/signature/signature.go.golden53
-rw-r--r--gopls/internal/lsp/testdata/signature/signature2.go.golden3
-rw-r--r--gopls/internal/lsp/testdata/signature/signature2.go.in5
-rw-r--r--gopls/internal/lsp/testdata/signature/signature3.go.golden3
-rw-r--r--gopls/internal/lsp/testdata/signature/signature3.go.in5
-rw-r--r--gopls/internal/lsp/testdata/signature/signature_test.go13
-rw-r--r--gopls/internal/lsp/testdata/signature/signature_test.go.golden9
8 files changed, 176 insertions, 0 deletions
diff --git a/gopls/internal/lsp/testdata/signature/signature.go b/gopls/internal/lsp/testdata/signature/signature.go
new file mode 100644
index 000000000..4e2b12bc4
--- /dev/null
+++ b/gopls/internal/lsp/testdata/signature/signature.go
@@ -0,0 +1,85 @@
+// Package signature has tests for signature help.
+package signature
+
+import (
+ "bytes"
+ "encoding/json"
+ "math/big"
+)
+
+func Foo(a string, b int) (c bool) {
+ return
+}
+
+func Bar(float64, ...byte) {
+}
+
+type myStruct struct{}
+
+func (*myStruct) foo(e *json.Decoder) (*big.Int, error) {
+ return nil, nil
+}
+
+type MyType struct{}
+
+type MyFunc func(foo int) string
+
+type Alias = int
+type OtherAlias = int
+type StringAlias = string
+
+func AliasSlice(a []*Alias) (b Alias) { return 0 }
+func AliasMap(a map[*Alias]StringAlias) (b, c map[*Alias]StringAlias) { return nil, nil }
+func OtherAliasMap(a, b map[Alias]OtherAlias) map[Alias]OtherAlias { return nil }
+
+func Qux() {
+ Foo("foo", 123) //@signature("(", "Foo(a string, b int) (c bool)", 0)
+ Foo("foo", 123) //@signature("123", "Foo(a string, b int) (c bool)", 1)
+ Foo("foo", 123) //@signature(",", "Foo(a string, b int) (c bool)", 0)
+ Foo("foo", 123) //@signature(" 1", "Foo(a string, b int) (c bool)", 1)
+ Foo("foo", 123) //@signature(")", "Foo(a string, b int) (c bool)", 1)
+
+ Bar(13.37, 0x13) //@signature("13.37", "Bar(float64, ...byte)", 0)
+ Bar(13.37, 0x37) //@signature("0x37", "Bar(float64, ...byte)", 1)
+ Bar(13.37, 1, 2, 3, 4) //@signature("4", "Bar(float64, ...byte)", 1)
+
+ fn := func(hi, there string) func(i int) rune {
+ return func(int) rune { return 0 }
+ }
+
+ fn("hi", "there") //@signature("hi", "", 0)
+ fn("hi", "there") //@signature(",", "fn(hi string, there string) func(i int) rune", 0)
+ fn("hi", "there")(1) //@signature("1", "func(i int) rune", 0)
+
+ fnPtr := &fn
+ (*fnPtr)("hi", "there") //@signature(",", "func(hi string, there string) func(i int) rune", 0)
+
+ var fnIntf interface{} = Foo
+ fnIntf.(func(string, int) bool)("hi", 123) //@signature("123", "func(string, int) bool", 1)
+
+ (&bytes.Buffer{}).Next(2) //@signature("2", "Next(n int) []byte", 0)
+
+ myFunc := MyFunc(func(n int) string { return "" })
+ myFunc(123) //@signature("123", "myFunc(foo int) string", 0)
+
+ var ms myStruct
+ ms.foo(nil) //@signature("nil", "foo(e *json.Decoder) (*big.Int, error)", 0)
+
+ _ = make([]int, 1, 2) //@signature("2", "make(t Type, size ...int) Type", 1)
+
+ Foo(myFunc(123), 456) //@signature("myFunc", "Foo(a string, b int) (c bool)", 0)
+ Foo(myFunc(123), 456) //@signature("123", "myFunc(foo int) string", 0)
+
+ panic("oops!") //@signature(")", "panic(v interface{})", 0)
+ println("hello", "world") //@signature(",", "println(args ...Type)", 0)
+
+ Hello(func() {
+ //@signature("//", "", 0)
+ })
+
+ AliasSlice() //@signature(")", "AliasSlice(a []*Alias) (b Alias)", 0)
+ AliasMap() //@signature(")", "AliasMap(a map[*Alias]StringAlias) (b map[*Alias]StringAlias, c map[*Alias]StringAlias)", 0)
+ OtherAliasMap() //@signature(")", "OtherAliasMap(a map[Alias]OtherAlias, b map[Alias]OtherAlias) map[Alias]OtherAlias", 0)
+}
+
+func Hello(func()) {}
diff --git a/gopls/internal/lsp/testdata/signature/signature.go.golden b/gopls/internal/lsp/testdata/signature/signature.go.golden
new file mode 100644
index 000000000..90a4facf9
--- /dev/null
+++ b/gopls/internal/lsp/testdata/signature/signature.go.golden
@@ -0,0 +1,53 @@
+-- AliasMap(a map[*Alias]StringAlias) (b map[*Alias]StringAlias, c map[*Alias]StringAlias)-signature --
+AliasMap(a map[*Alias]StringAlias) (b map[*Alias]StringAlias, c map[*Alias]StringAlias)
+
+-- AliasSlice(a []*Alias) (b Alias)-signature --
+AliasSlice(a []*Alias) (b Alias)
+
+-- Bar(float64, ...byte)-signature --
+Bar(float64, ...byte)
+
+-- Foo(a string, b int) (c bool)-signature --
+Foo(a string, b int) (c bool)
+
+-- Next(n int) []byte-signature --
+Next(n int) []byte
+
+Next returns a slice containing the next n bytes from the buffer, advancing the buffer as if the bytes had been returned by Read.
+
+-- OtherAliasMap(a map[Alias]OtherAlias, b map[Alias]OtherAlias) map[Alias]OtherAlias-signature --
+OtherAliasMap(a map[Alias]OtherAlias, b map[Alias]OtherAlias) map[Alias]OtherAlias
+
+-- fn(hi string, there string) func(i int) rune-signature --
+fn(hi string, there string) func(i int) rune
+
+-- foo(e *json.Decoder) (*big.Int, error)-signature --
+foo(e *json.Decoder) (*big.Int, error)
+
+-- func(hi string, there string) func(i int) rune-signature --
+func(hi string, there string) func(i int) rune
+
+-- func(i int) rune-signature --
+func(i int) rune
+
+-- func(string, int) bool-signature --
+func(string, int) bool
+
+-- make(t Type, size ...int) Type-signature --
+make(t Type, size ...int) Type
+
+The make built-in function allocates and initializes an object of type slice, map, or chan (only).
+
+-- myFunc(foo int) string-signature --
+myFunc(foo int) string
+
+-- panic(v interface{})-signature --
+panic(v any)
+
+The panic built-in function stops normal execution of the current goroutine.
+
+-- println(args ...Type)-signature --
+println(args ...Type)
+
+The println built-in function formats its arguments in an implementation-specific way and writes the result to standard error.
+
diff --git a/gopls/internal/lsp/testdata/signature/signature2.go.golden b/gopls/internal/lsp/testdata/signature/signature2.go.golden
new file mode 100644
index 000000000..e8102584f
--- /dev/null
+++ b/gopls/internal/lsp/testdata/signature/signature2.go.golden
@@ -0,0 +1,3 @@
+-- Foo(a string, b int) (c bool)-signature --
+Foo(a string, b int) (c bool)
+
diff --git a/gopls/internal/lsp/testdata/signature/signature2.go.in b/gopls/internal/lsp/testdata/signature/signature2.go.in
new file mode 100644
index 000000000..16355ffc0
--- /dev/null
+++ b/gopls/internal/lsp/testdata/signature/signature2.go.in
@@ -0,0 +1,5 @@
+package signature
+
+func _() {
+ Foo(//@signature("//", "Foo(a string, b int) (c bool)", 0)
+}
diff --git a/gopls/internal/lsp/testdata/signature/signature3.go.golden b/gopls/internal/lsp/testdata/signature/signature3.go.golden
new file mode 100644
index 000000000..e8102584f
--- /dev/null
+++ b/gopls/internal/lsp/testdata/signature/signature3.go.golden
@@ -0,0 +1,3 @@
+-- Foo(a string, b int) (c bool)-signature --
+Foo(a string, b int) (c bool)
+
diff --git a/gopls/internal/lsp/testdata/signature/signature3.go.in b/gopls/internal/lsp/testdata/signature/signature3.go.in
new file mode 100644
index 000000000..032be1304
--- /dev/null
+++ b/gopls/internal/lsp/testdata/signature/signature3.go.in
@@ -0,0 +1,5 @@
+package signature
+
+func _() {
+ Foo("hello",//@signature("//", "Foo(a string, b int) (c bool)", 1)
+} \ No newline at end of file
diff --git a/gopls/internal/lsp/testdata/signature/signature_test.go b/gopls/internal/lsp/testdata/signature/signature_test.go
new file mode 100644
index 000000000..500247dbd
--- /dev/null
+++ b/gopls/internal/lsp/testdata/signature/signature_test.go
@@ -0,0 +1,13 @@
+package signature_test
+
+import (
+ "testing"
+
+ sig "golang.org/lsptests/signature"
+)
+
+func TestSignature(t *testing.T) {
+ sig.AliasSlice() //@signature(")", "AliasSlice(a []*sig.Alias) (b sig.Alias)", 0)
+ sig.AliasMap() //@signature(")", "AliasMap(a map[*sig.Alias]sig.StringAlias) (b map[*sig.Alias]sig.StringAlias, c map[*sig.Alias]sig.StringAlias)", 0)
+ sig.OtherAliasMap() //@signature(")", "OtherAliasMap(a map[sig.Alias]sig.OtherAlias, b map[sig.Alias]sig.OtherAlias) map[sig.Alias]sig.OtherAlias", 0)
+}
diff --git a/gopls/internal/lsp/testdata/signature/signature_test.go.golden b/gopls/internal/lsp/testdata/signature/signature_test.go.golden
new file mode 100644
index 000000000..9e6561ac5
--- /dev/null
+++ b/gopls/internal/lsp/testdata/signature/signature_test.go.golden
@@ -0,0 +1,9 @@
+-- AliasMap(a map[*sig.Alias]sig.StringAlias) (b map[*sig.Alias]sig.StringAlias, c map[*sig.Alias]sig.StringAlias)-signature --
+AliasMap(a map[*sig.Alias]sig.StringAlias) (b map[*sig.Alias]sig.StringAlias, c map[*sig.Alias]sig.StringAlias)
+
+-- AliasSlice(a []*sig.Alias) (b sig.Alias)-signature --
+AliasSlice(a []*sig.Alias) (b sig.Alias)
+
+-- OtherAliasMap(a map[sig.Alias]sig.OtherAlias, b map[sig.Alias]sig.OtherAlias) map[sig.Alias]sig.OtherAlias-signature --
+OtherAliasMap(a map[sig.Alias]sig.OtherAlias, b map[sig.Alias]sig.OtherAlias) map[sig.Alias]sig.OtherAlias
+