From 18dfaf61649d2209a22a22207d8143f71ee836a4 Mon Sep 17 00:00:00 2001 From: wahur666 Date: Sat, 18 Jun 2022 10:02:39 +0200 Subject: [PATCH] tools: handle fn attributes/comments more robustly, when `v missdoc` is run (#14774) --- cmd/tools/vmissdoc.v | 50 +++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/cmd/tools/vmissdoc.v b/cmd/tools/vmissdoc.v index cd1d9bfa7..a2849a022 100644 --- a/cmd/tools/vmissdoc.v +++ b/cmd/tools/vmissdoc.v @@ -62,38 +62,30 @@ fn (opt &Options) collect_undocumented_functions_in_file(nfile string) []Undocum contents := os.read_file(file) or { panic(err) } lines := contents.split('\n') mut list := []UndocumentedFN{} + mut comments := []string{} + mut tags := []string{} for i, line in lines { - if line.starts_with('pub fn') || (opt.private && (line.starts_with('fn ') - && !(line.starts_with('fn C.') || line.starts_with('fn main')))) { - // println('Match: $line') - if i > 0 && lines.len > 0 { - mut line_above := lines[i - 1] - if !line_above.starts_with('//') { - mut tags := []string{} - mut grab := true - for j := i - 1; j >= 0; j-- { - prev_line := lines[j] - if prev_line.contains('}') { // We've looked back to the above scope, stop here - break - } else if prev_line.starts_with('[') { - tags << collect_tags(prev_line) - continue - } else if prev_line.starts_with('//') { // Single-line comment - grab = false - break - } - } - if grab { - clean_line := line.all_before_last(' {') - list << UndocumentedFN{ - line: i + 1 - signature: clean_line - tags: tags - file: file - } - } + if line.starts_with('//') { + comments << line + } else if line.trim_space().starts_with('[') { + tags << collect_tags(line) + } else if line.starts_with('pub fn') + || (opt.private && (line.starts_with('fn ') && !(line.starts_with('fn C.') + || line.starts_with('fn main')))) { + if comments.len == 0 { + clean_line := line.all_before_last(' {') + list << UndocumentedFN{ + line: i + 1 + signature: clean_line + tags: tags + file: file } } + tags = [] + comments = [] + } else { + tags = [] + comments = [] } } return list -- 2.30.2