minimax: absolute dog shit edits
This commit is contained in:
@@ -11,7 +11,7 @@ def find_definition_range(source: str, symbol_path: str) -> tuple[int, int] | No
|
||||
try:
|
||||
tree = ast.parse(source)
|
||||
except SyntaxError:
|
||||
return None
|
||||
return _find_definition_range_regex(source, symbol_path)
|
||||
parts = symbol_path.split('.')
|
||||
current_nodes = tree.body
|
||||
target_node = None
|
||||
@@ -21,13 +21,11 @@ def find_definition_range(source: str, symbol_path: str) -> tuple[int, int] | No
|
||||
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)) and node.name == part:
|
||||
if i == len(parts) - 1:
|
||||
target_node = node
|
||||
found = True
|
||||
break
|
||||
else:
|
||||
if isinstance(node, ast.ClassDef):
|
||||
current_nodes = node.body
|
||||
found = True
|
||||
break
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
return None
|
||||
if target_node:
|
||||
@@ -37,6 +35,42 @@ def find_definition_range(source: str, symbol_path: str) -> tuple[int, int] | No
|
||||
return (start, target_node.end_lineno)
|
||||
return None
|
||||
|
||||
def _find_definition_range_regex(source: str, symbol_path: str) -> tuple[int, int] | None:
|
||||
import re
|
||||
parts = symbol_path.split('.')
|
||||
symbol_name = parts[-1]
|
||||
if '.' in symbol_path:
|
||||
class_name = parts[0]
|
||||
class_pattern = r'class\s+' + re.escape(class_name) + r'\s*:'
|
||||
class_match = re.search(class_pattern, source)
|
||||
if not class_match:
|
||||
return None
|
||||
class_body_start = class_match.end()
|
||||
method_pattern = r'def\s+' + re.escape(symbol_name) + r'\s*\('
|
||||
method_match = re.search(method_pattern, source[class_body_start:])
|
||||
if not method_match:
|
||||
return None
|
||||
method_line_num = source[:class_body_start + method_match.start()].count('\n') + 1
|
||||
remaining = source[class_body_start + method_match.start():]
|
||||
end_pattern = r'\n(?= def\s|\nclass\s|\Z)'
|
||||
end_match = re.search(end_pattern, remaining)
|
||||
if end_match:
|
||||
end_line = source[:class_body_start + method_match.start() + end_match.start()].count('\n') + 1
|
||||
return (method_line_num, end_line)
|
||||
return None
|
||||
else:
|
||||
func_pattern = r'def\s+' + re.escape(symbol_name) + r'\s*\('
|
||||
func_match = re.search(func_pattern, source)
|
||||
if not func_match:
|
||||
return None
|
||||
start = source[:func_match.start()].count('\n') + 1
|
||||
remaining = source[func_match.start():]
|
||||
end_match = re.search(r'\n(?=def\s|\Z)', remaining)
|
||||
if end_match:
|
||||
end = remaining[:end_match.start()].count('\n') + start
|
||||
return (start, end)
|
||||
return None
|
||||
|
||||
def shift_indentation(content: str, target_depth: int) -> str:
|
||||
"""
|
||||
Shifts and normalizes the indentation of a code block to 1-space units.
|
||||
|
||||
Reference in New Issue
Block a user