mirror of
https://github.com/golang/go
synced 2024-11-18 19:24:39 -07:00
internal/lsp: fix nil pointer exception in document symbols
Change-Id: I168bf7b995aa0b609de67999879addad250eff11 Reviewed-on: https://go-review.googlesource.com/c/tools/+/170006 Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
parent
23e29df326
commit
0926561711
@ -46,15 +46,21 @@ func DocumentSymbols(ctx context.Context, f File) []Symbol {
|
||||
for _, decl := range file.Decls {
|
||||
switch decl := decl.(type) {
|
||||
case *ast.FuncDecl:
|
||||
symbols = append(symbols, funcSymbol(decl, info.ObjectOf(decl.Name), fset, q))
|
||||
if obj := info.ObjectOf(decl.Name); obj != nil {
|
||||
symbols = append(symbols, funcSymbol(decl, obj, fset, q))
|
||||
}
|
||||
case *ast.GenDecl:
|
||||
for _, spec := range decl.Specs {
|
||||
switch spec := spec.(type) {
|
||||
case *ast.TypeSpec:
|
||||
symbols = append(symbols, typeSymbol(spec, info.ObjectOf(spec.Name), fset, q))
|
||||
if obj := info.ObjectOf(spec.Name); obj != nil {
|
||||
symbols = append(symbols, typeSymbol(spec, obj, fset, q))
|
||||
}
|
||||
case *ast.ValueSpec:
|
||||
for _, name := range spec.Names {
|
||||
symbols = append(symbols, varSymbol(decl, name, info.ObjectOf(name), fset, q))
|
||||
if obj := info.ObjectOf(name); obj != nil {
|
||||
symbols = append(symbols, varSymbol(decl, name, obj, fset, q))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user