diff options
author | Andrew Gallant <jamslam@gmail.com> | 2023-11-21 20:04:54 -0500 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2023-11-25 15:03:53 -0500 |
commit | ebb986e767655f8c9c05a7a7e99b09236a6e8be5 (patch) | |
tree | b273a8353fc9dc660526dff2e6153f7ac4b541c6 /crates | |
parent | a2907db2de20fd33b0bf02d9bd1375da06218865 (diff) |
logging: show heuristic information and decision
When one does not provide any paths to ripgrep to search, it has to
guess between searching stdin and the current working directory. It is
possible for this guess to be wrong, and having the heuristics and the
choice in the debug logs is useful for diagnosing this.
The failure mode here is still pretty bad because you need to know to
reach for the `--debug` flag in the first place. Namely, the typical
failure mode is that ripgrep tries to search stdin while the intent is
for it to search the current working directory, and thus likely blocking
forever waiting for data on stdin.
(Arguably this is a problem with the process architecture that invokes
ripgrep. It shouldn't give ripgrep an open stdin handle that isn't
closed.)
Closes #2524
Diffstat (limited to 'crates')
-rw-r--r-- | crates/core/flags/hiargs.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/crates/core/flags/hiargs.rs b/crates/core/flags/hiargs.rs index b4e0c096..555c8bd6 100644 --- a/crates/core/flags/hiargs.rs +++ b/crates/core/flags/hiargs.rs @@ -1080,12 +1080,24 @@ impl Paths { // mode, but there really is no good way to mitigate it. It's just a // consequence of letting the user type 'rg foo' and "guessing" that // they meant to search the CWD. - let use_cwd = !grep::cli::is_readable_stdin() + let is_readable_stdin = grep::cli::is_readable_stdin(); + let use_cwd = !is_readable_stdin || state.stdin_consumed || !matches!(low.mode, Mode::Search(_)); + log::debug!( + "using heuristics to determine whether to read from \ + stdin or search ./ (\ + is_readable_stdin={is_readable_stdin}, \ + stdin_consumed={stdin_consumed}, \ + mode={mode:?})", + stdin_consumed = state.stdin_consumed, + mode = low.mode, + ); let (path, is_one_file) = if use_cwd { + log::debug!("heuristic chose to search ./"); (PathBuf::from("./"), false) } else { + log::debug!("heuristic chose to search stdin"); (PathBuf::from("-"), true) }; Ok(Paths { paths: vec![path], has_implicit_path: true, is_one_file }) |