Skip to content

Commit

Permalink
fix: correct completion fallback logic when spec matches but 0 results (
Browse files Browse the repository at this point in the history
  • Loading branch information
reubeno authored Jul 16, 2024
1 parent 4ea76db commit b2cb02a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
5 changes: 5 additions & 0 deletions brush-core/src/builtins/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,20 +473,25 @@ impl builtins::Command for CompGenCommand {
/// Set programmable command completion options.
#[derive(Parser)]
pub(crate) struct CompOptCommand {
/// Update the default completion settings.
#[arg(short = 'D')]
update_default: bool,

/// Update the completion settings for empty lines.
#[arg(short = 'E')]
update_empty: bool,

/// Update the completion settings for the initial word of the input line.
#[arg(short = 'I')]
update_initial_word: bool,

/// Enable the specified option for selected completion scenarios.
#[arg(short = 'o')]
enabled_options: Vec<CompleteOption>,
#[arg(long = concat!("+o"), hide = true)]
disabled_options: Vec<CompleteOption>,

/// If specified, scopes updates to completions of the named commands.
names: Vec<String>,
}

Expand Down
14 changes: 5 additions & 9 deletions brush-core/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,18 +839,14 @@ impl Config {

// Try to generate completions.
if let Some(spec) = found_spec {
let result = spec
.to_owned()
spec.to_owned()
.get_completions(shell, &context)
.await
.unwrap_or_else(|_err| Answer::Candidates(vec![], ProcessingOptions::default()));

if !matches!(&result, Answer::Candidates(candidates, _) if candidates.is_empty()) {
return result;
}
.unwrap_or_else(|_err| Answer::Candidates(vec![], ProcessingOptions::default()))
} else {
// If we didn't find a spec, then fall back to basic completion.
get_completions_using_basic_lookup(shell, &context)
}

get_completions_using_basic_lookup(shell, &context)
}
}

Expand Down

0 comments on commit b2cb02a

Please sign in to comment.