Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions gopls/internal/regtest/completion/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,21 +393,45 @@ func _() {
var bbbb1, bbbb2 b
var _ b = bbbb
}

type (
c *d
d *e
e **c
)

func _() {
var (
xxxxc c
xxxxd d
xxxxe e
)

var _ c = xxxx
var _ d = xxxx
var _ e = xxxx
}
`

Run(t, files, func(t *testing.T, env *Env) {
env.OpenFile("main.go")

completions := env.Completion("main.go", env.RegexpSearch("main.go", `var _ a = aaaa()`))
diff := compareCompletionResults([]string{"aaaa1", "aaaa2"}, completions.Items)
if diff != "" {
t.Fatal(diff)
tests := []struct {
re string
want []string
}{
{`var _ a = aaaa()`, []string{"aaaa1", "aaaa2"}},
{`var _ b = bbbb()`, []string{"bbbb1", "bbbb2"}},
{`var _ c = xxxx()`, []string{"***xxxxd", "**xxxxe", "xxxxc"}},
{`var _ d = xxxx()`, []string{"***xxxxe", "*xxxxc", "xxxxd"}},
{`var _ e = xxxx()`, []string{"**xxxxc", "*xxxxd", "xxxxe"}},
}

completions = env.Completion("main.go", env.RegexpSearch("main.go", `var _ b = bbbb()`))
diff = compareCompletionResults([]string{"bbbb1", "bbbb2"}, completions.Items)
if diff != "" {
t.Fatal(diff)
for _, tt := range tests {
completions := env.Completion("main.go", env.RegexpSearch("main.go", tt.re))
diff := compareCompletionResults(tt.want, completions.Items)
if diff != "" {
t.Errorf("%s: %s", tt.re, diff)
}
}
})
}
11 changes: 9 additions & 2 deletions internal/lsp/source/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,24 @@ func FormatNode(fset *token.FileSet, n ast.Node) string {
// Deref returns a pointer's element type, traversing as many levels as needed.
// Otherwise it returns typ.
//
// It can return a pointer type if the type refers to itself (see golang/go#45510).
// It can return a pointer type for cyclic types (see golang/go#45510).
func Deref(typ types.Type) types.Type {
var seen map[types.Type]struct{}
for {
p, ok := typ.Underlying().(*types.Pointer)
if !ok {
return typ
}
if typ == p.Elem() {
if _, ok := seen[p.Elem()]; ok {
return typ
}

typ = p.Elem()

if seen == nil {
seen = make(map[types.Type]struct{})
}
seen[typ] = struct{}{}
}
}

Expand Down