config: richer diagnostics for errors

Rather than storing a list of errors we now store a list of
"diagnostics." Each diagnostic has a richer set of structured
information, including a message, a key, the location where it occurred.

This lets us show more detailed messages, more human friendly messages, and
also let's us filter by key or location. We don't take advantage of
all of this capability in this initial commit, but we do use every field
for something.
This commit is contained in:
Mitchell Hashimoto
2024-10-16 16:45:38 -07:00
parent 3f1d6eb301
commit a4e14631ef
11 changed files with 316 additions and 169 deletions

View File

@@ -112,14 +112,15 @@ fn config_trigger_(
return trigger.cval();
}
export fn ghostty_config_errors_count(self: *Config) u32 {
return @intCast(self._errors.list.items.len);
export fn ghostty_config_diagnostics_count(self: *Config) u32 {
return @intCast(self._diagnostics.items().len);
}
export fn ghostty_config_get_error(self: *Config, idx: u32) Error {
if (idx >= self._errors.list.items.len) return .{};
const err = self._errors.list.items[idx];
return .{ .message = err.message.ptr };
export fn ghostty_config_get_diagnostic(self: *Config, idx: u32) Diagnostic {
const items = self._diagnostics.items();
if (idx >= items.len) return .{};
const message = self._diagnostics.precompute.messages.items[idx];
return .{ .message = message.ptr };
}
export fn ghostty_config_open() void {
@@ -128,7 +129,7 @@ export fn ghostty_config_open() void {
};
}
/// Sync with ghostty_error_s
const Error = extern struct {
/// Sync with ghostty_diagnostic_s
const Diagnostic = extern struct {
message: [*:0]const u8 = "",
};