diff --git a/tools/file_operations.py b/tools/file_operations.py index c3e4ef112dbbe..f6a2deacaba8c 100644 --- a/tools/file_operations.py +++ b/tools/file_operations.py @@ -2475,12 +2475,11 @@ class ShellFileOperations(FileOperations): limit: int, offset: int, output_mode: str, context: int) -> SearchResult: """Search for content inside files (grep-like).""" # Try ripgrep first (fast), fallback to grep (slower but works) + used_rg = False if self._has_command('rg'): + used_rg = True result = self._search_with_rg(pattern, path, file_glob, limit, offset, output_mode, context) - # rg auto-enables --multiline for \n patterns, so the line- - # oriented warning below no longer applies to this engine. - return result elif self._has_command('grep'): result = self._search_with_grep(pattern, path, file_glob, limit, offset, output_mode, context) @@ -2492,8 +2491,9 @@ class ShellFileOperations(FileOperations): ) # Zero-match steering: a 0-match result with no guidance is a dead - # turn. Probe cheaply for near-misses (wrong casing, unescaped regex - # metacharacters) and attach the finding as a warning. + # turn. Probe cheaply for near-misses (wrong casing, hidden-only + # matches, unescaped regex metacharacters) and attach the finding + # as a warning. Runs for BOTH engines. if (not result.error and result.total_count == 0 and not result.matches and not result.files and not result.counts): try: @@ -2503,6 +2503,10 @@ class ShellFileOperations(FileOperations): if hint: result.warning = hint if not result.warning else f"{result.warning} {hint}" + # rg auto-enables --multiline for \n patterns, so the line-oriented + # explanation only applies to the grep fallback engine. + if used_rg: + return result return _maybe_warn_line_oriented_newline_pattern(result, pattern) def _search_with_rg(self, pattern: str, path: str, file_glob: Optional[str],