mirror of
https://github.com/nushell/nushell.git
synced 2025-06-06 18:16:49 +02:00
fix: custom completion for flags only if we are on the flag value
This commit is contained in:
parent
8688cdee11
commit
50cb7623ac
@ -355,21 +355,32 @@ impl NuCompleter {
|
|||||||
|
|
||||||
match arg {
|
match arg {
|
||||||
// For named arguments, check Flag
|
// For named arguments, check Flag
|
||||||
Argument::Named((name, short, _)) => {
|
Argument::Named((name, short, value)) => {
|
||||||
// Try to find matching flag (long or short)
|
if value.as_ref().is_none_or(|e| !e.span.contains(pos)) {
|
||||||
let flag = signature.get_long_flag(&name.item)
|
None
|
||||||
.or_else(|| short.as_ref().and_then(|s|
|
} else {
|
||||||
signature.get_short_flag(s.item.chars().next().unwrap_or('_'))));
|
// If we're completing the value of the flag,
|
||||||
flag.and_then(|f| f.custom_completion)
|
// search for the matching custom completion decl_id (long or short)
|
||||||
|
let flag =
|
||||||
|
signature.get_long_flag(&name.item).or_else(|| {
|
||||||
|
short.as_ref().and_then(|s| {
|
||||||
|
signature.get_short_flag(
|
||||||
|
s.item.chars().next().unwrap_or('_'),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
});
|
||||||
|
flag.and_then(|f| f.custom_completion)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// For positional arguments, check PositionalArg
|
// For positional arguments, check PositionalArg
|
||||||
Argument::Positional(_) => {
|
Argument::Positional(_) => {
|
||||||
// Find the right positional argument by index
|
// Find the right positional argument by index
|
||||||
let arg_pos = positional_arg_indices.len();
|
let arg_pos = positional_arg_indices.len();
|
||||||
signature.get_positional(arg_pos)
|
signature
|
||||||
|
.get_positional(arg_pos)
|
||||||
.and_then(|pos_arg| pos_arg.custom_completion)
|
.and_then(|pos_arg| pos_arg.custom_completion)
|
||||||
}
|
}
|
||||||
_ => None
|
_ => None,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user