@@ -108,9 +108,11 @@ fn renderContext(self: *GraphicalFormatter, w: *Writer, e: *Error) FormatError!v
108108
109109 try self .renderContextMasthead (w , e , lineum_width , primary );
110110
111+ var last_rendered_line : u32 = 0 ;
111112 for (locations .items ) | loc | {
112113 if (loc .rendered ) continue ;
113- try self .renderContextLines (w , src , lineum_width , locations .items , loc );
114+ try self .renderContextLines (w , src , lineum_width , locations .items , loc , last_rendered_line );
115+ last_rendered_line = loc .line () + self .context_lines ;
114116 }
115117 try self .renderContextFinisher (w , lineum_width );
116118}
@@ -158,6 +160,8 @@ fn renderContextLines(
158160 lineum_width : u32 ,
159161 locations : []ContextInfo ,
160162 loc : ContextInfo ,
163+ // last rendered line of the previous location
164+ last_rendered_line : u32 ,
161165) ! void {
162166 var LINEBUF : [MAX_CONTEXT_LINES * 2 + 1 ]Line = undefined ;
163167 var linebuf = LINEBUF [0.. (self .context_lines * 2 + 1 )];
@@ -180,8 +184,9 @@ fn renderContextLines(
180184 lines_end += 1 ;
181185
182186 for (linebuf [lines_start .. lines_end ]) | line | {
183- // try w.print("{d}:", .{line.num});
184- // try w.writeByteNTimes(' ', padding);
187+ // avoid double-rendering lines when two spans have their context lines
188+ // overlap.
189+ if (line .num <= last_rendered_line ) continue ;
185190 try self .renderCodeLinePrefix (w , line .num , lineum_width );
186191 try w .writeAll (util .trimWhitespaceRight (line .contents ));
187192 if (util .IS_WINDOWS ) {
0 commit comments