Extract the relevant code block based on the error information
(self, code: str, error_info: Dict)
| 146 | return {"fix_scope": "single_line", "suggested_fix": "Check if the indentation is correct"} |
| 147 | |
| 148 | def _extract_relevant_code_block(self, code: str, error_info: Dict) -> str: |
| 149 | """Extract the relevant code block based on the error information""" |
| 150 | lines = code.split("\n") |
| 151 | |
| 152 | if error_info["fix_scope"] == "single_line" and error_info["line_number"]: |
| 153 | # Single line error: return the error line and surrounding lines |
| 154 | line_num = error_info["line_number"] - 1 # Convert to 0-indexed |
| 155 | start = max(0, line_num - 5) |
| 156 | end = min(len(lines), line_num + 5) |
| 157 | return "\n".join(lines[start:end]) |
| 158 | |
| 159 | elif error_info["fix_scope"] == "function": |
| 160 | # Function level error: find the function containing the error |
| 161 | return self._extract_function_containing_line(code, error_info["line_number"]) |
| 162 | |
| 163 | elif error_info["fix_scope"] == "section": |
| 164 | # Section level error: find the animation section containing the error |
| 165 | return self._extract_animation_section(code, error_info["line_number"]) |
| 166 | |
| 167 | return code # If the scope cannot be determined, return the entire code |
| 168 | |
| 169 | def _extract_function_containing_line(self, code: str, line_number: int) -> str: |
| 170 | """Extract the function containing the specified line number""" |
no test coverage detected