tools: handle fn attributes/comments more robustly, when `v missdoc` is run (#14774)
							parent
							
								
									01fdd5d07f
								
							
						
					
					
						commit
						18dfaf6164
					
				| 
						 | 
					@ -62,28 +62,17 @@ fn (opt &Options) collect_undocumented_functions_in_file(nfile string) []Undocum
 | 
				
			||||||
	contents := os.read_file(file) or { panic(err) }
 | 
						contents := os.read_file(file) or { panic(err) }
 | 
				
			||||||
	lines := contents.split('\n')
 | 
						lines := contents.split('\n')
 | 
				
			||||||
	mut list := []UndocumentedFN{}
 | 
						mut list := []UndocumentedFN{}
 | 
				
			||||||
	for i, line in lines {
 | 
						mut comments := []string{}
 | 
				
			||||||
		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 tags := []string{}
 | 
				
			||||||
					mut grab := true
 | 
						for i, line in lines {
 | 
				
			||||||
					for j := i - 1; j >= 0; j-- {
 | 
							if line.starts_with('//') {
 | 
				
			||||||
						prev_line := lines[j]
 | 
								comments << line
 | 
				
			||||||
						if prev_line.contains('}') { // We've looked back to the above scope, stop here
 | 
							} else if line.trim_space().starts_with('[') {
 | 
				
			||||||
							break
 | 
								tags << collect_tags(line)
 | 
				
			||||||
						} else if prev_line.starts_with('[') {
 | 
							} else if line.starts_with('pub fn')
 | 
				
			||||||
							tags << collect_tags(prev_line)
 | 
								|| (opt.private && (line.starts_with('fn ') && !(line.starts_with('fn C.')
 | 
				
			||||||
							continue
 | 
								|| line.starts_with('fn main')))) {
 | 
				
			||||||
						} else if prev_line.starts_with('//') { // Single-line comment
 | 
								if comments.len == 0 {
 | 
				
			||||||
							grab = false
 | 
					 | 
				
			||||||
							break
 | 
					 | 
				
			||||||
						}
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
					if grab {
 | 
					 | 
				
			||||||
				clean_line := line.all_before_last(' {')
 | 
									clean_line := line.all_before_last(' {')
 | 
				
			||||||
				list << UndocumentedFN{
 | 
									list << UndocumentedFN{
 | 
				
			||||||
					line: i + 1
 | 
										line: i + 1
 | 
				
			||||||
| 
						 | 
					@ -92,8 +81,11 @@ fn (opt &Options) collect_undocumented_functions_in_file(nfile string) []Undocum
 | 
				
			||||||
					file: file
 | 
										file: file
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
				}
 | 
								tags = []
 | 
				
			||||||
			}
 | 
								comments = []
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								tags = []
 | 
				
			||||||
 | 
								comments = []
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return list
 | 
						return list
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue