@@ -103,7 +103,7 @@ def find_code(
103
103
pattern : str = Field (description = "The ast-grep pattern to search for. Note, the pattern must have valid AST structure." ),
104
104
language : str = Field (description = f"The language of the code. Supported: { ', ' .join (get_supported_languages ())} . "
105
105
"If not specified, will be auto-detected based on file extensions." , default = "" ),
106
- max_results : Optional [ int ] = Field (default = None , description = "Maximum results to return" ),
106
+ max_results : int = Field (default = 0 , description = "Maximum results to return" ),
107
107
output_format : str = Field (default = "text" , description = "'text' or 'json'" ),
108
108
) -> str | List [dict [str , Any ]]:
109
109
"""
@@ -149,15 +149,15 @@ def another_function():
149
149
150
150
# Apply max_results limit to complete matches
151
151
total_matches = len (matches )
152
- if max_results is not None and total_matches > max_results :
152
+ if max_results and total_matches > max_results :
153
153
matches = matches [:max_results ]
154
154
155
155
if output_format == "text" :
156
156
if not matches :
157
157
return "No matches found"
158
158
text_output = format_matches_as_text (matches )
159
159
header = f"Found { len (matches )} matches"
160
- if max_results is not None and total_matches > max_results :
160
+ if max_results and total_matches > max_results :
161
161
header += f" (showing first { max_results } of { total_matches } )"
162
162
return header + ":\n \n " + text_output
163
163
return matches # type: ignore[no-any-return]
@@ -166,7 +166,7 @@ def another_function():
166
166
def find_code_by_rule (
167
167
project_folder : str = Field (description = "The absolute path to the project folder. It must be absolute path." ),
168
168
yaml : str = Field (description = "The ast-grep YAML rule to search. It must have id, language, rule fields." ),
169
- max_results : Optional [ int ] = Field (default = None , description = "Maximum results to return" ),
169
+ max_results : int = Field (default = 0 , description = "Maximum results to return" ),
170
170
output_format : str = Field (default = "text" , description = "'text' or 'json'" ),
171
171
) -> str | List [dict [str , Any ]]:
172
172
"""
@@ -212,15 +212,15 @@ class SimpleView: pass
212
212
213
213
# Apply max_results limit to complete matches
214
214
total_matches = len (matches )
215
- if max_results is not None and total_matches > max_results :
215
+ if max_results and total_matches > max_results :
216
216
matches = matches [:max_results ]
217
217
218
218
if output_format == "text" :
219
219
if not matches :
220
220
return "No matches found"
221
221
text_output = format_matches_as_text (matches )
222
222
header = f"Found { len (matches )} matches"
223
- if max_results is not None and total_matches > max_results :
223
+ if max_results and total_matches > max_results :
224
224
header += f" (showing first { max_results } of { total_matches } )"
225
225
return header + ":\n \n " + text_output
226
226
return matches # type: ignore[no-any-return]
0 commit comments