mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 01:24:49 +01:00
Autodoc: display line numbers in source code display
This commit is contained in:
parent
f061c0dc28
commit
6c63926333
4 changed files with 51 additions and 1 deletions
|
|
@ -40,6 +40,15 @@
|
|||
code a {
|
||||
color: #000000;
|
||||
}
|
||||
.source-code {
|
||||
display: grid;
|
||||
grid-template-columns: auto 1fr;
|
||||
align-items: start;
|
||||
}
|
||||
.source-line-numbers pre {
|
||||
text-align: right;
|
||||
color: #666;
|
||||
}
|
||||
#listFields > div, #listParams > div {
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
|
@ -429,7 +438,14 @@
|
|||
</div>
|
||||
<div id="sectSource" class="hidden">
|
||||
<h2>Source Code</h2>
|
||||
<pre><code id="sourceText"></code></pre>
|
||||
<div class="source-code">
|
||||
<div class="source-line-numbers">
|
||||
<pre><code id="sourceLineNumbers"></code></pre>
|
||||
</div>
|
||||
<div class="source-text">
|
||||
<pre><code id="sourceText"></code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<div id="helpDialog" class="hidden">
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@
|
|||
const domSectTypes = document.getElementById("sectTypes");
|
||||
const domSectValues = document.getElementById("sectValues");
|
||||
const domSourceText = document.getElementById("sourceText");
|
||||
const domSourceLineNumbers = document.getElementById("sourceLineNumbers");
|
||||
const domStatus = document.getElementById("status");
|
||||
const domTableFnErrors = document.getElementById("tableFnErrors");
|
||||
const domTldDocs = document.getElementById("tldDocs");
|
||||
|
|
@ -238,6 +239,7 @@
|
|||
href: location.hash,
|
||||
}]);
|
||||
|
||||
domSourceLineNumbers.innerHTML = declLineNumbersHtml(decl_index);
|
||||
domSourceText.innerHTML = declSourceHtml(decl_index);
|
||||
|
||||
domSectSource.classList.remove("hidden");
|
||||
|
|
@ -389,6 +391,7 @@
|
|||
if (members.length !== 0 || fields.length !== 0) {
|
||||
renderNamespace(decl_index, members, fields);
|
||||
} else {
|
||||
domSourceLineNumbers.innerHTML = declLineNumbersHtml(decl_index);
|
||||
domSourceText.innerHTML = declSourceHtml(decl_index);
|
||||
domSectSource.classList.remove("hidden");
|
||||
}
|
||||
|
|
@ -419,6 +422,7 @@
|
|||
renderErrorSet(base_decl, errorSetNodeList(decl_index, errorSetNode));
|
||||
}
|
||||
|
||||
domSourceLineNumbers.innerHTML = declLineNumbersHtml(decl_index);
|
||||
domSourceText.innerHTML = declSourceHtml(decl_index);
|
||||
domSectSource.classList.remove("hidden");
|
||||
}
|
||||
|
|
@ -433,6 +437,7 @@
|
|||
domTldDocs.classList.remove("hidden");
|
||||
}
|
||||
|
||||
domSourceLineNumbers.innerHTML = declLineNumbersHtml(decl_index);
|
||||
domSourceText.innerHTML = declSourceHtml(decl_index);
|
||||
domSectSource.classList.remove("hidden");
|
||||
}
|
||||
|
|
@ -918,6 +923,10 @@
|
|||
return unwrapString(wasm_exports.decl_source_html(decl_index));
|
||||
}
|
||||
|
||||
function declLineNumbersHtml(decl_index) {
|
||||
return unwrapString(wasm_exports.decl_line_numbers_html(decl_index));
|
||||
}
|
||||
|
||||
function declDoctestHtml(decl_index) {
|
||||
return unwrapString(wasm_exports.decl_doctest_html(decl_index));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,20 @@ pub const Annotation = struct {
|
|||
dom_id: u32,
|
||||
};
|
||||
|
||||
pub fn fileSourceLineNumbersHtml(
|
||||
file_index: Walk.File.Index,
|
||||
out: *std.ArrayListUnmanaged(u8),
|
||||
root_node: Ast.Node.Index,
|
||||
) !void {
|
||||
const ast = file_index.get_ast();
|
||||
const first_token_line = ast.tokenLocation(0, ast.firstToken(root_node)).line;
|
||||
const last_token_line = ast.tokenLocation(0, ast.lastToken(root_node)).line;
|
||||
const writer = out.writer(gpa);
|
||||
for (first_token_line..last_token_line + 1) |i| {
|
||||
try std.fmt.format(writer, "<span>{d}</span>\n", .{i + 1});
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fileSourceHtml(
|
||||
file_index: Walk.File.Index,
|
||||
out: *ArrayList(u8),
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ const ArrayList = std.ArrayList;
|
|||
const Writer = std.Io.Writer;
|
||||
|
||||
const fileSourceHtml = @import("html_render.zig").fileSourceHtml;
|
||||
const fileSourceLineNumbersHtml = @import("html_render.zig").fileSourceLineNumbersHtml;
|
||||
const appendEscaped = @import("html_render.zig").appendEscaped;
|
||||
const resolveDeclLink = @import("html_render.zig").resolveDeclLink;
|
||||
const missing_feature_url_escape = @import("html_render.zig").missing_feature_url_escape;
|
||||
|
|
@ -543,6 +544,16 @@ export fn decl_fn_proto_html(decl_index: Decl.Index, linkify_fn_name: bool) Stri
|
|||
return String.init(string_result.items);
|
||||
}
|
||||
|
||||
export fn decl_line_numbers_html(decl_index: Decl.Index) String {
|
||||
const decl = decl_index.get();
|
||||
|
||||
string_result.clearRetainingCapacity();
|
||||
fileSourceLineNumbersHtml(decl.file, &string_result, decl.ast_node) catch |err| {
|
||||
fatal("unable to render source line numbers: {s}", .{@errorName(err)});
|
||||
};
|
||||
return String.init(string_result.items);
|
||||
}
|
||||
|
||||
export fn decl_source_html(decl_index: Decl.Index) String {
|
||||
const decl = decl_index.get();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue