Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions go/analysis/internal/analysisflags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,22 +363,20 @@ type JSONSuggestedFix struct {
}

// A JSONDiagnostic describes the JSON schema of an analysis.Diagnostic.
//
// TODO(matloob): include End position if present.
type JSONDiagnostic struct {
Category string `json:"category,omitempty"`
Posn string `json:"posn"` // e.g. "file.go:line:column"
EndPosn string `json:"end_posn,omitempty"`
Message string `json:"message"`
SuggestedFixes []JSONSuggestedFix `json:"suggested_fixes,omitempty"`
Related []JSONRelatedInformation `json:"related,omitempty"`
}

// A JSONRelated describes a secondary position and message related to
// a primary diagnostic.
//
// TODO(adonovan): include End position if present.
type JSONRelatedInformation struct {
Posn string `json:"posn"` // e.g. "file.go:line:column"
EndPosn string `json:"end_posn,omitempty"`
Message string `json:"message"`
}

Expand Down Expand Up @@ -412,10 +410,14 @@ func (tree JSONTree) Add(fset *token.FileSet, id, name string, diags []analysis.
}
var related []JSONRelatedInformation
for _, r := range f.Related {
related = append(related, JSONRelatedInformation{
relatedInfo := JSONRelatedInformation{
Posn: fset.Position(r.Pos).String(),
Message: r.Message,
})
}
if r.End != token.NoPos {
relatedInfo.EndPosn = fset.Position(r.End).String()
}
related = append(related, relatedInfo)
}
jdiag := JSONDiagnostic{
Category: f.Category,
Expand All @@ -424,6 +426,9 @@ func (tree JSONTree) Add(fset *token.FileSet, id, name string, diags []analysis.
SuggestedFixes: fixes,
Related: related,
}
if f.End != token.NoPos {
jdiag.EndPosn = fset.Position(f.End).String()
}
diagnostics = append(diagnostics, jdiag)
}
v = diagnostics
Expand Down