From 114a7db6e53c613bd43a446b3080162af538d4b4 Mon Sep 17 00:00:00 2001 From: Ned Palacios <7358345+nedpals@users.noreply.github.com> Date: Tue, 9 Mar 2021 19:05:50 +0800 Subject: [PATCH] vdoc: fix symbol filtering (#9210) --- cmd/tools/vdoc/vdoc.v | 13 ++++--------- vlib/v/doc/doc.v | 16 +++++++++++----- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/cmd/tools/vdoc/vdoc.v b/cmd/tools/vdoc/vdoc.v index c1144f52a4..dcc0e2bf5b 100644 --- a/cmd/tools/vdoc/vdoc.v +++ b/cmd/tools/vdoc/vdoc.v @@ -292,7 +292,7 @@ fn (mut vd VDoc) generate_docs_from_file() { exit(1) } } else { - dcs = doc.generate(dirpath, cfg.pub_only, true) or { + dcs = doc.generate(dirpath, cfg.pub_only, true, cfg.symbol_name) or { vd.emit_generate_err(err) exit(1) } @@ -316,13 +316,6 @@ fn (mut vd VDoc) generate_docs_from_file() { } } } - if !cfg.is_multi && cfg.symbol_name.len > 0 { - if cfg.symbol_name in dcs.contents { - for _, c in dcs.contents[cfg.symbol_name].children { - dcs.contents[c.name] = c - } - } - } } vd.docs << dcs } @@ -449,7 +442,9 @@ fn parse_arguments(args []string) Config { else { if cfg.input_path.len < 1 { cfg.input_path = arg - } else { + } else if !cfg.is_multi { + // Symbol name filtering should not be enabled + // in multi-module documentation mode. cfg.symbol_name = arg } if i == args.len - 1 { diff --git a/vlib/v/doc/doc.v b/vlib/v/doc/doc.v index 4e4086cb20..fc3d55e300 100644 --- a/vlib/v/doc/doc.v +++ b/vlib/v/doc/doc.v @@ -63,10 +63,11 @@ pub mut: contents map[string]DocNode scoped_contents map[string]DocNode // for storing the contents of the file. - sources map[string]string - parent_mod_name string - orig_mod_name string - extract_vars bool + sources map[string]string + parent_mod_name string + orig_mod_name string + extract_vars bool + filter_symbol_names []string } pub struct DocPos { @@ -230,6 +231,10 @@ pub fn (mut d Doc) stmt(stmt ast.Stmt, filename string) ?DocNode { return error('invalid stmt type to document') } } + included := node.name in d.filter_symbol_names || node.parent_name in d.filter_symbol_names + if d.filter_symbol_names.len != 0 && !included { + return error('not included in the list of symbol names') + } return node } @@ -428,10 +433,11 @@ pub fn (mut d Doc) file_asts(file_asts []ast.File) ? { // generate documents a certain file directory and returns an // instance of `Doc` if it is successful. Otherwise, it will throw an error. -pub fn generate(input_path string, pub_only bool, with_comments bool) ?Doc { +pub fn generate(input_path string, pub_only bool, with_comments bool, filter_symbol_names ...string) ?Doc { mut doc := new(input_path) doc.pub_only = pub_only doc.with_comments = with_comments + doc.filter_symbol_names = filter_symbol_names.filter(it.len != 0) doc.generate() ? return doc }