@@ -83,6 +83,8 @@ const EDIT_MISMATCH_SCAN_LINE_LIMIT = 2000;
8383const EDIT_MISMATCH_LINE_DISPLAY_LIMIT = 140 ;
8484// Keep one extra char so formatting can still show that the source line was truncated.
8585const EDIT_MISMATCH_LINE_STORAGE_LIMIT = EDIT_MISMATCH_LINE_DISPLAY_LIMIT + 1 ;
86+ const EDIT_MISMATCH_SCAN_BYTE_LIMIT =
87+ EDIT_MISMATCH_SCAN_LINE_LIMIT * EDIT_MISMATCH_LINE_STORAGE_LIMIT ;
8688const EDIT_INDEXED_MISMATCH_RE = / \b C o u l d n o t f i n d e d i t s \[ \d + \] i n / u;
8789
8890/**
@@ -264,6 +266,7 @@ function findClosestMismatchLines(
264266 currentContent ,
265267 EDIT_MISMATCH_SCAN_LINE_LIMIT ,
266268 EDIT_MISMATCH_LINE_STORAGE_LIMIT ,
269+ EDIT_MISMATCH_SCAN_BYTE_LIMIT ,
267270 )
268271 . map ( ( line , index ) => ( {
269272 lineNumber : index + 1 ,
@@ -279,11 +282,13 @@ function collectNormalizedLines(
279282 content : string ,
280283 lineLimit : number ,
281284 lineLengthLimit : number ,
285+ scanByteLimit : number ,
282286) : string [ ] {
283287 const lines : string [ ] = [ ] ;
284288 let lineStart = 0 ;
289+ const scanEnd = Math . min ( content . length , scanByteLimit ) ;
285290
286- for ( let index = 0 ; index < content . length && lines . length < lineLimit ; index += 1 ) {
291+ for ( let index = 0 ; index < scanEnd && lines . length < lineLimit ; index += 1 ) {
287292 const char = content [ index ] ;
288293 if ( char !== "\n" && char !== "\r" ) {
289294 continue ;
@@ -296,8 +301,8 @@ function collectNormalizedLines(
296301 lineStart = index + 1 ;
297302 }
298303
299- if ( lines . length < lineLimit ) {
300- lines . push ( content . slice ( lineStart , lineStart + lineLengthLimit ) ) ;
304+ if ( lines . length < lineLimit && lineStart <= scanEnd ) {
305+ lines . push ( content . slice ( lineStart , Math . min ( scanEnd , lineStart + lineLengthLimit ) ) ) ;
301306 }
302307
303308 return lines ;
0 commit comments