vdoc: add attributes to enums and structs (#20957)

This commit is contained in:
Glenn Lewis 2024-03-04 04:19:22 -05:00 committed by GitHub
parent 293dd36f92
commit ddf1ae9115
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 60 additions and 0 deletions

View File

@ -242,6 +242,14 @@ pub fn (mut d Doc) stmt(mut stmt ast.Stmt, filename string) !DocNode {
}
}
}
for sa in stmt.attrs {
node.attrs[sa.name] = if sa.has_at {
'@[${sa.str()}]'
} else {
'[${sa.str()}]'
}
node.tags << node.attrs[sa.name]
}
}
ast.InterfaceDecl {
node.kind = .interface_
@ -264,6 +272,14 @@ pub fn (mut d Doc) stmt(mut stmt ast.Stmt, filename string) !DocNode {
}
}
}
for sa in stmt.attrs {
node.attrs[sa.name] = if sa.has_at {
'@[${sa.str()}]'
} else {
'[${sa.str()}]'
}
node.tags << node.attrs[sa.name]
}
}
ast.TypeDecl {
node.kind = .typedef

View File

@ -16,3 +16,47 @@ fn test_generate_from_mod() {
assert nested_mod_doc.contents.len == 3
assert nested_mod_doc.contents['ChunkScanner'].children.len == 3
}
fn test_tags_with_flag_struct_attribute() {
mod_name := 'gg'
mod_doc := doc.generate_from_mod(mod_name, false, true) or {
eprintln(err)
assert false
doc.Doc{}
}
assert mod_doc.head.name == mod_name
mouse_buttons := mod_doc.contents['MouseButtons']!
assert mouse_buttons.content == '@[flag]
pub enum MouseButtons {
left
right
middle
}'
assert mouse_buttons.attrs == {
'flag': '@[flag]'
}
assert mouse_buttons.tags == ['@[flag]']
end_options := mod_doc.contents['EndOptions']
assert end_options.content == '@[params]
pub struct EndOptions {
how EndEnum
}'
assert end_options.attrs == {
'params': '@[params]'
}
assert end_options.tags == ['@[params]']
pipeline_container := mod_doc.contents['PipelineContainer']
assert pipeline_container.content == '@[heap]
pub struct PipelineContainer {
pub mut:
alpha sgl.Pipeline
add sgl.Pipeline
}'
assert pipeline_container.attrs == {
'heap': '@[heap]'
}
assert pipeline_container.tags == ['@[heap]']
}