vdoc: fix symbol filtering (#9210)

pull/9217/head
Ned Palacios 2021-03-09 19:05:50 +08:00 committed by GitHub
parent 00399b49ab
commit 114a7db6e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 14 deletions

View File

@ -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 {

View File

@ -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
}