@@ -103,7 +103,7 @@ def find_code(
103103 pattern : str = Field (description = "The ast-grep pattern to search for. Note, the pattern must have valid AST structure." ),
104104 language : str = Field (description = f"The language of the code. Supported: { ', ' .join (get_supported_languages ())} . "
105105 "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" ),
107107 output_format : str = Field (default = "text" , description = "'text' or 'json'" ),
108108 ) -> str | List [dict [str , Any ]]:
109109 """
@@ -149,15 +149,15 @@ def another_function():
149149
150150 # Apply max_results limit to complete matches
151151 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 :
153153 matches = matches [:max_results ]
154154
155155 if output_format == "text" :
156156 if not matches :
157157 return "No matches found"
158158 text_output = format_matches_as_text (matches )
159159 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 :
161161 header += f" (showing first { max_results } of { total_matches } )"
162162 return header + ":\n \n " + text_output
163163 return matches # type: ignore[no-any-return]
@@ -166,7 +166,7 @@ def another_function():
166166 def find_code_by_rule (
167167 project_folder : str = Field (description = "The absolute path to the project folder. It must be absolute path." ),
168168 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" ),
170170 output_format : str = Field (default = "text" , description = "'text' or 'json'" ),
171171 ) -> str | List [dict [str , Any ]]:
172172 """
@@ -212,15 +212,15 @@ class SimpleView: pass
212212
213213 # Apply max_results limit to complete matches
214214 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 :
216216 matches = matches [:max_results ]
217217
218218 if output_format == "text" :
219219 if not matches :
220220 return "No matches found"
221221 text_output = format_matches_as_text (matches )
222222 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 :
224224 header += f" (showing first { max_results } of { total_matches } )"
225225 return header + ":\n \n " + text_output
226226 return matches # type: ignore[no-any-return]
0 commit comments