diff --git a/crates/nu-cli/src/commands/keybindings.rs b/crates/nu-cli/src/commands/keybindings.rs index 469c0f96cd..a8c8053a56 100644 --- a/crates/nu-cli/src/commands/keybindings.rs +++ b/crates/nu-cli/src/commands/keybindings.rs @@ -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, ) diff --git a/crates/nu-cli/src/menus/help_completions.rs b/crates/nu-cli/src/menus/help_completions.rs index b8bdaad435..62f40b9d8d 100644 --- a/crates/nu-cli/src/menus/help_completions.rs +++ b/crates/nu-cli/src/menus/help_completions.rs @@ -18,7 +18,7 @@ impl NuHelpCompleter { //Vec<(Signature, Vec, 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::>(); - 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; diff --git a/crates/nu-cmd-dataframe/src/dataframe/stub.rs b/crates/nu-cmd-dataframe/src/dataframe/stub.rs index 2d8cfde423..58dd2996cd 100644 --- a/crates/nu-cmd-dataframe/src/dataframe/stub.rs +++ b/crates/nu-cmd-dataframe/src/dataframe/stub.rs @@ -35,7 +35,7 @@ impl Command for Dfr { &Dfr.examples(), engine_state, stack, - self.is_parser_keyword(), + self.is_keyword(), ), call.head, ) diff --git a/crates/nu-cmd-extra/src/extra/bits/bits_.rs b/crates/nu-cmd-extra/src/extra/bits/bits_.rs index 6767d3dd83..d795beda4e 100644 --- a/crates/nu-cmd-extra/src/extra/bits/bits_.rs +++ b/crates/nu-cmd-extra/src/extra/bits/bits_.rs @@ -35,7 +35,7 @@ impl Command for Bits { &Bits.examples(), engine_state, stack, - self.is_parser_keyword(), + self.is_keyword(), ), call.head, ) diff --git a/crates/nu-cmd-extra/src/extra/filters/roll/roll_.rs b/crates/nu-cmd-extra/src/extra/filters/roll/roll_.rs index 76e167a575..a1622d71c0 100644 --- a/crates/nu-cmd-extra/src/extra/filters/roll/roll_.rs +++ b/crates/nu-cmd-extra/src/extra/filters/roll/roll_.rs @@ -39,7 +39,7 @@ impl Command for Roll { &Roll.examples(), engine_state, stack, - self.is_parser_keyword(), + self.is_keyword(), ), call.head, ) diff --git a/crates/nu-cmd-extra/src/extra/strings/str_/case/str_.rs b/crates/nu-cmd-extra/src/extra/strings/str_/case/str_.rs index cf4537f046..56e0d1164f 100644 --- a/crates/nu-cmd-extra/src/extra/strings/str_/case/str_.rs +++ b/crates/nu-cmd-extra/src/extra/strings/str_/case/str_.rs @@ -35,7 +35,7 @@ impl Command for Str { &Str.examples(), engine_state, stack, - self.is_parser_keyword(), + self.is_keyword(), ), call.head, ) diff --git a/crates/nu-cmd-lang/src/core_commands/alias.rs b/crates/nu-cmd-lang/src/core_commands/alias.rs index f3603611e4..f14f4d5827 100644 --- a/crates/nu-cmd-lang/src/core_commands/alias.rs +++ b/crates/nu-cmd-lang/src/core_commands/alias.rs @@ -1,4 +1,5 @@ use nu_engine::command_prelude::*; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct Alias; @@ -29,8 +30,8 @@ impl Command for Alias { https://www.nushell.sh/book/thinking_in_nu.html"# } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn search_terms(&self) -> Vec<&str> { diff --git a/crates/nu-cmd-lang/src/core_commands/const_.rs b/crates/nu-cmd-lang/src/core_commands/const_.rs index 4076ae87c9..f780c5ada9 100644 --- a/crates/nu-cmd-lang/src/core_commands/const_.rs +++ b/crates/nu-cmd-lang/src/core_commands/const_.rs @@ -1,4 +1,5 @@ use nu_engine::command_prelude::*; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct Const; @@ -30,8 +31,8 @@ impl Command for Const { https://www.nushell.sh/book/thinking_in_nu.html"# } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn search_terms(&self) -> Vec<&str> { diff --git a/crates/nu-cmd-lang/src/core_commands/def.rs b/crates/nu-cmd-lang/src/core_commands/def.rs index 922ba78abb..eb1124da19 100644 --- a/crates/nu-cmd-lang/src/core_commands/def.rs +++ b/crates/nu-cmd-lang/src/core_commands/def.rs @@ -1,4 +1,5 @@ use nu_engine::command_prelude::*; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct Def; @@ -28,8 +29,8 @@ impl Command for Def { https://www.nushell.sh/book/thinking_in_nu.html"# } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn run( diff --git a/crates/nu-cmd-lang/src/core_commands/export.rs b/crates/nu-cmd-lang/src/core_commands/export.rs index e5d3d45683..8634a8c06b 100644 --- a/crates/nu-cmd-lang/src/core_commands/export.rs +++ b/crates/nu-cmd-lang/src/core_commands/export.rs @@ -1,4 +1,5 @@ use nu_engine::{command_prelude::*, get_full_help}; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct ExportCommand; @@ -23,8 +24,8 @@ impl Command for ExportCommand { https://www.nushell.sh/book/thinking_in_nu.html"# } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn run( @@ -40,7 +41,7 @@ impl Command for ExportCommand { &ExportCommand.examples(), engine_state, stack, - self.is_parser_keyword(), + self.is_keyword(), ), call.head, ) diff --git a/crates/nu-cmd-lang/src/core_commands/export_alias.rs b/crates/nu-cmd-lang/src/core_commands/export_alias.rs index 14caddcc7a..4df335da44 100644 --- a/crates/nu-cmd-lang/src/core_commands/export_alias.rs +++ b/crates/nu-cmd-lang/src/core_commands/export_alias.rs @@ -1,4 +1,5 @@ use nu_engine::command_prelude::*; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct ExportAlias; @@ -29,8 +30,8 @@ impl Command for ExportAlias { https://www.nushell.sh/book/thinking_in_nu.html"# } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn search_terms(&self) -> Vec<&str> { diff --git a/crates/nu-cmd-lang/src/core_commands/export_const.rs b/crates/nu-cmd-lang/src/core_commands/export_const.rs index 988db50b2a..631d85ad89 100644 --- a/crates/nu-cmd-lang/src/core_commands/export_const.rs +++ b/crates/nu-cmd-lang/src/core_commands/export_const.rs @@ -1,4 +1,5 @@ use nu_engine::command_prelude::*; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct ExportConst; @@ -30,8 +31,8 @@ impl Command for ExportConst { https://www.nushell.sh/book/thinking_in_nu.html"# } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn run( diff --git a/crates/nu-cmd-lang/src/core_commands/export_def.rs b/crates/nu-cmd-lang/src/core_commands/export_def.rs index 93c5932efb..7a2d3949e1 100644 --- a/crates/nu-cmd-lang/src/core_commands/export_def.rs +++ b/crates/nu-cmd-lang/src/core_commands/export_def.rs @@ -1,4 +1,5 @@ use nu_engine::command_prelude::*; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct ExportDef; @@ -28,8 +29,8 @@ impl Command for ExportDef { https://www.nushell.sh/book/thinking_in_nu.html"# } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn run( diff --git a/crates/nu-cmd-lang/src/core_commands/export_extern.rs b/crates/nu-cmd-lang/src/core_commands/export_extern.rs index 9ca756cf93..1a2ba4e5cb 100644 --- a/crates/nu-cmd-lang/src/core_commands/export_extern.rs +++ b/crates/nu-cmd-lang/src/core_commands/export_extern.rs @@ -1,4 +1,5 @@ use nu_engine::command_prelude::*; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct ExportExtern; @@ -25,8 +26,8 @@ impl Command for ExportExtern { https://www.nushell.sh/book/thinking_in_nu.html"# } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn run( diff --git a/crates/nu-cmd-lang/src/core_commands/export_module.rs b/crates/nu-cmd-lang/src/core_commands/export_module.rs index fdbd143fb0..53a6ca750c 100644 --- a/crates/nu-cmd-lang/src/core_commands/export_module.rs +++ b/crates/nu-cmd-lang/src/core_commands/export_module.rs @@ -1,4 +1,5 @@ use nu_engine::command_prelude::*; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct ExportModule; @@ -30,8 +31,8 @@ impl Command for ExportModule { https://www.nushell.sh/book/thinking_in_nu.html"# } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn run( diff --git a/crates/nu-cmd-lang/src/core_commands/export_use.rs b/crates/nu-cmd-lang/src/core_commands/export_use.rs index 2e4fd3f3e9..5ca96a899e 100644 --- a/crates/nu-cmd-lang/src/core_commands/export_use.rs +++ b/crates/nu-cmd-lang/src/core_commands/export_use.rs @@ -1,4 +1,5 @@ use nu_engine::command_prelude::*; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct ExportUse; @@ -29,8 +30,8 @@ impl Command for ExportUse { https://www.nushell.sh/book/thinking_in_nu.html"# } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn run( diff --git a/crates/nu-cmd-lang/src/core_commands/extern_.rs b/crates/nu-cmd-lang/src/core_commands/extern_.rs index 71400dbb7c..496f104650 100644 --- a/crates/nu-cmd-lang/src/core_commands/extern_.rs +++ b/crates/nu-cmd-lang/src/core_commands/extern_.rs @@ -1,4 +1,5 @@ use nu_engine::command_prelude::*; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct Extern; @@ -25,8 +26,8 @@ impl Command for Extern { https://www.nushell.sh/book/thinking_in_nu.html"# } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn run( diff --git a/crates/nu-cmd-lang/src/core_commands/for_.rs b/crates/nu-cmd-lang/src/core_commands/for_.rs index 6f9391614e..387af45282 100644 --- a/crates/nu-cmd-lang/src/core_commands/for_.rs +++ b/crates/nu-cmd-lang/src/core_commands/for_.rs @@ -1,4 +1,5 @@ use nu_engine::{command_prelude::*, get_eval_block, get_eval_expression}; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct For; @@ -41,8 +42,8 @@ impl Command for For { https://www.nushell.sh/book/thinking_in_nu.html"# } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn run( diff --git a/crates/nu-cmd-lang/src/core_commands/hide.rs b/crates/nu-cmd-lang/src/core_commands/hide.rs index 2cfafa6c02..d52d2131c9 100644 --- a/crates/nu-cmd-lang/src/core_commands/hide.rs +++ b/crates/nu-cmd-lang/src/core_commands/hide.rs @@ -1,4 +1,5 @@ use nu_engine::command_prelude::*; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct Hide; @@ -31,8 +32,8 @@ This command is a parser keyword. For details, check: https://www.nushell.sh/book/thinking_in_nu.html"# } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn run( diff --git a/crates/nu-cmd-lang/src/core_commands/let_.rs b/crates/nu-cmd-lang/src/core_commands/let_.rs index cc5504d8d6..f2da628c31 100644 --- a/crates/nu-cmd-lang/src/core_commands/let_.rs +++ b/crates/nu-cmd-lang/src/core_commands/let_.rs @@ -1,4 +1,5 @@ use nu_engine::{command_prelude::*, get_eval_block}; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct Let; @@ -30,8 +31,8 @@ impl Command for Let { https://www.nushell.sh/book/thinking_in_nu.html"# } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn search_terms(&self) -> Vec<&str> { diff --git a/crates/nu-cmd-lang/src/core_commands/module.rs b/crates/nu-cmd-lang/src/core_commands/module.rs index 45641649ff..908c0764e5 100644 --- a/crates/nu-cmd-lang/src/core_commands/module.rs +++ b/crates/nu-cmd-lang/src/core_commands/module.rs @@ -1,4 +1,5 @@ use nu_engine::command_prelude::*; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct Module; @@ -30,8 +31,8 @@ impl Command for Module { https://www.nushell.sh/book/thinking_in_nu.html"# } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn run( diff --git a/crates/nu-cmd-lang/src/core_commands/mut_.rs b/crates/nu-cmd-lang/src/core_commands/mut_.rs index 60c4c146db..5db3c929af 100644 --- a/crates/nu-cmd-lang/src/core_commands/mut_.rs +++ b/crates/nu-cmd-lang/src/core_commands/mut_.rs @@ -1,4 +1,5 @@ use nu_engine::{command_prelude::*, get_eval_block}; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct Mut; @@ -30,8 +31,8 @@ impl Command for Mut { https://www.nushell.sh/book/thinking_in_nu.html"# } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn search_terms(&self) -> Vec<&str> { diff --git a/crates/nu-cmd-lang/src/core_commands/overlay/command.rs b/crates/nu-cmd-lang/src/core_commands/overlay/command.rs index db502c0932..72cc28e77c 100644 --- a/crates/nu-cmd-lang/src/core_commands/overlay/command.rs +++ b/crates/nu-cmd-lang/src/core_commands/overlay/command.rs @@ -1,4 +1,5 @@ use nu_engine::{command_prelude::*, get_full_help}; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct Overlay; @@ -25,8 +26,8 @@ impl Command for Overlay { You must use one of the following subcommands. Using this command as-is will only produce this help message."# } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn run( @@ -42,7 +43,7 @@ impl Command for Overlay { &[], engine_state, stack, - self.is_parser_keyword(), + self.is_keyword(), ), call.head, ) diff --git a/crates/nu-cmd-lang/src/core_commands/overlay/hide.rs b/crates/nu-cmd-lang/src/core_commands/overlay/hide.rs index c1b4a653bc..7ea84a2a91 100644 --- a/crates/nu-cmd-lang/src/core_commands/overlay/hide.rs +++ b/crates/nu-cmd-lang/src/core_commands/overlay/hide.rs @@ -1,4 +1,5 @@ use nu_engine::command_prelude::*; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct OverlayHide; @@ -35,8 +36,8 @@ impl Command for OverlayHide { https://www.nushell.sh/book/thinking_in_nu.html"# } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn run( diff --git a/crates/nu-cmd-lang/src/core_commands/overlay/new.rs b/crates/nu-cmd-lang/src/core_commands/overlay/new.rs index 8f9a0e53ea..a571c37947 100644 --- a/crates/nu-cmd-lang/src/core_commands/overlay/new.rs +++ b/crates/nu-cmd-lang/src/core_commands/overlay/new.rs @@ -1,4 +1,5 @@ use nu_engine::command_prelude::*; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct OverlayNew; @@ -33,8 +34,8 @@ This command is a parser keyword. For details, check: https://www.nushell.sh/book/thinking_in_nu.html"# } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn run( diff --git a/crates/nu-cmd-lang/src/core_commands/overlay/use_.rs b/crates/nu-cmd-lang/src/core_commands/overlay/use_.rs index 13c3f711ad..e8b51fb59b 100644 --- a/crates/nu-cmd-lang/src/core_commands/overlay/use_.rs +++ b/crates/nu-cmd-lang/src/core_commands/overlay/use_.rs @@ -2,7 +2,7 @@ use nu_engine::{ command_prelude::*, find_in_dirs_env, get_dirs_var_from_call, get_eval_block, redirect_env, }; use nu_parser::trim_quotes_str; -use nu_protocol::ast::Expr; +use nu_protocol::{ast::Expr, engine::CommandType}; use std::path::Path; @@ -50,8 +50,8 @@ impl Command for OverlayUse { https://www.nushell.sh/book/thinking_in_nu.html"# } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn run( diff --git a/crates/nu-cmd-lang/src/core_commands/return_.rs b/crates/nu-cmd-lang/src/core_commands/return_.rs index 969456d005..478224079b 100644 --- a/crates/nu-cmd-lang/src/core_commands/return_.rs +++ b/crates/nu-cmd-lang/src/core_commands/return_.rs @@ -1,4 +1,5 @@ use nu_engine::command_prelude::*; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct Return; @@ -28,8 +29,8 @@ impl Command for Return { https://www.nushell.sh/book/thinking_in_nu.html"# } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn run( diff --git a/crates/nu-cmd-lang/src/core_commands/scope/command.rs b/crates/nu-cmd-lang/src/core_commands/scope/command.rs index da507f3159..72a9e74932 100644 --- a/crates/nu-cmd-lang/src/core_commands/scope/command.rs +++ b/crates/nu-cmd-lang/src/core_commands/scope/command.rs @@ -1,4 +1,5 @@ use nu_engine::{command_prelude::*, get_full_help}; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct Scope; @@ -19,8 +20,8 @@ impl Command for Scope { "Commands for getting info about what is in scope." } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn run( @@ -36,7 +37,7 @@ impl Command for Scope { &[], engine_state, stack, - self.is_parser_keyword(), + self.is_keyword(), ), call.head, ) diff --git a/crates/nu-cmd-lang/src/core_commands/use_.rs b/crates/nu-cmd-lang/src/core_commands/use_.rs index 32978d7e62..b0f3648304 100644 --- a/crates/nu-cmd-lang/src/core_commands/use_.rs +++ b/crates/nu-cmd-lang/src/core_commands/use_.rs @@ -1,7 +1,10 @@ use nu_engine::{ command_prelude::*, find_in_dirs_env, get_dirs_var_from_call, get_eval_block, redirect_env, }; -use nu_protocol::ast::{Expr, Expression}; +use nu_protocol::{ + ast::{Expr, Expression}, + engine::CommandType, +}; #[derive(Clone)] pub struct Use; @@ -40,8 +43,8 @@ This command is a parser keyword. For details, check: https://www.nushell.sh/book/thinking_in_nu.html"# } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn run( diff --git a/crates/nu-cmd-plugin/src/commands/plugin/mod.rs b/crates/nu-cmd-plugin/src/commands/plugin/mod.rs index 87daa5a328..cf4ee5d9a3 100644 --- a/crates/nu-cmd-plugin/src/commands/plugin/mod.rs +++ b/crates/nu-cmd-plugin/src/commands/plugin/mod.rs @@ -43,7 +43,7 @@ impl Command for PluginCommand { &PluginCommand.examples(), engine_state, stack, - self.is_parser_keyword(), + self.is_keyword(), ), call.head, ) diff --git a/crates/nu-cmd-plugin/src/commands/plugin/use_.rs b/crates/nu-cmd-plugin/src/commands/plugin/use_.rs index e5997efcf0..3cfb28f28b 100644 --- a/crates/nu-cmd-plugin/src/commands/plugin/use_.rs +++ b/crates/nu-cmd-plugin/src/commands/plugin/use_.rs @@ -1,4 +1,5 @@ use nu_engine::command_prelude::*; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct PluginUse; @@ -52,8 +53,8 @@ it was already previously registered with `plugin add`. vec!["add", "register", "scope"] } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn run( diff --git a/crates/nu-cmd-plugin/src/commands/register.rs b/crates/nu-cmd-plugin/src/commands/register.rs index 924ab00d62..2c10456db7 100644 --- a/crates/nu-cmd-plugin/src/commands/register.rs +++ b/crates/nu-cmd-plugin/src/commands/register.rs @@ -1,4 +1,5 @@ use nu_engine::command_prelude::*; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct Register; @@ -48,8 +49,8 @@ This command is a parser keyword. For details, check: vec!["add"] } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn run( diff --git a/crates/nu-command/src/bytes/bytes_.rs b/crates/nu-command/src/bytes/bytes_.rs index f262e6a82e..451ee1e5d5 100644 --- a/crates/nu-command/src/bytes/bytes_.rs +++ b/crates/nu-command/src/bytes/bytes_.rs @@ -35,7 +35,7 @@ impl Command for Bytes { &Bytes.examples(), engine_state, stack, - self.is_parser_keyword(), + self.is_keyword(), ), call.head, ) diff --git a/crates/nu-command/src/conversions/into/command.rs b/crates/nu-command/src/conversions/into/command.rs index 37bbbff02e..5a8175b298 100644 --- a/crates/nu-command/src/conversions/into/command.rs +++ b/crates/nu-command/src/conversions/into/command.rs @@ -35,7 +35,7 @@ impl Command for Into { &[], engine_state, stack, - self.is_parser_keyword(), + self.is_keyword(), ), call.head, ) diff --git a/crates/nu-command/src/debug/view.rs b/crates/nu-command/src/debug/view.rs index 38a4efc2e7..fcbc377e4b 100644 --- a/crates/nu-command/src/debug/view.rs +++ b/crates/nu-command/src/debug/view.rs @@ -35,7 +35,7 @@ impl Command for View { &View.examples(), engine_state, stack, - self.is_parser_keyword(), + self.is_keyword(), ), call.head, ) diff --git a/crates/nu-command/src/debug/view_source.rs b/crates/nu-command/src/debug/view_source.rs index 974a92e1ee..54bca55956 100644 --- a/crates/nu-command/src/debug/view_source.rs +++ b/crates/nu-command/src/debug/view_source.rs @@ -55,7 +55,7 @@ impl Command for ViewSource { } } // gets vector of positionals. - else if let Some(block_id) = decl.get_block_id() { + else if let Some(block_id) = decl.block_id() { let block = engine_state.get_block(block_id); if let Some(block_span) = block.span { let contents = engine_state.get_span_contents(block_span); diff --git a/crates/nu-command/src/env/config/config_.rs b/crates/nu-command/src/env/config/config_.rs index 30285c5c9e..948e8248b8 100644 --- a/crates/nu-command/src/env/config/config_.rs +++ b/crates/nu-command/src/env/config/config_.rs @@ -35,7 +35,7 @@ impl Command for ConfigMeta { &ConfigMeta.examples(), engine_state, stack, - self.is_parser_keyword(), + self.is_keyword(), ), call.head, ) diff --git a/crates/nu-command/src/filesystem/open.rs b/crates/nu-command/src/filesystem/open.rs index 5fb8527511..842eaa5f4c 100644 --- a/crates/nu-command/src/filesystem/open.rs +++ b/crates/nu-command/src/filesystem/open.rs @@ -172,7 +172,7 @@ impl Command for Open { match converter { Some((converter_id, ext)) => { let decl = engine_state.get_decl(converter_id); - let command_output = if let Some(block_id) = decl.get_block_id() { + let command_output = if let Some(block_id) = decl.block_id() { let block = engine_state.get_block(block_id); eval_block(engine_state, stack, block, stream) } else { diff --git a/crates/nu-command/src/filesystem/save.rs b/crates/nu-command/src/filesystem/save.rs index 1be74665b2..340ceb4f62 100644 --- a/crates/nu-command/src/filesystem/save.rs +++ b/crates/nu-command/src/filesystem/save.rs @@ -393,7 +393,7 @@ fn convert_to_extension( ) -> Result { if let Some(decl_id) = engine_state.find_decl(format!("to {extension}").as_bytes(), &[]) { let decl = engine_state.get_decl(decl_id); - if let Some(block_id) = decl.get_block_id() { + if let Some(block_id) = decl.block_id() { let block = engine_state.get_block(block_id); let eval_block = get_eval_block(engine_state); eval_block(engine_state, stack, block, input) diff --git a/crates/nu-command/src/formats/from/command.rs b/crates/nu-command/src/formats/from/command.rs index ce5987e5b1..3df3d86e2e 100644 --- a/crates/nu-command/src/formats/from/command.rs +++ b/crates/nu-command/src/formats/from/command.rs @@ -35,7 +35,7 @@ impl Command for From { &From.examples(), engine_state, stack, - self.is_parser_keyword(), + self.is_keyword(), ), call.head, ) diff --git a/crates/nu-command/src/formats/to/command.rs b/crates/nu-command/src/formats/to/command.rs index 26c9a259b6..1288c2d73b 100644 --- a/crates/nu-command/src/formats/to/command.rs +++ b/crates/nu-command/src/formats/to/command.rs @@ -35,7 +35,7 @@ impl Command for To { &To.examples(), engine_state, stack, - self.is_parser_keyword(), + self.is_keyword(), ), call.head, ) diff --git a/crates/nu-command/src/hash/hash_.rs b/crates/nu-command/src/hash/hash_.rs index e3b19624a2..fc7f58cd3b 100644 --- a/crates/nu-command/src/hash/hash_.rs +++ b/crates/nu-command/src/hash/hash_.rs @@ -35,7 +35,7 @@ impl Command for Hash { &Self.examples(), engine_state, stack, - self.is_parser_keyword(), + self.is_keyword(), ), call.head, ) diff --git a/crates/nu-command/src/help/help_commands.rs b/crates/nu-command/src/help/help_commands.rs index bc0fd92d92..2633595356 100644 --- a/crates/nu-command/src/help/help_commands.rs +++ b/crates/nu-command/src/help/help_commands.rs @@ -1,6 +1,7 @@ use crate::help::highlight_search_in_table; use nu_color_config::StyleComputer; use nu_engine::{command_prelude::*, get_full_help}; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct HelpCommands; @@ -90,9 +91,15 @@ pub fn help_commands( let output = engine_state .get_signatures_with_examples(false) .iter() - .filter(|(signature, _, _, _, _)| signature.name == name) - .map(|(signature, examples, _, _, is_parser_keyword)| { - get_full_help(signature, examples, engine_state, stack, *is_parser_keyword) + .filter(|(signature, _, _)| signature.name == name) + .map(|(signature, examples, cmd_type)| { + get_full_help( + signature, + examples, + engine_state, + stack, + cmd_type == &CommandType::Keyword, + ) }) .collect::>(); diff --git a/crates/nu-command/src/help/help_externs.rs b/crates/nu-command/src/help/help_externs.rs index 22fb4a303c..0378553463 100644 --- a/crates/nu-command/src/help/help_externs.rs +++ b/crates/nu-command/src/help/help_externs.rs @@ -1,6 +1,7 @@ use crate::help::highlight_search_in_table; use nu_color_config::StyleComputer; use nu_engine::{command_prelude::*, get_full_help, scope::ScopeData}; +use nu_protocol::engine::CommandType; #[derive(Clone)] pub struct HelpExterns; @@ -110,9 +111,15 @@ pub fn help_externs( let output = engine_state .get_signatures_with_examples(false) .iter() - .filter(|(signature, _, _, _, _)| signature.name == name) - .map(|(signature, examples, _, _, is_parser_keyword)| { - get_full_help(signature, examples, engine_state, stack, *is_parser_keyword) + .filter(|(signature, _, _)| signature.name == name) + .map(|(signature, examples, cmd_type)| { + get_full_help( + signature, + examples, + engine_state, + stack, + cmd_type == &CommandType::Keyword, + ) }) .collect::>(); diff --git a/crates/nu-command/src/math/math_.rs b/crates/nu-command/src/math/math_.rs index a4a146738f..9f230362ea 100644 --- a/crates/nu-command/src/math/math_.rs +++ b/crates/nu-command/src/math/math_.rs @@ -35,7 +35,7 @@ impl Command for MathCommand { &MathCommand.examples(), engine_state, stack, - self.is_parser_keyword(), + self.is_keyword(), ), call.head, ) diff --git a/crates/nu-command/src/misc/source.rs b/crates/nu-command/src/misc/source.rs index 798b321c6b..08a979b9f5 100644 --- a/crates/nu-command/src/misc/source.rs +++ b/crates/nu-command/src/misc/source.rs @@ -1,4 +1,5 @@ use nu_engine::{command_prelude::*, get_eval_block_with_early_return}; +use nu_protocol::engine::CommandType; /// Source a file for environment variables. #[derive(Clone)] @@ -29,8 +30,8 @@ impl Command for Source { https://www.nushell.sh/book/thinking_in_nu.html"# } - fn is_parser_keyword(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Keyword } fn run( diff --git a/crates/nu-command/src/network/http/http_.rs b/crates/nu-command/src/network/http/http_.rs index 15bc96494c..b1e8d64120 100644 --- a/crates/nu-command/src/network/http/http_.rs +++ b/crates/nu-command/src/network/http/http_.rs @@ -41,7 +41,7 @@ impl Command for Http { &Http.examples(), engine_state, stack, - self.is_parser_keyword(), + self.is_keyword(), ), call.head, ) diff --git a/crates/nu-command/src/network/url/url_.rs b/crates/nu-command/src/network/url/url_.rs index 9f795c7eab..49d55c4c6b 100644 --- a/crates/nu-command/src/network/url/url_.rs +++ b/crates/nu-command/src/network/url/url_.rs @@ -39,7 +39,7 @@ impl Command for Url { &Url.examples(), engine_state, stack, - self.is_parser_keyword(), + self.is_keyword(), ), call.head, ) diff --git a/crates/nu-command/src/path/path_.rs b/crates/nu-command/src/path/path_.rs index 19351d590a..2d1d0730fa 100644 --- a/crates/nu-command/src/path/path_.rs +++ b/crates/nu-command/src/path/path_.rs @@ -48,7 +48,7 @@ the path literal."# &PathCommand.examples(), engine_state, stack, - self.is_parser_keyword(), + self.is_keyword(), ), call.head, ) diff --git a/crates/nu-command/src/random/random_.rs b/crates/nu-command/src/random/random_.rs index 21819fa24f..16135000ea 100644 --- a/crates/nu-command/src/random/random_.rs +++ b/crates/nu-command/src/random/random_.rs @@ -39,7 +39,7 @@ impl Command for RandomCommand { &RandomCommand.examples(), engine_state, stack, - self.is_parser_keyword(), + self.is_keyword(), ), call.head, ) diff --git a/crates/nu-command/src/stor/stor_.rs b/crates/nu-command/src/stor/stor_.rs index e736fd8357..3fb6840e7d 100644 --- a/crates/nu-command/src/stor/stor_.rs +++ b/crates/nu-command/src/stor/stor_.rs @@ -35,7 +35,7 @@ impl Command for Stor { &Stor.examples(), engine_state, stack, - self.is_parser_keyword(), + self.is_keyword(), ), call.head, ) diff --git a/crates/nu-command/src/strings/format/format_.rs b/crates/nu-command/src/strings/format/format_.rs index 18159b610f..c51213e4ef 100644 --- a/crates/nu-command/src/strings/format/format_.rs +++ b/crates/nu-command/src/strings/format/format_.rs @@ -35,7 +35,7 @@ impl Command for Format { &Format.examples(), engine_state, stack, - self.is_parser_keyword(), + self.is_keyword(), ), call.head, ) diff --git a/crates/nu-command/src/strings/split/command.rs b/crates/nu-command/src/strings/split/command.rs index cb52cdb44c..0333249c2b 100644 --- a/crates/nu-command/src/strings/split/command.rs +++ b/crates/nu-command/src/strings/split/command.rs @@ -35,7 +35,7 @@ impl Command for SplitCommand { &SplitCommand.examples(), engine_state, stack, - self.is_parser_keyword(), + self.is_keyword(), ), call.head, ) diff --git a/crates/nu-command/src/strings/str_/case/str_.rs b/crates/nu-command/src/strings/str_/case/str_.rs index cf4537f046..56e0d1164f 100644 --- a/crates/nu-command/src/strings/str_/case/str_.rs +++ b/crates/nu-command/src/strings/str_/case/str_.rs @@ -35,7 +35,7 @@ impl Command for Str { &Str.examples(), engine_state, stack, - self.is_parser_keyword(), + self.is_keyword(), ), call.head, ) diff --git a/crates/nu-command/src/system/which_.rs b/crates/nu-command/src/system/which_.rs index 1244a57d99..81b6057864 100644 --- a/crates/nu-command/src/system/which_.rs +++ b/crates/nu-command/src/system/which_.rs @@ -1,5 +1,5 @@ -use log::trace; use nu_engine::{command_prelude::*, env}; +use nu_protocol::engine::CommandType; use std::{ffi::OsStr, path::Path}; #[derive(Clone)] @@ -51,14 +51,14 @@ impl Command for Which { fn entry( arg: impl Into, path: impl Into, - cmd_type: impl Into, + cmd_type: CommandType, span: Span, ) -> Value { Value::record( record! { - "command" => Value::string(arg.into(), span), - "path" => Value::string(path.into(), span), - "type" => Value::string(cmd_type.into(), span), + "command" => Value::string(arg, span), + "path" => Value::string(path, span), + "type" => Value::string(cmd_type.to_string(), span), }, span, ) @@ -66,17 +66,8 @@ fn entry( fn get_entry_in_commands(engine_state: &EngineState, name: &str, span: Span) -> Option { if let Some(decl_id) = engine_state.find_decl(name.as_bytes(), &[]) { - let cmd_type = if engine_state.get_decl(decl_id).is_custom_command() { - "custom" - } else if engine_state.get_decl(decl_id).is_alias() { - "alias" - } else { - "built-in" - }; - - trace!("Found command: {}", name); - - Some(entry(name, "", cmd_type, span)) + let decl = engine_state.get_decl(decl_id); + Some(entry(name, "", decl.command_type(), span)) } else { None } @@ -109,7 +100,7 @@ fn get_first_entry_in_path( paths: impl AsRef, ) -> Option { which::which_in(item, Some(paths), cwd) - .map(|path| entry(item, path.to_string_lossy().to_string(), "external", span)) + .map(|path| entry(item, path.to_string_lossy(), CommandType::External, span)) .ok() } @@ -132,7 +123,7 @@ fn get_all_entries_in_path( ) -> Vec { which::which_in_all(&item, Some(paths), cwd) .map(|iter| { - iter.map(|path| entry(item, path.to_string_lossy().to_string(), "external", span)) + iter.map(|path| entry(item, path.to_string_lossy(), CommandType::External, span)) .collect() }) .unwrap_or_default() diff --git a/crates/nu-engine/src/eval.rs b/crates/nu-engine/src/eval.rs index 0bc0c3727c..02feef3f38 100644 --- a/crates/nu-engine/src/eval.rs +++ b/crates/nu-engine/src/eval.rs @@ -36,10 +36,10 @@ pub fn eval_call( &decl.examples(), engine_state, caller_stack, - decl.is_parser_keyword(), + decl.is_keyword(), ); Ok(Value::string(full_help, call.head).into_pipeline_data()) - } else if let Some(block_id) = decl.get_block_id() { + } else if let Some(block_id) = decl.block_id() { let block = engine_state.get_block(block_id); let mut callee_stack = caller_stack.gather_captures(engine_state, &block.captures); diff --git a/crates/nu-engine/src/scope.rs b/crates/nu-engine/src/scope.rs index 1f5bf2a358..b6a43ca47c 100644 --- a/crates/nu-engine/src/scope.rs +++ b/crates/nu-engine/src/scope.rs @@ -111,13 +111,8 @@ impl<'e, 's> ScopeData<'e, 's> { "signatures" => self.collect_signatures(&signature, span), "usage" => Value::string(decl.usage(), span), "examples" => Value::list(examples, span), - // we can only be a is_builtin or is_custom, not both - "is_builtin" => Value::bool(!decl.is_custom_command(), span), + "type" => Value::string(decl.command_type().to_string(), span), "is_sub" => Value::bool(decl.is_sub(), span), - "is_plugin" => Value::bool(decl.is_plugin(), span), - "is_custom" => Value::bool(decl.is_custom_command(), span), - "is_keyword" => Value::bool(decl.is_parser_keyword(), span), - "is_extern" => Value::bool(decl.is_known_external(), span), "creates_scope" => Value::bool(signature.creates_scope, span), "extra_usage" => Value::string(decl.extra_usage(), span), "search_terms" => Value::string(decl.search_terms().join(", "), span), diff --git a/crates/nu-lsp/src/lib.rs b/crates/nu-lsp/src/lib.rs index 47535d9bd4..44eeeb5756 100644 --- a/crates/nu-lsp/src/lib.rs +++ b/crates/nu-lsp/src/lib.rs @@ -279,7 +279,7 @@ impl LanguageServer { match id { Id::Declaration(decl_id) => { - if let Some(block_id) = working_set.get_decl(decl_id).get_block_id() { + if let Some(block_id) = working_set.get_decl(decl_id).block_id() { let block = working_set.get_block(block_id); if let Some(span) = &block.span { for cached_file in working_set.files() { diff --git a/crates/nu-parser/src/known_external.rs b/crates/nu-parser/src/known_external.rs index d5cc1f2369..1463a3b080 100644 --- a/crates/nu-parser/src/known_external.rs +++ b/crates/nu-parser/src/known_external.rs @@ -1,5 +1,8 @@ use nu_engine::command_prelude::*; -use nu_protocol::ast::{Argument, Expr, Expression}; +use nu_protocol::{ + ast::{Argument, Expr, Expression}, + engine::CommandType, +}; #[derive(Clone)] pub struct KnownExternal { @@ -22,12 +25,8 @@ impl Command for KnownExternal { &self.usage } - fn is_known_external(&self) -> bool { - true - } - - fn is_builtin(&self) -> bool { - false + fn command_type(&self) -> CommandType { + CommandType::External } fn run( diff --git a/crates/nu-parser/src/parse_keywords.rs b/crates/nu-parser/src/parse_keywords.rs index 015873e69a..25a55c8489 100644 --- a/crates/nu-parser/src/parse_keywords.rs +++ b/crates/nu-parser/src/parse_keywords.rs @@ -1020,7 +1020,7 @@ pub fn parse_alias( } => { let cmd = working_set.get_decl(rhs_call.decl_id); - if cmd.is_parser_keyword() + if cmd.is_keyword() && !ALIASABLE_PARSER_KEYWORDS.contains(&cmd.name().as_bytes()) { working_set.error(ParseError::CantAliasKeyword( diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index fb36e8b503..61a4261d8d 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -5966,7 +5966,7 @@ pub fn discover_captures_in_expr( Expr::Bool(_) => {} Expr::Call(call) => { let decl = working_set.get_decl(call.decl_id); - if let Some(block_id) = decl.get_block_id() { + if let Some(block_id) = decl.block_id() { match seen_blocks.get(&block_id) { Some(capture_list) => { // Push captures onto the outer closure that aren't created by that outer closure diff --git a/crates/nu-plugin-engine/src/declaration.rs b/crates/nu-plugin-engine/src/declaration.rs index 7f45ce1507..d48fa39b85 100644 --- a/crates/nu-plugin-engine/src/declaration.rs +++ b/crates/nu-plugin-engine/src/declaration.rs @@ -1,6 +1,6 @@ use nu_engine::{command_prelude::*, get_eval_expression}; use nu_plugin_protocol::{CallInfo, EvaluatedCall}; -use nu_protocol::{PluginIdentity, PluginSignature}; +use nu_protocol::{engine::CommandType, PluginIdentity, PluginSignature}; use std::sync::Arc; use crate::{GetPlugin, PluginExecutionCommandContext, PluginSource}; @@ -116,8 +116,8 @@ impl Command for PluginDeclaration { ) } - fn is_plugin(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Plugin } fn plugin_identity(&self) -> Option<&PluginIdentity> { diff --git a/crates/nu-protocol/src/alias.rs b/crates/nu-protocol/src/alias.rs index 47b7e0fd9e..24448225d4 100644 --- a/crates/nu-protocol/src/alias.rs +++ b/crates/nu-protocol/src/alias.rs @@ -1,6 +1,6 @@ use crate::{ ast::{Call, Expression}, - engine::{Command, EngineState, Stack}, + engine::{Command, CommandType, EngineState, Stack}, PipelineData, ShellError, Signature, }; @@ -48,8 +48,8 @@ impl Command for Alias { }) } - fn is_alias(&self) -> bool { - true + fn command_type(&self) -> CommandType { + CommandType::Alias } fn as_alias(&self) -> Option<&Alias> { diff --git a/crates/nu-protocol/src/engine/command.rs b/crates/nu-protocol/src/engine/command.rs index 38119d6f8f..043d2a66c7 100644 --- a/crates/nu-protocol/src/engine/command.rs +++ b/crates/nu-protocol/src/engine/command.rs @@ -1,8 +1,8 @@ -use crate::{ast::Call, Alias, BlockId, Example, OutDest, PipelineData, ShellError, Signature}; - use super::{EngineState, Stack, StateWorkingSet}; +use crate::{ast::Call, Alias, BlockId, Example, OutDest, PipelineData, ShellError, Signature}; +use std::fmt::Display; -#[derive(Clone, Debug, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum CommandType { Builtin, Custom, @@ -10,7 +10,20 @@ pub enum CommandType { External, Alias, Plugin, - Other, +} + +impl Display for CommandType { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let str = match self { + CommandType::Builtin => "built-in", + CommandType::Custom => "custom", + CommandType::Keyword => "keyword", + CommandType::External => "external", + CommandType::Alias => "alias", + CommandType::Plugin => "plugin", + }; + write!(f, "{str}") + } } pub trait Command: Send + Sync + CommandClone { @@ -49,49 +62,29 @@ pub trait Command: Send + Sync + CommandClone { Vec::new() } - // This is a built-in command - fn is_builtin(&self) -> bool { - true + // Related terms to help with command search + fn search_terms(&self) -> Vec<&str> { + vec![] } - // This is a signature for a known external command - fn is_known_external(&self) -> bool { + // Whether can run in const evaluation in the parser + fn is_const(&self) -> bool { false } - // This is an alias of another command - fn is_alias(&self) -> bool { - false - } - - // Return reference to the command as Alias - fn as_alias(&self) -> Option<&Alias> { - None - } - - // This is an enhanced method to determine if a command is custom command or not - // since extern "foo" [] and def "foo" [] behaves differently - fn is_custom_command(&self) -> bool { - if self.get_block_id().is_some() { - true - } else { - self.is_known_external() - } - } - // Is a sub command fn is_sub(&self) -> bool { self.name().contains(' ') } - // Is a parser keyword (source, def, etc.) - fn is_parser_keyword(&self) -> bool { - false + // If command is a block i.e. def blah [] { }, get the block id + fn block_id(&self) -> Option { + None } - /// Is a plugin command - fn is_plugin(&self) -> bool { - false + // Return reference to the command as Alias + fn as_alias(&self) -> Option<&Alias> { + None } /// The identity of the plugin, if this is a plugin command @@ -100,38 +93,32 @@ pub trait Command: Send + Sync + CommandClone { None } - // Whether can run in const evaluation in the parser - fn is_const(&self) -> bool { - false - } - - // If command is a block i.e. def blah [] { }, get the block id - fn get_block_id(&self) -> Option { - None - } - - // Related terms to help with command search - fn search_terms(&self) -> Vec<&str> { - vec![] - } - fn command_type(&self) -> CommandType { - match ( - self.is_builtin(), - self.is_custom_command(), - self.is_parser_keyword(), - self.is_known_external(), - self.is_alias(), - self.is_plugin(), - ) { - (true, false, false, false, false, false) => CommandType::Builtin, - (true, true, false, false, false, false) => CommandType::Custom, - (true, false, true, false, false, false) => CommandType::Keyword, - (false, true, false, true, false, false) => CommandType::External, - (_, _, _, _, true, _) => CommandType::Alias, - (true, false, false, false, false, true) => CommandType::Plugin, - _ => CommandType::Other, - } + CommandType::Builtin + } + + fn is_builtin(&self) -> bool { + self.command_type() == CommandType::Builtin + } + + fn is_custom(&self) -> bool { + self.command_type() == CommandType::Custom + } + + fn is_keyword(&self) -> bool { + self.command_type() == CommandType::Keyword + } + + fn is_known_external(&self) -> bool { + self.command_type() == CommandType::External + } + + fn is_alias(&self) -> bool { + self.command_type() == CommandType::Alias + } + + fn is_plugin(&self) -> bool { + self.command_type() == CommandType::Plugin } fn pipe_redirection(&self) -> (Option, Option) { diff --git a/crates/nu-protocol/src/engine/engine_state.rs b/crates/nu-protocol/src/engine/engine_state.rs index bea49b5d6c..1948b67d43 100644 --- a/crates/nu-protocol/src/engine/engine_state.rs +++ b/crates/nu-protocol/src/engine/engine_state.rs @@ -794,7 +794,7 @@ impl EngineState { } pub fn get_signature(&self, decl: &dyn Command) -> Signature { - if let Some(block_id) = decl.get_block_id() { + if let Some(block_id) = decl.block_id() { *self.blocks[block_id].signature.clone() } else { decl.signature() @@ -814,26 +814,16 @@ impl EngineState { /// Get signatures of all commands within scope. /// - /// In addition to signatures, it returns whether each command is: - /// a) a plugin - /// b) custom + /// In addition to signatures, it returns each command's examples and type. pub fn get_signatures_with_examples( &self, include_hidden: bool, - ) -> Vec<(Signature, Vec, bool, bool, bool)> { + ) -> Vec<(Signature, Vec, CommandType)> { self.get_decls_sorted(include_hidden) .map(|(_, id)| { let decl = self.get_decl(id); - let signature = self.get_signature(decl).update_from_command(decl); - - ( - signature, - decl.examples(), - decl.is_plugin(), - decl.get_block_id().is_some(), - decl.is_parser_keyword(), - ) + (signature, decl.examples(), decl.command_type()) }) .collect() } diff --git a/crates/nu-protocol/src/pipeline/pipeline_data.rs b/crates/nu-protocol/src/pipeline/pipeline_data.rs index 0f4d1eb826..7faa4ed221 100644 --- a/crates/nu-protocol/src/pipeline/pipeline_data.rs +++ b/crates/nu-protocol/src/pipeline/pipeline_data.rs @@ -550,7 +550,7 @@ impl PipelineData { // to create the table value that will be printed in the terminal if let Some(decl_id) = engine_state.table_decl_id { let command = engine_state.get_decl(decl_id); - if command.get_block_id().is_some() { + if command.block_id().is_some() { self.write_all_and_flush(engine_state, no_newline, to_stderr) } else { let call = Call::new(Span::new(0, 0)); diff --git a/crates/nu-protocol/src/signature.rs b/crates/nu-protocol/src/signature.rs index 7f3a48cc35..70e94b35f1 100644 --- a/crates/nu-protocol/src/signature.rs +++ b/crates/nu-protocol/src/signature.rs @@ -1,6 +1,6 @@ use crate::{ ast::Call, - engine::{Command, EngineState, Stack}, + engine::{Command, CommandType, EngineState, Stack}, BlockId, PipelineData, ShellError, SyntaxShape, Type, Value, VarId, }; use serde::{Deserialize, Serialize}; @@ -703,7 +703,11 @@ impl Command for BlockCommand { }) } - fn get_block_id(&self) -> Option { + fn command_type(&self) -> CommandType { + CommandType::Custom + } + + fn block_id(&self) -> Option { Some(self.block_id) } } diff --git a/src/ide.rs b/src/ide.rs index a3474fe3b6..0a24bcd013 100644 --- a/src/ide.rs +++ b/src/ide.rs @@ -145,7 +145,7 @@ pub fn goto_def(engine_state: &mut EngineState, file_path: &str, location: &Valu match find_id(&mut working_set, file_path, &file, location) { Some((Id::Declaration(decl_id), ..)) => { let result = working_set.get_decl(decl_id); - if let Some(block_id) = result.get_block_id() { + if let Some(block_id) = result.block_id() { let block = working_set.get_block(block_id); if let Some(span) = &block.span { for file in working_set.files() {