mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-03 15:01:16 -03:00
complete: reuse replaces_token()
This commit is contained in:
@@ -207,7 +207,7 @@ pub fn rank(&self) -> u32 {
|
||||
|
||||
/// If this completion replaces the entire token, prepend a prefix. Otherwise do nothing.
|
||||
pub fn prepend_token_prefix(&mut self, prefix: &wstr) {
|
||||
if self.flags.contains(CompleteFlags::REPLACES_TOKEN) {
|
||||
if self.replaces_token() {
|
||||
self.completion.insert_utfstr(0, prefix)
|
||||
}
|
||||
}
|
||||
@@ -2093,7 +2093,7 @@ fn escape_opening_brackets(completions: &mut [Completion], argument: &wstr) {
|
||||
return;
|
||||
};
|
||||
for comp in completions {
|
||||
if comp.flags.contains(CompleteFlags::REPLACES_TOKEN) {
|
||||
if comp.replaces_token() {
|
||||
continue;
|
||||
}
|
||||
comp.flags |= CompleteFlags::REPLACES_TOKEN;
|
||||
@@ -2128,7 +2128,7 @@ fn mark_completions_duplicating_arguments(
|
||||
let mut comp_str;
|
||||
for comp in self.completions.get_list_mut() {
|
||||
comp_str = comp.completion.clone();
|
||||
if !comp.flags.contains(CompleteFlags::REPLACES_TOKEN) {
|
||||
if !comp.replaces_token() {
|
||||
comp_str.insert_utfstr(0, prefix);
|
||||
}
|
||||
if arg_strs.binary_search(&comp_str).is_ok() {
|
||||
@@ -3000,7 +3000,7 @@ macro_rules! unique_completion_applies_as {
|
||||
let completions = do_complete(L!("cat te"), CompletionRequestOptions::default());
|
||||
assert_eq!(completions.len(), 1);
|
||||
assert_eq!(completions[0].completion, L!("stfile"));
|
||||
assert!(!(completions[0].flags.contains(CompleteFlags::REPLACES_TOKEN)));
|
||||
assert!(!completions[0].replaces_token());
|
||||
assert!(
|
||||
!(completions[0]
|
||||
.flags
|
||||
@@ -3017,7 +3017,7 @@ macro_rules! unique_completion_applies_as {
|
||||
let completions = do_complete(L!("cat testfile TE"), CompletionRequestOptions::default());
|
||||
assert_eq!(completions.len(), 1);
|
||||
assert_eq!(completions[0].completion, L!("testfile"));
|
||||
assert!(completions[0].flags.contains(CompleteFlags::REPLACES_TOKEN));
|
||||
assert!(completions[0].replaces_token());
|
||||
assert!(
|
||||
completions[0]
|
||||
.flags
|
||||
|
||||
@@ -6641,7 +6641,7 @@ fn compute_and_apply_completions(&mut self, c: ReadlineCmd) {
|
||||
fn try_insert(&mut self, c: Completion, tok: &wstr, token_range: Range<usize>) {
|
||||
// If this is a replacement completion, check that we know how to replace it, e.g. that
|
||||
// the token doesn't contain evil operators like {}.
|
||||
if !c.flags.contains(CompleteFlags::REPLACES_TOKEN) || reader_can_replace(tok, c.flags) {
|
||||
if !c.replaces_token() || reader_can_replace(tok, c.flags) {
|
||||
self.completion_insert(
|
||||
&c.completion,
|
||||
token_range.end,
|
||||
@@ -6693,7 +6693,7 @@ fn handle_completions(&mut self, token_range: Range<usize>, comp: Vec<Completion
|
||||
// rank do not require replacement, then ignore all those that want to use replacement.
|
||||
let mut will_replace_token = true;
|
||||
for c in comp {
|
||||
if c.rank() <= best_rank && !c.flags.contains(CompleteFlags::REPLACES_TOKEN) {
|
||||
if c.rank() <= best_rank && !c.replaces_token() {
|
||||
will_replace_token = false;
|
||||
break;
|
||||
}
|
||||
@@ -6710,9 +6710,9 @@ fn handle_completions(&mut self, token_range: Range<usize>, comp: Vec<Completion
|
||||
}
|
||||
|
||||
// Only use completions that match replace_token.
|
||||
let completion_replaces_token = c.flags.contains(CompleteFlags::REPLACES_TOKEN);
|
||||
let completion_replaces_token = c.replaces_token();
|
||||
let replaces_only_due_to_case_mismatch = {
|
||||
c.flags.contains(CompleteFlags::REPLACES_TOKEN)
|
||||
completion_replaces_token
|
||||
&& c.r#match.is_exact_or_prefix()
|
||||
&& !matches!(c.r#match.case_fold, CaseSensitivity::Sensitive)
|
||||
};
|
||||
|
||||
@@ -1002,8 +1002,7 @@ fn try_add_completion_result(
|
||||
// Note that prepend_token_prefix is a no-op unless COMPLETE_REPLACES_TOKEN is set
|
||||
let after = self.resolved_completions.len();
|
||||
for c in self.resolved_completions[before..after].iter_mut() {
|
||||
if info.has_fuzzy_ancestor && !(c.flags.contains(CompleteFlags::REPLACES_TOKEN))
|
||||
{
|
||||
if info.has_fuzzy_ancestor && !c.replaces_token() {
|
||||
c.flags |= CompleteFlags::REPLACES_TOKEN;
|
||||
c.prepend_token_prefix(wildcard);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user