tools: handle fn attributes/comments more robustly, when `v missdoc` is run (#14774)
							parent
							
								
									01fdd5d07f
								
							
						
					
					
						commit
						18dfaf6164
					
				|  | @ -62,38 +62,30 @@ 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{} | ||||||
|  | 	mut comments := []string{} | ||||||
|  | 	mut tags := []string{} | ||||||
| 	for i, line in lines { | 	for i, line in lines { | ||||||
| 		if line.starts_with('pub fn') || (opt.private && (line.starts_with('fn ') | 		if line.starts_with('//') { | ||||||
| 			&& !(line.starts_with('fn C.') || line.starts_with('fn main')))) { | 			comments << line | ||||||
| 			// println('Match: $line')
 | 		} else if line.trim_space().starts_with('[') { | ||||||
| 			if i > 0 && lines.len > 0 { | 			tags << collect_tags(line) | ||||||
| 				mut line_above := lines[i - 1] | 		} else if line.starts_with('pub fn') | ||||||
| 				if !line_above.starts_with('//') { | 			|| (opt.private && (line.starts_with('fn ') && !(line.starts_with('fn C.') | ||||||
| 					mut tags := []string{} | 			|| line.starts_with('fn main')))) { | ||||||
| 					mut grab := true | 			if comments.len == 0 { | ||||||
| 					for j := i - 1; j >= 0; j-- { | 				clean_line := line.all_before_last(' {') | ||||||
| 						prev_line := lines[j] | 				list << UndocumentedFN{ | ||||||
| 						if prev_line.contains('}') { // We've looked back to the above scope, stop here
 | 					line: i + 1 | ||||||
| 							break | 					signature: clean_line | ||||||
| 						} else if prev_line.starts_with('[') { | 					tags: tags | ||||||
| 							tags << collect_tags(prev_line) | 					file: file | ||||||
| 							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 |  | ||||||
| 						} |  | ||||||
| 					} |  | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
|  | 			tags = [] | ||||||
|  | 			comments = [] | ||||||
|  | 		} else { | ||||||
|  | 			tags = [] | ||||||
|  | 			comments = [] | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	return list | 	return list | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue