diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-08-05 15:32:19 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-08-07 00:48:32 -0700 |
| commit | 3d48602c995b90e40c6e70ace1e0cdcdeea2eac4 (patch) | |
| tree | a6904c4c91273ee2750dc9d51c5cc2cc1757faff /lib/docs/wasm/html_render.zig | |
| parent | ef4c2193fc4b048da2afd3861bedb50451a31358 (diff) | |
| download | zig-3d48602c995b90e40c6e70ace1e0cdcdeea2eac4.tar.gz zig-3d48602c995b90e40c6e70ace1e0cdcdeea2eac4.zip | |
fuzzer web UI: annotated PCs in source view
Diffstat (limited to 'lib/docs/wasm/html_render.zig')
| -rw-r--r-- | lib/docs/wasm/html_render.zig | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/docs/wasm/html_render.zig b/lib/docs/wasm/html_render.zig index cce201049d..a406699f59 100644 --- a/lib/docs/wasm/html_render.zig +++ b/lib/docs/wasm/html_render.zig @@ -16,6 +16,16 @@ pub const RenderSourceOptions = struct { skip_comments: bool = false, collapse_whitespace: bool = false, fn_link: Decl.Index = .none, + /// Assumed to be sorted ascending. + source_location_annotations: []const Annotation = &.{}, + /// Concatenated with dom_id. + annotation_prefix: []const u8 = "l", +}; + +pub const Annotation = struct { + file_byte_offset: u32, + /// Concatenated with annotation_prefix. + dom_id: u32, }; pub fn fileSourceHtml( @@ -51,6 +61,8 @@ pub fn fileSourceHtml( } } + var next_annotate_index: usize = 0; + for ( token_tags[start_token..end_token], token_starts[start_token..end_token], @@ -74,6 +86,18 @@ pub fn fileSourceHtml( if (tag == .eof) break; const slice = ast.tokenSlice(token_index); cursor = start + slice.len; + + // Insert annotations. + while (true) { + if (next_annotate_index >= options.source_location_annotations.len) break; + const next_annotation = options.source_location_annotations[next_annotate_index]; + if (cursor < next_annotation.file_byte_offset) break; + try out.writer(gpa).print("<span id=\"{s}{d}\"></span>", .{ + options.annotation_prefix, next_annotation.dom_id, + }); + next_annotate_index += 1; + } + switch (tag) { .eof => unreachable, |
