Use CommandType in more places (#12832)

# Description
Kind of a vague title, but this PR does two main things:
1. Rather than overriding functions like `Command::is_parser_keyword`,
this PR instead changes commands to override `Command::command_type`.
The `CommandType` returned by `Command::command_type` is then used to
automatically determine whether `Command::is_parser_keyword` and the
other `is_{type}` functions should return true. These changes allow us
to remove the `CommandType::Other` case and should also guarantee than
only one of the `is_{type}` functions on `Command` will return true.
2. Uses the new, reworked `Command::command_type` function in the `scope
commands` and `which` commands.


# User-Facing Changes
- Breaking change for `scope commands`: multiple columns (`is_builtin`,
`is_keyword`, `is_plugin`, etc.) have been merged into the `type`
column.
- Breaking change: the `which` command can now report `plugin` or
`keyword` instead of `built-in` in the `type` column. It may also now
report `external` instead of `custom` in the `type` column for known
`extern`s.
This commit is contained in:
Ian Manske
2024-05-18 23:37:31 +00:00
committed by GitHub
parent 580c60bb82
commit cc9f41e553
68 changed files with 224 additions and 217 deletions

View File

@ -42,7 +42,7 @@ For more information on input and keybindings, check:
&Keybindings.examples(),
engine_state,
stack,
self.is_parser_keyword(),
self.is_keyword(),
),
call.head,
)

View File

@ -18,7 +18,7 @@ impl NuHelpCompleter {
//Vec<(Signature, Vec<Example>, bool, bool)> {
let mut commands = full_commands
.iter()
.filter(|(sig, _, _, _, _)| {
.filter(|(sig, _, _)| {
sig.name.to_folded_case().contains(&folded_line)
|| sig.usage.to_folded_case().contains(&folded_line)
|| sig
@ -29,7 +29,7 @@ impl NuHelpCompleter {
})
.collect::<Vec<_>>();
commands.sort_by(|(a, _, _, _, _), (b, _, _, _, _)| {
commands.sort_by(|(a, _, _), (b, _, _)| {
let a_distance = levenshtein_distance(line, &a.name);
let b_distance = levenshtein_distance(line, &b.name);
a_distance.cmp(&b_distance)
@ -37,7 +37,7 @@ impl NuHelpCompleter {
commands
.into_iter()
.map(|(sig, examples, _, _, _)| {
.map(|(sig, examples, _)| {
let mut long_desc = String::new();
let usage = &sig.usage;