frontend: provide contextual source repair advice

This commit is contained in:
dev committed 2026-10-09 14:04:40 +03:00
1 parent 008867fe48
commit 2c6c7a3dcd
37 files changed
+562 -24

No files matched your search

+13
View File
@@ -162,6 +162,19 @@ fn runSource(arena: std.mem.Allocator, io: std.Io, dir: std.Io.Dir, rel: []const
const report = try aji.check.checkWithModules(arena, path, source, modules.items);
if (report.status == .unimplemented) return .{ .outcome = .pending, .detail = report.missing_stage };
if (try diagnosticIssue(arena, report.diagnostics)) |issue| return .{ .outcome = .fail, .detail = issue };
const advice_path = try std.fmt.allocPrint(arena, "{s}.advice", .{rel});
if (dir.readFileAlloc(io, advice_path, arena, .limited(1 << 20))) |golden| {
var output: std.Io.Writer.Allocating = .init(arena);
for (report.diagnostics) |diagnostic| {
var json: std.json.Stringify = .{ .writer = &output.writer };
try aji.diag.writeRepairCandidates(diagnostic.repair_candidates, &json);
try output.writer.writeByte('\n');
}
if (!std.mem.eql(u8, golden, output.written())) return .{ .outcome = .fail, .detail = "source repair advice differs from .advice golden" };
} else |err| switch (err) {
error.FileNotFound => {},
else => return .{ .outcome = .fail, .detail = try std.fmt.allocPrint(arena, "cannot read advice golden: {t}", .{err}) },
}
if (report.lowered) |lowered| {
const again = try aji.frontend.compileWithModules(arena, path, source, modules.items);
if (again != .ok or !std.mem.eql(u8, again.ok.air, lowered.air)) return .{ .outcome = .fail, .detail = "lowering is not deterministic" };