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.
@@ -71,6 +76,10 @@ def parse_search_output(output: str, base_path: str) -> Dict[str, List[Tuple[int
71
76
# Normalize path separators for consistency
72
77
relative_path = normalize_file_path (relative_path )
73
78
79
+ # Truncate content if it exceeds max_line_length
80
+ if max_line_length and len (content ) > max_line_length :
81
+ content = content [:max_line_length ] + '... (truncated)'
82
+
74
83
if relative_path not in results :
75
84
results [relative_path ] = []
76
85
results [relative_path ].append ((line_number , content ))
@@ -193,7 +202,8 @@ def search(
193
202
context_lines : int = 0 ,
194
203
file_pattern : Optional [str ] = None ,
195
204
fuzzy : bool = False ,
196
- regex : bool = False
205
+ regex : bool = False ,
206
+ max_line_length : Optional [int ] = None
197
207
) -> Dict [str , List [Tuple [int , str ]]]:
198
208
"""
199
209
Execute a search using the specific strategy.
@@ -211,4 +221,3 @@ def search(
211
221
A dictionary mapping filenames to lists of (line_number, line_content) tuples.
212
222
"""
213
223
pass
214
-
0 commit comments