From ddf1ae911529159c76e0a95a72fd762c9c49abc0 Mon Sep 17 00:00:00 2001 From: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> Date: Mon, 4 Mar 2024 04:19:22 -0500 Subject: [PATCH] vdoc: add attributes to enums and structs (#20957) --- vlib/v/doc/doc.v | 16 ++++++++++++++++ vlib/v/doc/doc_test.v | 44 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/vlib/v/doc/doc.v b/vlib/v/doc/doc.v index 0f0332ae44..652010775c 100644 --- a/vlib/v/doc/doc.v +++ b/vlib/v/doc/doc.v @@ -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 diff --git a/vlib/v/doc/doc_test.v b/vlib/v/doc/doc_test.v index 7e6cd126ea..73ec7f27b4 100644 --- a/vlib/v/doc/doc_test.v +++ b/vlib/v/doc/doc_test.v @@ -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]'] +}