@@ -200,7 +200,7 @@ func hover(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle, pp pro
200
200
if err != nil {
201
201
return protocol.Range {}, nil , fmt .Errorf ("re-parsing declaration of %s: %v" , obj .Name (), err )
202
202
}
203
- decl , spec , field := findDeclInfo ([]* ast.File {declPGF .File }, declPos )
203
+ decl , spec , field := findDeclInfo ([]* ast.File {declPGF .File }, declPos ) // may be nil^3
204
204
comment := chooseDocComment (decl , spec , field )
205
205
docText := comment .Text ()
206
206
@@ -219,19 +219,22 @@ func hover(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle, pp pro
219
219
// objectString is insufficient:
220
220
// (1) large structs are formatted poorly, with no newlines
221
221
// (2) we lose inline comments
222
- //
223
222
// Furthermore, we include a summary of their method set.
224
- //
225
- // TODO(rfindley): this should use FormatVarType to get proper qualification
226
- // of identifiers, and we should revisit the formatting of method set.
227
- //
228
- // TODO(adonovan): this logic belongs in objectString.
229
223
_ , isTypeName := obj .(* types.TypeName )
230
224
_ , isTypeParam := obj .Type ().(* types.TypeParam )
231
225
if isTypeName && ! isTypeParam {
232
226
spec , ok := spec .(* ast.TypeSpec )
233
227
if ! ok {
234
- return protocol.Range {}, nil , bug .Errorf ("type name %q without type spec" , obj .Name ())
228
+ // We cannot find a TypeSpec for this type or alias declaration
229
+ // (that is not a type parameter or a built-in).
230
+ // This should be impossible even for ill-formed trees;
231
+ // we suspect that AST repair may be creating inconsistent
232
+ // positions. Don't report a bug in that case. (#64241)
233
+ errorf := fmt .Errorf
234
+ if ! declPGF .Fixed () {
235
+ errorf = bug .Errorf
236
+ }
237
+ return protocol.Range {}, nil , errorf ("type name %q without type spec" , obj .Name ())
235
238
}
236
239
spec2 := * spec
237
240
// Don't duplicate comments when formatting type specs.
0 commit comments