Skip to content

Commit

Permalink
CwdAwareHinter: remove cwd filter when there are no results
Browse files Browse the repository at this point in the history
  • Loading branch information
p00f committed Nov 7, 2023
1 parent c853d71 commit 4190932
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/hinter/cwd_aware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Hinter for CwdAwareHinter {
use_ansi_coloring: bool,
) -> String {
self.current_hint = if line.chars().count() >= self.min_chars {
history
let with_cwd = history

Check warning on line 27 in src/hinter/cwd_aware.rs

View check run for this annotation

Codecov / codecov/patch

src/hinter/cwd_aware.rs#L27

Added line #L27 was not covered by tests
.search(SearchQuery::last_with_prefix_and_cwd(
line.to_string(),
history.session(),
Expand All @@ -39,15 +39,29 @@ impl Hinter for CwdAwareHinter {
Err(err)
}
})
.expect("todo: error handling")
.get(0)
.map_or_else(String::new, |entry| {
entry
.command_line
.get(line.len()..)
.unwrap_or_default()
.to_string()
})
.expect("todo: error handling");
if !with_cwd.is_empty() {
with_cwd[0]
.command_line
.get(line.len()..)
.unwrap_or_default()
.to_string()

Check warning on line 48 in src/hinter/cwd_aware.rs

View check run for this annotation

Codecov / codecov/patch

src/hinter/cwd_aware.rs#L42-L48

Added lines #L42 - L48 were not covered by tests
} else {
history
.search(SearchQuery::last_with_prefix(
line.to_string(),
history.session(),
))
.expect("todo: error handling")
.get(0)
.map_or_else(String::new, |entry| {
entry
.command_line
.get(line.len()..)
.unwrap_or_default()
.to_string()
})

Check warning on line 63 in src/hinter/cwd_aware.rs

View check run for this annotation

Codecov / codecov/patch

src/hinter/cwd_aware.rs#L50-L63

Added lines #L50 - L63 were not covered by tests
}
} else {
String::new()
};
Expand Down

0 comments on commit 4190932

Please sign in to comment.