14
14
15
15
from ..indexing .qualified_names import normalize_file_path
16
16
17
- def parse_search_output (output : str , base_path : str ) -> Dict [str , List [Tuple [int , str ]]]:
17
+ def parse_search_output (
18
+ output : str ,
19
+ base_path : str ,
20
+ max_line_length : Optional [int ] = None
21
+ ) -> Dict [str , List [Tuple [int , str ]]]:
18
22
"""
19
23
Parse the output of command-line search tools (grep, ag, rg).
20
24
21
25
Args:
22
26
output: The raw output from the command-line tool.
23
27
base_path: The base path of the project to make file paths relative.
28
+ max_line_length: Optional maximum line length to truncate long lines.
24
29
25
30
Returns:
26
31
A dictionary where keys are file paths and values are lists of (line_number, line_content) tuples.
@@ -53,6 +58,10 @@ def parse_search_output(output: str, base_path: str) -> Dict[str, List[Tuple[int
53
58
# Normalize path separators for consistency
54
59
relative_path = normalize_file_path (relative_path )
55
60
61
+ # Truncate content if it exceeds max_line_length
62
+ if max_line_length and len (content ) > max_line_length :
63
+ content = content [:max_line_length ] + '... (truncated)'
64
+
56
65
if relative_path not in results :
57
66
results [relative_path ] = []
58
67
results [relative_path ].append ((line_number , content ))
@@ -175,7 +184,8 @@ def search(
175
184
context_lines : int = 0 ,
176
185
file_pattern : Optional [str ] = None ,
177
186
fuzzy : bool = False ,
178
- regex : bool = False
187
+ regex : bool = False ,
188
+ max_line_length : Optional [int ] = None
179
189
) -> Dict [str , List [Tuple [int , str ]]]:
180
190
"""
181
191
Execute a search using the specific strategy.
@@ -193,4 +203,3 @@ def search(
193
203
A dictionary mapping filenames to lists of (line_number, line_content) tuples.
194
204
"""
195
205
pass
196
-
0 commit comments