mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
Merge pull request #2831 from ghostty-org/push-wsstrqtukpzq
config: clone should copy diagnostics
This commit is contained in:
@ -34,6 +34,14 @@ pub const Diagnostic = struct {
|
|||||||
|
|
||||||
try writer.print("{s}", .{self.message});
|
try writer.print("{s}", .{self.message});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn clone(self: *const Diagnostic, alloc: Allocator) Allocator.Error!Diagnostic {
|
||||||
|
return .{
|
||||||
|
.location = try self.location.clone(alloc),
|
||||||
|
.key = try alloc.dupeZ(u8, self.key),
|
||||||
|
.message = try alloc.dupeZ(u8, self.message),
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The possible locations for a diagnostic message. This is used
|
/// The possible locations for a diagnostic message. This is used
|
||||||
@ -61,6 +69,19 @@ pub const Location = union(enum) {
|
|||||||
if (!@hasDecl(Iter, "location")) return .none;
|
if (!@hasDecl(Iter, "location")) return .none;
|
||||||
return iter.location() orelse .none;
|
return iter.location() orelse .none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn clone(self: *const Location, alloc: Allocator) Allocator.Error!Location {
|
||||||
|
return switch (self.*) {
|
||||||
|
.none,
|
||||||
|
.cli,
|
||||||
|
=> self.*,
|
||||||
|
|
||||||
|
.file => |v| .{ .file = .{
|
||||||
|
.path = try alloc.dupe(u8, v.path),
|
||||||
|
.line = v.line,
|
||||||
|
} },
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A list of diagnostics. The "_diagnostics" field must be this type
|
/// A list of diagnostics. The "_diagnostics" field must be this type
|
||||||
@ -88,11 +109,45 @@ pub const DiagnosticList = struct {
|
|||||||
// We specifically want precompute for libghostty.
|
// We specifically want precompute for libghostty.
|
||||||
.lib => true,
|
.lib => true,
|
||||||
};
|
};
|
||||||
|
|
||||||
const Precompute = if (precompute_enabled) struct {
|
const Precompute = if (precompute_enabled) struct {
|
||||||
messages: std.ArrayListUnmanaged([:0]const u8) = .{},
|
messages: std.ArrayListUnmanaged([:0]const u8) = .{},
|
||||||
|
|
||||||
|
pub fn clone(
|
||||||
|
self: *const Precompute,
|
||||||
|
alloc: Allocator,
|
||||||
|
) Allocator.Error!Precompute {
|
||||||
|
var result: Precompute = .{};
|
||||||
|
try result.messages.ensureTotalCapacity(alloc, self.messages.items.len);
|
||||||
|
for (self.messages.items) |msg| {
|
||||||
|
result.messages.appendAssumeCapacity(
|
||||||
|
try alloc.dupeZ(u8, msg),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
} else void;
|
} else void;
|
||||||
|
|
||||||
const precompute_init: Precompute = if (precompute_enabled) .{} else {};
|
const precompute_init: Precompute = if (precompute_enabled) .{} else {};
|
||||||
|
|
||||||
|
pub fn clone(
|
||||||
|
self: *const DiagnosticList,
|
||||||
|
alloc: Allocator,
|
||||||
|
) Allocator.Error!DiagnosticList {
|
||||||
|
var result: DiagnosticList = .{};
|
||||||
|
|
||||||
|
try result.list.ensureTotalCapacity(alloc, self.list.items.len);
|
||||||
|
for (self.list.items) |*diag| result.list.appendAssumeCapacity(
|
||||||
|
try diag.clone(alloc),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (comptime precompute_enabled) {
|
||||||
|
result.precompute = try self.precompute.clone(alloc);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn append(
|
pub fn append(
|
||||||
self: *DiagnosticList,
|
self: *DiagnosticList,
|
||||||
alloc: Allocator,
|
alloc: Allocator,
|
||||||
|
@ -3063,6 +3063,9 @@ pub fn clone(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy our diagnostics
|
||||||
|
result._diagnostics = try self._diagnostics.clone(alloc_arena);
|
||||||
|
|
||||||
// Preserve our replay steps. We copy them exactly to also preserve
|
// Preserve our replay steps. We copy them exactly to also preserve
|
||||||
// the exact conditionals required for some steps.
|
// the exact conditionals required for some steps.
|
||||||
try result._replay_steps.ensureTotalCapacity(
|
try result._replay_steps.ensureTotalCapacity(
|
||||||
|
Reference in New Issue
Block a user