kikocis/auto-code-rover public
Changesets · Branches · Tags · Compare
| Changeset | 61cc3168abed61cf1fd37bddfc01df659cad9c77b1f918e925a961683b524c0a |
|---|---|
| Author | Martin Mirchev <mmirchev@comp.nus.edu.sg> · 2024-07-18 13:46 +08:00 |
| Committer | GitHub <noreply@github.com> · 2024-07-18 13:46 +08:00 |
| Parents | 9339e58b0527, 5ec8c94cffaa |
1 file changed
modified app/search/search_utils.py +8 −6
| @@ -149,6 +149,7 @@ | ||
| 149 | 149 | # (3) get top-level functions in the file (exclues functions defined in classes) |
| 150 | 150 | top_level_funcs = [] |
| 151 | 151 | |
| 152 | + function_nodes_in_class = [] | |
| 152 | 153 | for node in ast.walk(tree): |
| 153 | 154 | if isinstance(node, ast.ClassDef): |
| 154 | 155 | ## class part (1): collect class info |
| @@ -159,14 +160,15 @@ | ||
| 159 | 160 | classes.append((class_name, start_lineno, end_lineno)) |
| 160 | 161 | |
| 161 | 162 | ## class part (2): collect function info inside this class |
| 162 | - class_funcs = [ | |
| 163 | - (n.name, n.lineno, n.end_lineno) | |
| 164 | - for n in ast.walk(node) | |
| 165 | - if isinstance(n, ast.FunctionDef) | |
| 166 | - ] | |
| 163 | + class_funcs = [] | |
| 164 | + for n in ast.walk(node): | |
| 165 | + if isinstance(n, ast.FunctionDef): | |
| 166 | + class_funcs.append((n.name, n.lineno, n.end_lineno)) | |
| 167 | + function_nodes_in_class.append(n) | |
| 167 | 168 | class_to_funcs[class_name] = class_funcs |
| 168 | 169 | |
| 169 | - elif isinstance(node, ast.FunctionDef): | |
| 170 | + # top-level functions, excluding functions defined in classes | |
| 171 | + elif isinstance(node, ast.FunctionDef) and node not in function_nodes_in_class: | |
| 170 | 172 | function_name = node.name |
| 171 | 173 | start_lineno = node.lineno |
| 172 | 174 | end_lineno = node.end_lineno |