Skip to content

Commit 956be90

Browse files
committed
refactor(search): remove max_line_length parameter from search strategies
1 parent 786ba63 commit 956be90

File tree

8 files changed

+15
-40
lines changed

8 files changed

+15
-40
lines changed

src/code_index_mcp/search/ag.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ def search(
2727
context_lines: int = 0,
2828
file_pattern: Optional[str] = None,
2929
fuzzy: bool = False,
30-
regex: bool = False,
31-
max_line_length: Optional[int] = None
30+
regex: bool = False
3231
) -> Dict[str, List[Tuple[int, str]]]:
3332
"""
3433
Execute a search using The Silver Searcher (ag).
@@ -41,7 +40,6 @@ def search(
4140
file_pattern: File pattern to filter
4241
fuzzy: Enable word boundary matching (not true fuzzy search)
4342
regex: Enable regex pattern matching
44-
max_line_length: Optional. Limit the length of lines when context_lines is used
4543
"""
4644
# ag prints line numbers and groups by file by default, which is good.
4745
# --noheading is used to be consistent with other tools' output format.
@@ -138,7 +136,7 @@ def search(
138136
if process.returncode > 1:
139137
raise RuntimeError(f"ag failed with exit code {process.returncode}: {process.stderr}")
140138

141-
return parse_search_output(process.stdout, base_path, max_line_length)
139+
return parse_search_output(process.stdout, base_path)
142140

143141
except FileNotFoundError:
144142
raise RuntimeError("'ag' (The Silver Searcher) not found. Please install it and ensure it's in your PATH.")

src/code_index_mcp/search/base.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@
1919

2020
def parse_search_output(
2121
output: str,
22-
base_path: str,
23-
max_line_length: Optional[int] = None
22+
base_path: str
2423
) -> Dict[str, List[Tuple[int, str]]]:
2524
"""
2625
Parse the output of command-line search tools (grep, ag, rg).
2726
2827
Args:
2928
output: The raw output from the command-line tool.
3029
base_path: The base path of the project to make file paths relative.
31-
max_line_length: Optional maximum line length to truncate long lines.
3230
3331
Returns:
3432
A dictionary where keys are file paths and values are lists of (line_number, line_content) tuples.
@@ -84,10 +82,6 @@ def parse_search_output(
8482
# Normalize path separators for consistency
8583
relative_path = normalize_file_path(relative_path)
8684

87-
# Truncate content if it exceeds max_line_length
88-
if max_line_length and len(content) > max_line_length:
89-
content = content[:max_line_length] + '... (truncated)'
90-
9185
if relative_path not in results:
9286
results[relative_path] = []
9387
results[relative_path].append((line_number, content))
@@ -220,8 +214,7 @@ def search(
220214
context_lines: int = 0,
221215
file_pattern: Optional[str] = None,
222216
fuzzy: bool = False,
223-
regex: bool = False,
224-
max_line_length: Optional[int] = None
217+
regex: bool = False
225218
) -> Dict[str, List[Tuple[int, str]]]:
226219
"""
227220
Execute a search using the specific strategy.

src/code_index_mcp/search/basic.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ def search(
4747
context_lines: int = 0,
4848
file_pattern: Optional[str] = None,
4949
fuzzy: bool = False,
50-
regex: bool = False,
51-
max_line_length: Optional[int] = None
50+
regex: bool = False
5251
) -> Dict[str, List[Tuple[int, str]]]:
5352
"""
5453
Execute a basic, line-by-line search.
@@ -62,7 +61,6 @@ def search(
6261
file_pattern: File pattern to filter
6362
fuzzy: Enable word boundary matching
6463
regex: Enable regex pattern matching
65-
max_line_length: Optional. Limit the length of lines when context_lines is used
6664
"""
6765
results: Dict[str, List[Tuple[int, str]]] = {}
6866

@@ -107,9 +105,6 @@ def search(
107105
for line_num, line in enumerate(f, 1):
108106
if search_regex.search(line):
109107
content = line.rstrip('\n')
110-
if max_line_length and len(content) > max_line_length:
111-
content = content[:max_line_length] + '... (truncated)'
112-
113108
if rel_path not in results:
114109
results[rel_path] = []
115110
results[rel_path].append((line_num, content))

src/code_index_mcp/search/grep.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ def search(
3232
context_lines: int = 0,
3333
file_pattern: Optional[str] = None,
3434
fuzzy: bool = False,
35-
regex: bool = False,
36-
max_line_length: Optional[int] = None
35+
regex: bool = False
3736
) -> Dict[str, List[Tuple[int, str]]]:
3837
"""
3938
Execute a search using standard grep.
@@ -46,7 +45,6 @@ def search(
4645
file_pattern: File pattern to filter
4746
fuzzy: Enable word boundary matching
4847
regex: Enable regex pattern matching
49-
max_line_length: Optional. Limit the length of lines when context_lines is used
5048
"""
5149
# -r: recursive, -n: line number
5250
cmd = ['grep', '-r', '-n']
@@ -125,7 +123,7 @@ def search(
125123
if process.returncode > 1:
126124
raise RuntimeError(f"grep failed with exit code {process.returncode}: {process.stderr}")
127125

128-
return parse_search_output(process.stdout, base_path, max_line_length)
126+
return parse_search_output(process.stdout, base_path)
129127

130128
except FileNotFoundError:
131129
raise RuntimeError("'grep' not found. Please install it and ensure it's in your PATH.")

src/code_index_mcp/search/ripgrep.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ def search(
2727
context_lines: int = 0,
2828
file_pattern: Optional[str] = None,
2929
fuzzy: bool = False,
30-
regex: bool = False,
31-
max_line_length: Optional[int] = None
30+
regex: bool = False
3231
) -> Dict[str, List[Tuple[int, str]]]:
3332
"""
3433
Execute a search using ripgrep.
@@ -41,7 +40,6 @@ def search(
4140
file_pattern: File pattern to filter
4241
fuzzy: Enable word boundary matching (not true fuzzy search)
4342
regex: Enable regex pattern matching
44-
max_line_length: Optional. Limit the length of lines when context_lines is used
4543
"""
4644
cmd = ['rg', '--line-number', '--no-heading', '--color=never', '--no-ignore']
4745

@@ -114,7 +112,7 @@ def search(
114112
if process.returncode > 1:
115113
raise RuntimeError(f"ripgrep failed with exit code {process.returncode}: {process.stderr}")
116114

117-
return parse_search_output(process.stdout, base_path, max_line_length)
115+
return parse_search_output(process.stdout, base_path)
118116

119117
except FileNotFoundError:
120118
raise RuntimeError("ripgrep (rg) not found. Please install it and ensure it's in your PATH.")

src/code_index_mcp/search/ugrep.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ def search(
2727
context_lines: int = 0,
2828
file_pattern: Optional[str] = None,
2929
fuzzy: bool = False,
30-
regex: bool = False,
31-
max_line_length: Optional[int] = None
30+
regex: bool = False
3231
) -> Dict[str, List[Tuple[int, str]]]:
3332
"""
3433
Execute a search using the 'ug' command-line tool.
@@ -41,7 +40,6 @@ def search(
4140
file_pattern: File pattern to filter
4241
fuzzy: Enable true fuzzy search (ugrep native support)
4342
regex: Enable regex pattern matching
44-
max_line_length: Optional. Limit the length of lines when context_lines is used
4543
"""
4644
if not self.is_available():
4745
return {"error": "ugrep (ug) command not found."}
@@ -115,7 +113,7 @@ def search(
115113
error_output = process.stderr.strip()
116114
return {"error": f"ugrep execution failed with code {process.returncode}", "details": error_output}
117115

118-
return parse_search_output(process.stdout, base_path, max_line_length)
116+
return parse_search_output(process.stdout, base_path)
119117

120118
except FileNotFoundError:
121119
return {"error": "ugrep (ug) command not found. Please ensure it's installed and in your PATH."}

src/code_index_mcp/server.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ def search_code_advanced(
164164
context_lines: int = 0,
165165
file_pattern: str = None,
166166
fuzzy: bool = False,
167-
regex: bool = None,
168-
max_line_length: int = None
167+
regex: bool = None
169168
) -> Dict[str, Any]:
170169
"""
171170
Search for a code pattern in the project using an advanced, fast tool.
@@ -179,7 +178,6 @@ def search_code_advanced(
179178
context_lines: Number of lines to show before and after the match.
180179
file_pattern: A glob pattern to filter files to search in
181180
(e.g., "*.py", "*.js", "test_*.py").
182-
max_line_length: Optional. Default None (no limit). Limits the length of lines when context_lines is used.
183181
All search tools now handle glob patterns consistently:
184182
- ugrep: Uses glob patterns (*.py, *.{js,ts})
185183
- ripgrep: Uses glob patterns (*.py, *.{js,ts})
@@ -208,8 +206,7 @@ def search_code_advanced(
208206
context_lines=context_lines,
209207
file_pattern=file_pattern,
210208
fuzzy=fuzzy,
211-
regex=regex,
212-
max_line_length=max_line_length
209+
regex=regex
213210
)
214211

215212
@mcp.tool()

src/code_index_mcp/services/search_service.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ def search_code( # pylint: disable=too-many-arguments
2727
context_lines: int = 0,
2828
file_pattern: Optional[str] = None,
2929
fuzzy: bool = False,
30-
regex: Optional[bool] = None,
31-
max_line_length: Optional[int] = None
30+
regex: Optional[bool] = None
3231
) -> Dict[str, Any]:
3332
"""Search for code patterns in the project."""
3433
self._require_project_setup()
@@ -62,8 +61,7 @@ def search_code( # pylint: disable=too-many-arguments
6261
context_lines=context_lines,
6362
file_pattern=file_pattern,
6463
fuzzy=fuzzy,
65-
regex=regex,
66-
max_line_length=max_line_length
64+
regex=regex
6765
)
6866
filtered = self._filter_results(results)
6967
return ResponseFormatter.search_results_response(filtered)

0 commit comments

Comments
 (0)