mirror of
https://github.com/ziglang/zig.git
synced 2025-12-15 02:33:07 +00:00
autodoc: improve frontend rendering
This commit is contained in:
parent
cf685c1132
commit
aa545dbd1e
709
lib/docs/main.js
709
lib/docs/main.js
File diff suppressed because it is too large
Load Diff
@ -542,13 +542,14 @@ const DocData = struct {
|
||||
call: usize, // index in `calls`
|
||||
enumLiteral: []const u8, // direct value
|
||||
typeOf: usize, // index in `exprs`
|
||||
as: struct {
|
||||
typeRefArg: ?usize, // index in `exprs`
|
||||
exprArg: usize, // index in `exprs`
|
||||
},
|
||||
as: As,
|
||||
sizeOf: usize, // index in `exprs`
|
||||
compileError: []const u8,
|
||||
string: []const u8, // direct value
|
||||
const As = struct {
|
||||
typeRefArg: ?usize, // index in `exprs`
|
||||
exprArg: usize, // index in `exprs`
|
||||
};
|
||||
const FieldRef = struct {
|
||||
type: usize, // index in `types`
|
||||
index: usize, // index in type.fields
|
||||
@ -592,12 +593,16 @@ const DocData = struct {
|
||||
, .{v});
|
||||
},
|
||||
.sizeOf => |v| try std.json.stringify(v, options, w),
|
||||
.as => |v| try std.json.stringify(v, options, w),
|
||||
.fieldRef => |v| try std.json.stringify(
|
||||
struct { fieldRef: FieldRef }{ .fieldRef = v },
|
||||
options,
|
||||
w,
|
||||
),
|
||||
.as => |v| try std.json.stringify(
|
||||
struct { as: As }{ .as = v },
|
||||
options,
|
||||
w,
|
||||
),
|
||||
.@"struct" => |v| try std.json.stringify(
|
||||
struct { @"struct": []FieldVal }{ .@"struct" = v },
|
||||
options,
|
||||
@ -774,7 +779,12 @@ fn walkInstruction(
|
||||
);
|
||||
|
||||
return DocData.WalkResult{
|
||||
.expr = .{ .compileError = operand.expr.string },
|
||||
.expr = .{
|
||||
.compileError = switch (operand.expr) {
|
||||
.string => |s| s,
|
||||
else => "TODO: non-string @compileError arguments",
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
.enum_literal => {
|
||||
@ -1010,6 +1020,9 @@ fn walkInstruction(
|
||||
.decl_val, .decl_ref => {
|
||||
const str_tok = data[inst_index].str_tok;
|
||||
const decls_slot_index = parent_scope.resolveDeclName(str_tok.start);
|
||||
// While it would make sense to grab the original decl's typeRef info,
|
||||
// that decl might not have been analyzed yet! The frontend will have
|
||||
// to navigate through all declRefs to find the underlying type.
|
||||
return DocData.WalkResult{ .expr = .{ .declRef = decls_slot_index } };
|
||||
},
|
||||
.field_val, .field_call_bind, .field_ptr, .field_type => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user