mirror of
https://github.com/golang/go
synced 2024-09-30 20:18:33 -06:00
internal/lsp: fix breadcrumbs when inside of a method
This change fixes breadcrumbs when the cursor is inside of a method by making the method a top level symbol and removing it from the struct's hierarchy. Fixes golang/go#36949 Change-Id: I8da5f453a5c78ade1e7688fc4eeebf79ce96f1e1 Reviewed-on: https://go-review.googlesource.com/c/tools/+/221819 Run-TryBot: Rohan Challa <rohan@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
827390e901
commit
d05f4d6edb
@ -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
|
||||
}
|
||||
|
||||
|
@ -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", "")
|
||||
|
@ -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
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package casesensitive
|
||||
|
||||
/*@
|
||||
workspacesymbolcasesensitive("baz", baz)
|
||||
workspacesymbolcasesensitive("Baz", Baz)
|
||||
workspacesymbolcasesensitive("dunk", dunk)
|
||||
workspacesymbolcasesensitive("Dunk", Dunk)
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user