diff --git a/lib/docs/index.html b/lib/docs/index.html
index e8d84aa91446..78c8a65cd15f 100644
--- a/lib/docs/index.html
+++ b/lib/docs/index.html
@@ -36,6 +36,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;
}
@@ -400,7 +409,14 @@
Example Usage
diff --git a/lib/docs/main.js b/lib/docs/main.js
index 49c277b9f512..9d8ebf47e4fb 100644
--- a/lib/docs/main.js
+++ b/lib/docs/main.js
@@ -45,6 +45,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");
@@ -215,6 +216,7 @@
href: location.hash,
}]);
+ domSourceLineNumbers.innerHTML = declLineNumbersHtml(decl_index);
domSourceText.innerHTML = declSourceHtml(decl_index);
domSectSource.classList.remove("hidden");
@@ -366,6 +368,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");
}
@@ -396,6 +399,7 @@
renderErrorSet(base_decl, errorSetNodeList(decl_index, errorSetNode));
}
+ domSourceLineNumbers.innerHTML = declLineNumbersHtml(decl_index);
domSourceText.innerHTML = declSourceHtml(decl_index);
domSectSource.classList.remove("hidden");
}
@@ -410,6 +414,7 @@
domTldDocs.classList.remove("hidden");
}
+ domSourceLineNumbers.innerHTML = declLineNumbersHtml(decl_index);
domSourceText.innerHTML = declSourceHtml(decl_index);
domSectSource.classList.remove("hidden");
}
@@ -890,6 +895,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));
}
diff --git a/lib/docs/wasm/html_render.zig b/lib/docs/wasm/html_render.zig
index d9cb74f152e8..22a4816c41dd 100644
--- a/lib/docs/wasm/html_render.zig
+++ b/lib/docs/wasm/html_render.zig
@@ -28,6 +28,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, "{d}\n", .{i + 1});
+ }
+}
+
pub fn fileSourceHtml(
file_index: Walk.File.Index,
out: *std.ArrayListUnmanaged(u8),
diff --git a/lib/docs/wasm/main.zig b/lib/docs/wasm/main.zig
index 0ec222751283..25dc8b6b71c3 100644
--- a/lib/docs/wasm/main.zig
+++ b/lib/docs/wasm/main.zig
@@ -7,6 +7,7 @@ const markdown = @import("markdown.zig");
const Decl = Walk.Decl;
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;
@@ -519,6 +520,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();