Skip to content

Commit f707494

Browse files
committed
do not create invalid error bundle source locations from zig stderr
See ziglang/vscode-zig#452
1 parent f302ba6 commit f707494

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/features/diagnostics.zig

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,18 +412,19 @@ pub fn getErrorBundleFromStderr(
412412

413413
const src_loc = if (maybe_source) |source| src_loc: {
414414
const source_index = offsets.positionToIndex(source, utf8_position, .@"utf-8");
415-
const source_line = offsets.lineSliceAtIndex(source, source_index);
415+
const source_loc = offsets.lineLocAtIndex(source, source_index);
416416

417417
const loc = offsets.tokenIndexToLoc(source, source_index);
418418

419419
break :src_loc try error_bundle.addSourceLocation(.{
420420
.src_path = eb_src_path,
421421
.line = utf8_position.line,
422422
.column = utf8_position.character,
423-
.span_start = @intCast(loc.start),
423+
// span_start <= span_main <= span_end <= source_loc.end
424+
.span_start = @intCast(@min(source_index, loc.start)),
424425
.span_main = @intCast(source_index),
425-
.span_end = @intCast(loc.end),
426-
.source_line = try error_bundle.addString(source_line),
426+
.span_end = @intCast(@min(@max(source_index, loc.end), source_loc.end)),
427+
.source_line = try error_bundle.addString(offsets.locToSlice(source, source_loc)),
427428
});
428429
} else src_loc: {
429430
break :src_loc try error_bundle.addSourceLocation(.{

0 commit comments

Comments
 (0)