diff --git a/internal/lsp/source/symbols.go b/internal/lsp/source/symbols.go index 11de4c3fa3..dff505d877 100644 --- a/internal/lsp/source/symbols.go +++ b/internal/lsp/source/symbols.go @@ -30,7 +30,6 @@ func DocumentSymbols(ctx context.Context, snapshot Snapshot, fh FileHandle) ([]p info := pkg.GetTypesInfo() q := qualifier(file, pkg.GetTypes(), info) - methodsToReceiver := make(map[types.Type][]protocol.DocumentSymbol) symbolsToReceiver := make(map[types.Type]int) var symbols []protocol.DocumentSymbol for _, decl := range file.Decls { @@ -41,14 +40,12 @@ func DocumentSymbols(ctx context.Context, snapshot Snapshot, fh FileHandle) ([]p if err != nil { return nil, err } - // Store methods separately, as we want them to appear as children - // of the corresponding type (which we may not have seen yet). + // If function is a method, prepend the type of the method. if fs.Kind == protocol.Method { rtype := obj.Type().(*types.Signature).Recv().Type() - methodsToReceiver[rtype] = append(methodsToReceiver[rtype], fs) - } else { - symbols = append(symbols, fs) + fs.Name = fmt.Sprintf("(%s).%s", types.TypeString(rtype, q), fs.Name) } + symbols = append(symbols, fs) } case *ast.GenDecl: for _, spec := range decl.Specs { @@ -76,20 +73,6 @@ func DocumentSymbols(ctx context.Context, snapshot Snapshot, fh FileHandle) ([]p } } } - - // Attempt to associate methods to the corresponding type symbol. - for typ, methods := range methodsToReceiver { - if ptr, ok := typ.(*types.Pointer); ok { - typ = ptr.Elem() - } - - if i, ok := symbolsToReceiver[typ]; ok { - symbols[i].Children = append(symbols[i].Children, methods...) - } else { - // The type definition for the receiver of these methods was not in the document. - symbols = append(symbols, methods...) - } - } return symbols, nil } diff --git a/internal/lsp/testdata/lsp/primarymod/symbols/main.go b/internal/lsp/testdata/lsp/primarymod/symbols/main.go index 0e8d5b650f..b4961b40c5 100644 --- a/internal/lsp/testdata/lsp/primarymod/symbols/main.go +++ b/internal/lsp/testdata/lsp/primarymod/symbols/main.go @@ -30,11 +30,11 @@ type Quux struct { //@symbol("Quux", "Quux", "Struct", "") X, Y float64 //@mark(qX, "X"), symbol("X", "X", "Field", "Quux"), symbol("Y", "Y", "Field", "Quux") } -func (f Foo) Baz() string { //@symbol("Baz", "Baz", "Method", "Foo") +func (f Foo) Baz() string { //@symbol("(Foo).Baz", "Baz", "Method", "") return f.baz } -func (q *Quux) Do() {} //@mark(qDo, "Do"), symbol("Do", "Do", "Method", "Quux") +func (q *Quux) Do() {} //@mark(qDo, "Do"), symbol("(*Quux).Do", "Do", "Method", "") func main() { //@symbol("main", "main", "Function", "") @@ -54,3 +54,7 @@ type WithEmbeddeds interface { //@symbol("WithEmbeddeds", "WithEmbeddeds", "Inte ABer //@symbol("ABer", "ABer", "Interface", "WithEmbeddeds") io.Writer //@mark(ioWriter, "io.Writer"), symbol("io.Writer", "io.Writer", "Interface", "WithEmbeddeds") } + +func Dunk() int { return 0 } //@symbol("Dunk", "Dunk", "Function", "") + +func dunk() {} //@symbol("dunk", "dunk", "Function", "") diff --git a/internal/lsp/testdata/lsp/primarymod/symbols/main.go.golden b/internal/lsp/testdata/lsp/primarymod/symbols/main.go.golden index 22cc38aedf..08d1da7d35 100644 --- a/internal/lsp/testdata/lsp/primarymod/symbols/main.go.golden +++ b/internal/lsp/testdata/lsp/primarymod/symbols/main.go.golden @@ -8,14 +8,14 @@ Boolean Boolean 18:2-18:9 BoolAlias Boolean 19:2-19:11 Foo Struct 22:6-22:9 Bar Field 25:2-25:5 - Baz Method 33:14-33:17 Quux Field 23:2-23:6 W Field 24:2-24:3 baz Field 26:2-26:5 Quux Struct 29:6-29:10 - Do Method 37:16-37:18 X Field 30:2-30:3 Y Field 30:5-30:6 +(Foo).Baz Method 33:14-33:17 +(*Quux).Do Method 37:16-37:18 main Function 39:6-39:10 Stringer Interface 43:6-43:14 String Method 44:2-44:8 @@ -26,4 +26,6 @@ WithEmbeddeds Interface 52:6-52:19 ABer Interface 54:2-54:6 Do Method 53:2-53:4 io.Writer Interface 55:2-55:11 +Dunk Function 58:6-58:10 +dunk Function 60:6-60:10 diff --git a/internal/lsp/testdata/lsp/primarymod/workspacesymbol/casesensitive/casesensitive.go b/internal/lsp/testdata/lsp/primarymod/workspacesymbol/casesensitive/casesensitive.go index 9b60651d1c..10d1ebc439 100644 --- a/internal/lsp/testdata/lsp/primarymod/workspacesymbol/casesensitive/casesensitive.go +++ b/internal/lsp/testdata/lsp/primarymod/workspacesymbol/casesensitive/casesensitive.go @@ -1,6 +1,6 @@ package casesensitive /*@ -workspacesymbolcasesensitive("baz", baz) -workspacesymbolcasesensitive("Baz", Baz) +workspacesymbolcasesensitive("dunk", dunk) +workspacesymbolcasesensitive("Dunk", Dunk) */