@@ -362,15 +362,24 @@ type JSONSuggestedFix struct {
362
362
Edits []JSONTextEdit `json:"edits"`
363
363
}
364
364
365
- // A JSONDiagnostic can be used to encode and decode analysis.Diagnostics to and
366
- // from JSON.
367
- // TODO(matloob): Should the JSON diagnostics contain ranges?
368
- // If so, how should they be formatted?
365
+ // A JSONDiagnostic describes the JSON schema of an analysis.Diagnostic.
366
+ //
367
+ // TODO(matloob): include End position if present.
369
368
type JSONDiagnostic struct {
370
- Category string `json:"category,omitempty"`
371
- Posn string `json:"posn"`
372
- Message string `json:"message"`
373
- SuggestedFixes []JSONSuggestedFix `json:"suggested_fixes,omitempty"`
369
+ Category string `json:"category,omitempty"`
370
+ Posn string `json:"posn"` // e.g. "file.go:line:column"
371
+ Message string `json:"message"`
372
+ SuggestedFixes []JSONSuggestedFix `json:"suggested_fixes,omitempty"`
373
+ Related []JSONRelatedInformation `json:"related,omitempty"`
374
+ }
375
+
376
+ // A JSONRelated describes a secondary position and message related to
377
+ // a primary diagnostic.
378
+ //
379
+ // TODO(adonovan): include End position if present.
380
+ type JSONRelatedInformation struct {
381
+ Posn string `json:"posn"` // e.g. "file.go:line:column"
382
+ Message string `json:"message"`
374
383
}
375
384
376
385
// Add adds the result of analysis 'name' on package 'id'.
@@ -401,11 +410,19 @@ func (tree JSONTree) Add(fset *token.FileSet, id, name string, diags []analysis.
401
410
Edits : edits ,
402
411
})
403
412
}
413
+ var related []JSONRelatedInformation
414
+ for _ , r := range f .Related {
415
+ related = append (related , JSONRelatedInformation {
416
+ Posn : fset .Position (r .Pos ).String (),
417
+ Message : r .Message ,
418
+ })
419
+ }
404
420
jdiag := JSONDiagnostic {
405
421
Category : f .Category ,
406
422
Posn : fset .Position (f .Pos ).String (),
407
423
Message : f .Message ,
408
424
SuggestedFixes : fixes ,
425
+ Related : related ,
409
426
}
410
427
diagnostics = append (diagnostics , jdiag )
411
428
}
0 commit comments