Add option to show docs in source order within each file

This commit is contained in:
mtarik34b
2026-03-28 00:09:27 +01:00
parent 44bf8ba464
commit ac17852f36
3 changed files with 70 additions and 13 deletions

View File

@@ -28,7 +28,7 @@ gb_global char const *print_entity_names[Entity_Count] = {
};
gb_internal GB_COMPARE_PROC(cmp_entities_for_printing) {
gb_internal GB_COMPARE_PROC(cmp_entities_for_printing_by_kind_order) {
GB_ASSERT(a != nullptr);
GB_ASSERT(b != nullptr);
Entity *x = *cast(Entity **)a;
@@ -55,6 +55,37 @@ gb_internal GB_COMPARE_PROC(cmp_entities_for_printing) {
return res;
}
gb_internal GB_COMPARE_PROC(cmp_entities_for_printing_by_order_in_src) {
GB_ASSERT(a != nullptr);
GB_ASSERT(b != nullptr);
Entity *x = *cast(Entity **)a;
Entity *y = *cast(Entity **)b;
u64 res = 0;
if (x->pkg != y->pkg) {
if (x->pkg == nullptr) {
return -1;
}
if (y->pkg == nullptr) {
return +1;
}
res = string_compare(x->pkg->name, y->pkg->name);
if (res != 0) {
return res;
}
}
u64 sx = x->order_in_src;
u64 sy = y->order_in_src;
res = u64_cmp(sx, sy);
if (res) {
return res;
}
res = i32_cmp(x->token.pos.offset, y->token.pos.offset);
return res;
}
gb_internal GB_COMPARE_PROC(cmp_ast_package_by_name) {
GB_ASSERT(a != nullptr);
GB_ASSERT(b != nullptr);
@@ -237,18 +268,37 @@ gb_internal void print_doc_package(CheckerInfo *info, AstPackage *pkg) {
}
array_add(&entities, e);
}
array_sort(entities, cmp_entities_for_printing);
bool in_src_order = build_context.cmd_doc_flags & CmdDocFlag_InSourceOrder;
if (in_src_order) {
array_sort(entities, cmp_entities_for_printing_by_order_in_src);
} else {
array_sort(entities, cmp_entities_for_printing_by_kind_order);
}
bool show_docs = (build_context.cmd_doc_flags & CmdDocFlag_Short) == 0;
AstFile *curr_file = nullptr;
EntityKind curr_entity_kind = Entity_Invalid;
for (Entity *e : entities) {
if (curr_entity_kind != e->kind) {
if (curr_entity_kind != Entity_Invalid) {
print_doc_line(0, "");
if (in_src_order) {
if (curr_file != e->file) {
if (curr_file != nullptr) {
print_doc_line(0, "");
}
curr_file = e->file;
String filename = remove_directory_from_path(curr_file->fullpath);
print_doc_line(1, "file: %s", filename);
}
} else {
if (curr_entity_kind != e->kind) {
if (curr_entity_kind != Entity_Invalid) {
print_doc_line(0, "");
}
curr_entity_kind = e->kind;
print_doc_line(1, "%s", print_entity_names[e->kind]);
}
curr_entity_kind = e->kind;
print_doc_line(1, "%s", print_entity_names[e->kind]);
}
Ast *type_expr = nullptr;
@@ -303,7 +353,6 @@ gb_internal void print_doc_package(CheckerInfo *info, AstPackage *pkg) {
print_doc_line(2, filename);
}
}
}
gb_internal void generate_documentation(Checker *c) {