Update CommentGroup parsing for struct types

This commit is contained in:
gingerBill
2022-01-24 14:47:33 +00:00
parent 49872e40dc
commit 2554c72bb2
5 changed files with 21 additions and 3 deletions

View File

@@ -120,6 +120,8 @@ void check_struct_fields(CheckerContext *ctx, Ast *node, Slice<Entity *> *fields
ast_node(p, Field, param);
Ast *type_expr = p->type;
Type *type = nullptr;
CommentGroup *docs = p->docs;
CommentGroup *comment = p->comment;
if (type_expr != nullptr) {
type = check_type_expr(ctx, type_expr, nullptr);
@@ -156,6 +158,14 @@ void check_struct_fields(CheckerContext *ctx, Ast *node, Slice<Entity *> *fields
Entity *field = alloc_entity_field(ctx->scope, name_token, type, is_using, field_src_index);
add_entity(ctx, ctx->scope, name, field);
field->Variable.field_group_index = field_group_index;
if (j == 0) {
field->Variable.docs = docs;
}
if (j+1 == p->names.count) {
field->Variable.comment = comment;
}
array_add(&fields_array, field);
String tag = p->tag.string;
if (tag.len != 0 && !unquote_string(permanent_allocator(), &tag, 0, tag.text[0] == '`')) {

View File

@@ -185,8 +185,8 @@ struct OdinDocEntity {
OdinDocTypeIndex type;
OdinDocString init_string;
u32 reserved_for_init;
OdinDocString comment;
OdinDocString docs;
OdinDocString comment; // line comment
OdinDocString docs; // preceding comment
i32 field_group_index;
OdinDocEntityIndex foreign_library;
OdinDocString link_name;

View File

@@ -811,6 +811,12 @@ OdinDocEntityIndex odin_doc_add_entity(OdinDocWriter *w, Entity *e) {
comment = e->decl_info->comment;
docs = e->decl_info->docs;
}
if (!comment && e->kind == Entity_Variable) {
comment = e->Variable.comment;
}
if (!docs && e->kind == Entity_Variable) {
docs = e->Variable.docs;
}
String link_name = {};

View File

@@ -175,6 +175,8 @@ struct Entity {
String link_name;
String link_prefix;
String link_section;
CommentGroup *docs;
CommentGroup *comment;
bool is_foreign;
bool is_export;
} Variable;

View File

@@ -944,7 +944,7 @@ Ast *ast_field(AstFile *f, Array<Ast *> const &names, Ast *type, Ast *default_va
result->Field.default_value = default_value;
result->Field.flags = flags;
result->Field.tag = tag;
result->Field.docs = docs;
result->Field.docs = docs;
result->Field.comment = comment;
return result;
}