@@ -75,6 +75,7 @@ type Diagnostic struct {
7575 ReportsUnnecessary bool `json:"reportsUnnecessary"`
7676 ReportsDeprecated bool `json:"reportsDeprecated"`
7777 SkippedOnNoEmit bool `json:"skippedOnNoEmit"`
78+ SourceLine string `json:"sourceLine"`
7879}
7980
8081type diagnosticMaps struct {
@@ -88,13 +89,26 @@ func (d *diagnosticMaps) addDiagnostic(diagnostic *ast.Diagnostic, ls *LanguageS
8889 }
8990 id := DiagnosticId (len (d .diagnosticMapById ) + 1 )
9091
92+ startPos := diagnostic .Loc ().Pos ()
93+ startPosLineCol := getPosition (diagnostic .File (), startPos , ls )
94+ lineMap := ls .converters .getLineMap (diagnostic .File ().FileName ())
95+ lineStartPos := lineMap .LineStarts [startPosLineCol .Line ]
96+ var lineEndPos int
97+ if int (startPosLineCol .Line + 1 ) >= len (lineMap .LineStarts ) {
98+ lineEndPos = len (diagnostic .File ().Text ())
99+ } else {
100+ lineEndPos = int (lineMap .LineStarts [startPosLineCol .Line + 1 ]) - 1
101+ }
102+ sourceLine := diagnostic .File ().Text ()[lineStartPos :lineEndPos ]
103+
91104 diag := Diagnostic {
92105 Id : id ,
93106 FileName : diagnostic .File ().FileName (),
94- Start : getPosition ( diagnostic . File (), diagnostic . Loc (). Pos (), ls ) ,
107+ Start : startPosLineCol ,
95108 End : getPosition (diagnostic .File (), diagnostic .Loc ().End (), ls ),
96- StartPos : diagnostic . Loc (). Pos () ,
109+ StartPos : startPos ,
97110 EndPos : diagnostic .Loc ().End (),
111+ SourceLine : sourceLine ,
98112 Code : diagnostic .Code (),
99113 Category : diagnostic .Category ().Name (),
100114 Message : diagnostic .Message (),
0 commit comments