mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-15 14:34:05 +00:00
Swap code blocks for completing separator suffix resp. whole token
Mainly to make the next commit's diff smaller. Not much functional change: since file completions never have the DONT_SORT flag set, these results will be sorted, and there are no data dependencies -- unless we're overflowing the max number of completions. But in that case the whole-token completions seem more important anyway.
This commit is contained in:
parent
b46417c77b
commit
0cfc95993a
1 changed files with 38 additions and 36 deletions
|
@ -1584,43 +1584,8 @@ impl<'ctx> Completer<'ctx> {
|
|||
};
|
||||
let complete_from_start = sep_index.is_none() || !string_prefixes_string(L!("-"), s);
|
||||
|
||||
if let Some(sep_index) = sep_index {
|
||||
let sep_string = s.slice_from(sep_index + 1);
|
||||
let mut local_completions = Vec::new();
|
||||
if matches!(
|
||||
expand_string(
|
||||
sep_string.to_owned(),
|
||||
&mut local_completions,
|
||||
flags,
|
||||
self.ctx,
|
||||
None,
|
||||
)
|
||||
.result,
|
||||
ExpandResultCode::error | ExpandResultCode::overflow
|
||||
) {
|
||||
FLOGF!(complete, "Error while expanding string '%ls'", sep_string);
|
||||
}
|
||||
|
||||
// Any COMPLETE_REPLACES_TOKEN will also stomp the separator. We need to "repair" them by
|
||||
// inserting our separator and prefix.
|
||||
Self::escape_opening_brackets(&mut local_completions, s);
|
||||
Self::escape_separators(
|
||||
&mut local_completions,
|
||||
variable_override_prefix,
|
||||
self.flags.autosuggestion,
|
||||
true,
|
||||
quoted,
|
||||
);
|
||||
let prefix_with_sep = s.as_char_slice()[..sep_index + 1].into();
|
||||
for comp in &mut local_completions {
|
||||
comp.prepend_token_prefix(prefix_with_sep);
|
||||
}
|
||||
if !self.completions.extend(local_completions) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if complete_from_start {
|
||||
let mut flags = flags;
|
||||
// Don't do fuzzy matching for files if the string begins with a dash (issue #568). We could
|
||||
// consider relaxing this if there was a preceding double-dash argument.
|
||||
if string_prefixes_string(L!("-"), s) {
|
||||
|
@ -1645,6 +1610,43 @@ impl<'ctx> Completer<'ctx> {
|
|||
quoted,
|
||||
);
|
||||
}
|
||||
|
||||
let Some(sep_index) = sep_index else {
|
||||
return;
|
||||
};
|
||||
let sep_string = s.slice_from(sep_index + 1);
|
||||
let mut local_completions = Vec::new();
|
||||
if matches!(
|
||||
expand_string(
|
||||
sep_string.to_owned(),
|
||||
&mut local_completions,
|
||||
flags,
|
||||
self.ctx,
|
||||
None,
|
||||
)
|
||||
.result,
|
||||
ExpandResultCode::error | ExpandResultCode::overflow
|
||||
) {
|
||||
FLOGF!(complete, "Error while expanding string '%ls'", sep_string);
|
||||
}
|
||||
|
||||
// Any COMPLETE_REPLACES_TOKEN will also stomp the separator. We need to "repair" them by
|
||||
// inserting our separator and prefix.
|
||||
Self::escape_opening_brackets(&mut local_completions, s);
|
||||
Self::escape_separators(
|
||||
&mut local_completions,
|
||||
variable_override_prefix,
|
||||
self.flags.autosuggestion,
|
||||
true,
|
||||
quoted,
|
||||
);
|
||||
let prefix_with_sep = s.as_char_slice()[..sep_index + 1].into();
|
||||
for comp in &mut local_completions {
|
||||
comp.prepend_token_prefix(prefix_with_sep);
|
||||
}
|
||||
if !self.completions.extend(local_completions) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fn escape_separators(
|
||||
|
|
Loading…
Reference in a new issue