@@ -156,12 +156,31 @@ export class DiagnosticsFeature extends Feature implements IDiagnosticsFeature {
156156 const diagnostic = editorDiagnostic . diagnostic ;
157157 const severity = SeverityMap [ diagnostic . severity ! ] ;
158158
159+ const lines = view . state . doc . lines ;
160+ const lastLineLength = view . state . doc . line ( lines ) . length ;
161+ const start = PositionConverter . cm_to_ce (
162+ editorDiagnostic . range . start
163+ ) ;
164+ const end = PositionConverter . cm_to_ce (
165+ editorDiagnostic . range . end
166+ ) ;
167+
159168 const from = editorDiagnostic . editor . getOffsetAt (
160- PositionConverter . cm_to_ce ( editorDiagnostic . range . start )
169+ start . line >= lines
170+ ? {
171+ line : Math . min ( start . line , lines ) ,
172+ column : Math . min ( start . column , lastLineLength )
173+ }
174+ : start
161175 ) ;
162176 // TODO: this is wrong; there is however an issue if this is not applied
163177 const to = editorDiagnostic . editor . getOffsetAt (
164- PositionConverter . cm_to_ce ( editorDiagnostic . range . end )
178+ end . line >= lines
179+ ? {
180+ line : Math . min ( end . line , lines ) ,
181+ column : Math . min ( end . column , lastLineLength )
182+ }
183+ : end
165184 ) ;
166185
167186 const classNames = [ ] ;
@@ -170,8 +189,8 @@ export class DiagnosticsFeature extends Feature implements IDiagnosticsFeature {
170189 }
171190
172191 diagnostics . push ( {
173- from : Math . min ( from , view . state . doc . length - 1 ) ,
174- to : Math . min ( to , view . state . doc . length - 1 ) ,
192+ from : Math . min ( from , view . state . doc . length ) ,
193+ to : Math . min ( to , view . state . doc . length ) ,
175194 severity : severity ,
176195 message : diagnostic . message ,
177196 source : diagnostic . source ,
0 commit comments