@@ -37,9 +37,13 @@ func DocumentSymbols(ctx context.Context, snapshot Snapshot, f File) ([]protocol
37
37
switch decl := decl .(type ) {
38
38
case * ast.FuncDecl :
39
39
if obj := info .ObjectOf (decl .Name ); obj != nil {
40
- if fs := funcSymbol (ctx , snapshot .View (), m , decl , obj , q ); fs .Kind == protocol .Method {
41
- // Store methods separately, as we want them to appear as children
42
- // of the corresponding type (which we may not have seen yet).
40
+ fs , err := funcSymbol (ctx , snapshot .View (), m , decl , obj , q )
41
+ if err != nil {
42
+ return nil , err
43
+ }
44
+ // Store methods separately, as we want them to appear as children
45
+ // of the corresponding type (which we may not have seen yet).
46
+ if fs .Kind == protocol .Method {
43
47
rtype := obj .Type ().(* types.Signature ).Recv ().Type ()
44
48
methodsToReceiver [rtype ] = append (methodsToReceiver [rtype ], fs )
45
49
} else {
@@ -51,14 +55,21 @@ func DocumentSymbols(ctx context.Context, snapshot Snapshot, f File) ([]protocol
51
55
switch spec := spec .(type ) {
52
56
case * ast.TypeSpec :
53
57
if obj := info .ObjectOf (spec .Name ); obj != nil {
54
- ts := typeSymbol (ctx , snapshot .View (), m , info , spec , obj , q )
58
+ ts , err := typeSymbol (ctx , snapshot .View (), m , info , spec , obj , q )
59
+ if err != nil {
60
+ return nil , err
61
+ }
55
62
symbols = append (symbols , ts )
56
63
symbolsToReceiver [obj .Type ()] = len (symbols ) - 1
57
64
}
58
65
case * ast.ValueSpec :
59
66
for _ , name := range spec .Names {
60
67
if obj := info .ObjectOf (name ); obj != nil {
61
- symbols = append (symbols , varSymbol (ctx , snapshot .View (), m , decl , name , obj , q ))
68
+ vs , err := varSymbol (ctx , snapshot .View (), m , decl , name , obj , q )
69
+ if err != nil {
70
+ return nil , err
71
+ }
72
+ symbols = append (symbols , vs )
62
73
}
63
74
}
64
75
}
@@ -82,16 +93,19 @@ func DocumentSymbols(ctx context.Context, snapshot Snapshot, f File) ([]protocol
82
93
return symbols , nil
83
94
}
84
95
85
- func funcSymbol (ctx context.Context , view View , m * protocol.ColumnMapper , decl * ast.FuncDecl , obj types.Object , q types.Qualifier ) protocol.DocumentSymbol {
96
+ func funcSymbol (ctx context.Context , view View , m * protocol.ColumnMapper , decl * ast.FuncDecl , obj types.Object , q types.Qualifier ) ( protocol.DocumentSymbol , error ) {
86
97
s := protocol.DocumentSymbol {
87
98
Name : obj .Name (),
88
99
Kind : protocol .Function ,
89
100
}
90
- if span , err := nodeToProtocolRange (ctx , view , m , decl ); err == nil {
91
- s .Range = span
101
+ var err error
102
+ s .Range , err = nodeToProtocolRange (ctx , view , m , decl )
103
+ if err != nil {
104
+ return protocol.DocumentSymbol {}, err
92
105
}
93
- if span , err := nodeToProtocolRange (ctx , view , m , decl .Name ); err == nil {
94
- s .SelectionRange = span
106
+ s .SelectionRange , err = nodeToProtocolRange (ctx , view , m , decl .Name )
107
+ if err != nil {
108
+ return protocol.DocumentSymbol {}, err
95
109
}
96
110
sig , _ := obj .Type ().(* types.Signature )
97
111
if sig != nil {
@@ -112,7 +126,7 @@ func funcSymbol(ctx context.Context, view View, m *protocol.ColumnMapper, decl *
112
126
}
113
127
s .Detail += ")"
114
128
}
115
- return s
129
+ return s , nil
116
130
}
117
131
118
132
func setKind (s * protocol.DocumentSymbol , typ types.Type , q types.Qualifier ) {
@@ -143,18 +157,21 @@ func setKind(s *protocol.DocumentSymbol, typ types.Type, q types.Qualifier) {
143
157
}
144
158
}
145
159
146
- func typeSymbol (ctx context.Context , view View , m * protocol.ColumnMapper , info * types.Info , spec * ast.TypeSpec , obj types.Object , q types.Qualifier ) protocol.DocumentSymbol {
160
+ func typeSymbol (ctx context.Context , view View , m * protocol.ColumnMapper , info * types.Info , spec * ast.TypeSpec , obj types.Object , q types.Qualifier ) ( protocol.DocumentSymbol , error ) {
147
161
s := protocol.DocumentSymbol {
148
162
Name : obj .Name (),
149
163
}
150
164
s .Detail , _ = formatType (obj .Type (), q )
151
165
setKind (& s , obj .Type (), q )
152
166
153
- if span , err := nodeToProtocolRange (ctx , view , m , spec ); err == nil {
154
- s .Range = span
167
+ var err error
168
+ s .Range , err = nodeToProtocolRange (ctx , view , m , spec )
169
+ if err != nil {
170
+ return protocol.DocumentSymbol {}, err
155
171
}
156
- if span , err := nodeToProtocolRange (ctx , view , m , spec .Name ); err == nil {
157
- s .SelectionRange = span
172
+ s .SelectionRange , err = nodeToProtocolRange (ctx , view , m , spec .Name )
173
+ if err != nil {
174
+ return protocol.DocumentSymbol {}, err
158
175
}
159
176
t , objIsStruct := obj .Type ().Underlying ().(* types.Struct )
160
177
st , specIsStruct := spec .Type .(* ast.StructType )
@@ -198,11 +215,13 @@ func typeSymbol(ctx context.Context, view View, m *protocol.ColumnMapper, info *
198
215
}
199
216
}
200
217
}
201
- if span , err := nodeToProtocolRange (ctx , view , m , spanNode ); err == nil {
202
- child .Range = span
218
+ child .Range , err = nodeToProtocolRange (ctx , view , m , spanNode )
219
+ if err != nil {
220
+ return protocol.DocumentSymbol {}, err
203
221
}
204
- if span , err := nodeToProtocolRange (ctx , view , m , selectionNode ); err == nil {
205
- child .SelectionRange = span
222
+ child .SelectionRange , err = nodeToProtocolRange (ctx , view , m , selectionNode )
223
+ if err != nil {
224
+ return protocol.DocumentSymbol {}, err
206
225
}
207
226
s .Children = append (s .Children , child )
208
227
}
@@ -230,16 +249,18 @@ func typeSymbol(ctx context.Context, view View, m *protocol.ColumnMapper, info *
230
249
break Embeddeds
231
250
}
232
251
}
233
- if rng , err := nodeToProtocolRange (ctx , view , m , spanNode ); err == nil {
234
- child .Range = rng
252
+ child .Range , err = nodeToProtocolRange (ctx , view , m , spanNode )
253
+ if err != nil {
254
+ return protocol.DocumentSymbol {}, err
235
255
}
236
- if span , err := nodeToProtocolRange (ctx , view , m , selectionNode ); err == nil {
237
- child .SelectionRange = span
256
+ child .SelectionRange , err = nodeToProtocolRange (ctx , view , m , selectionNode )
257
+ if err != nil {
258
+ return protocol.DocumentSymbol {}, err
238
259
}
239
260
s .Children = append (s .Children , child )
240
261
}
241
262
}
242
- return s
263
+ return s , nil
243
264
}
244
265
245
266
func nodesForStructField (i int , st * ast.StructType ) (span , selection ast.Node ) {
@@ -262,20 +283,23 @@ func nodesForStructField(i int, st *ast.StructType) (span, selection ast.Node) {
262
283
return nil , nil
263
284
}
264
285
265
- func varSymbol (ctx context.Context , view View , m * protocol.ColumnMapper , decl ast.Node , name * ast.Ident , obj types.Object , q types.Qualifier ) protocol.DocumentSymbol {
286
+ func varSymbol (ctx context.Context , view View , m * protocol.ColumnMapper , decl ast.Node , name * ast.Ident , obj types.Object , q types.Qualifier ) ( protocol.DocumentSymbol , error ) {
266
287
s := protocol.DocumentSymbol {
267
288
Name : obj .Name (),
268
289
Kind : protocol .Variable ,
269
290
}
270
291
if _ , ok := obj .(* types.Const ); ok {
271
292
s .Kind = protocol .Constant
272
293
}
273
- if rng , err := nodeToProtocolRange (ctx , view , m , decl ); err == nil {
274
- s .Range = rng
294
+ var err error
295
+ s .Range , err = nodeToProtocolRange (ctx , view , m , decl )
296
+ if err != nil {
297
+ return protocol.DocumentSymbol {}, err
275
298
}
276
- if span , err := nodeToProtocolRange (ctx , view , m , name ); err == nil {
277
- s .SelectionRange = span
299
+ s .SelectionRange , err = nodeToProtocolRange (ctx , view , m , name )
300
+ if err != nil {
301
+ return protocol.DocumentSymbol {}, err
278
302
}
279
303
s .Detail = types .TypeString (obj .Type (), q )
280
- return s
304
+ return s , nil
281
305
}
0 commit comments