vdoc: fix symbol filtering (#9210)
parent
00399b49ab
commit
114a7db6e5
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue