diff --git a/lib/docs/index.html b/lib/docs/index.html
index e60a3f960a..75c0daf797 100644
--- a/lib/docs/index.html
+++ b/lib/docs/index.html
@@ -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 @@
diff --git a/lib/docs/main.js b/lib/docs/main.js
index 71a14516cb..a9bf4a745e 100644
--- a/lib/docs/main.js
+++ b/lib/docs/main.js
@@ -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));
}
diff --git a/lib/docs/wasm/html_render.zig b/lib/docs/wasm/html_render.zig
index 13d2ec05c5..f88e6eb1dd 100644
--- a/lib/docs/wasm/html_render.zig
+++ b/lib/docs/wasm/html_render.zig
@@ -30,6 +30,19 @@ 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;
+ for (first_token_line..last_token_line + 1) |i| {
+ try out.print(gpa, "{d}\n", .{i + 1});
+ }
+}
+
pub fn fileSourceHtml(
file_index: Walk.File.Index,
out: *ArrayList(u8),
diff --git a/lib/docs/wasm/main.zig b/lib/docs/wasm/main.zig
index 2a093886f5..bee3e4acbc 100644
--- a/lib/docs/wasm/main.zig
+++ b/lib/docs/wasm/main.zig
@@ -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| {
+ std.debug.panic("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();