Add parser keyword note to help and $nu.scope (#4978)

This commit is contained in:
Jakub Žádník 2022-03-26 21:22:45 +02:00 committed by GitHub
parent 79e4d35f01
commit 3484e0defd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 200 additions and 9 deletions

View File

@ -25,6 +25,15 @@ impl Command for Alias {
.category(Category::Core) .category(Category::Core)
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check
https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"#
}
fn is_parser_keyword(&self) -> bool {
true
}
fn run( fn run(
&self, &self,
_engine_state: &EngineState, _engine_state: &EngineState,

View File

@ -26,6 +26,15 @@ impl Command for Def {
.category(Category::Core) .category(Category::Core)
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check
https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"#
}
fn is_parser_keyword(&self) -> bool {
true
}
fn run( fn run(
&self, &self,
_engine_state: &EngineState, _engine_state: &EngineState,

View File

@ -26,6 +26,15 @@ impl Command for DefEnv {
.category(Category::Core) .category(Category::Core)
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check
https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"#
}
fn is_parser_keyword(&self) -> bool {
true
}
fn run( fn run(
&self, &self,
_engine_state: &EngineState, _engine_state: &EngineState,

View File

@ -21,6 +21,15 @@ impl Command for ExportCommand {
"Export custom commands or environment variables from a module." "Export custom commands or environment variables from a module."
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check
https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"#
}
fn is_parser_keyword(&self) -> bool {
true
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -25,6 +25,15 @@ impl Command for ExportAlias {
.category(Category::Core) .category(Category::Core)
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check
https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"#
}
fn is_parser_keyword(&self) -> bool {
true
}
fn run( fn run(
&self, &self,
_engine_state: &EngineState, _engine_state: &EngineState,

View File

@ -26,6 +26,15 @@ impl Command for ExportDef {
.category(Category::Core) .category(Category::Core)
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check
https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"#
}
fn is_parser_keyword(&self) -> bool {
true
}
fn run( fn run(
&self, &self,
_engine_state: &EngineState, _engine_state: &EngineState,

View File

@ -26,6 +26,15 @@ impl Command for ExportDefEnv {
.category(Category::Core) .category(Category::Core)
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check
https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"#
}
fn is_parser_keyword(&self) -> bool {
true
}
fn run( fn run(
&self, &self,
_engine_state: &EngineState, _engine_state: &EngineState,

View File

@ -29,6 +29,15 @@ impl Command for ExportEnv {
.category(Category::Core) .category(Category::Core)
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check
https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"#
}
fn is_parser_keyword(&self) -> bool {
true
}
fn run( fn run(
&self, &self,
_engine_state: &EngineState, _engine_state: &EngineState,

View File

@ -21,6 +21,15 @@ impl Command for ExportExtern {
.category(Category::Core) .category(Category::Core)
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check
https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"#
}
fn is_parser_keyword(&self) -> bool {
true
}
fn run( fn run(
&self, &self,
_engine_state: &EngineState, _engine_state: &EngineState,

View File

@ -21,6 +21,15 @@ impl Command for Extern {
.category(Category::Core) .category(Category::Core)
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check
https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"#
}
fn is_parser_keyword(&self) -> bool {
true
}
fn run( fn run(
&self, &self,
_engine_state: &EngineState, _engine_state: &EngineState,

View File

@ -44,6 +44,15 @@ impl Command for For {
.category(Category::Core) .category(Category::Core)
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check
https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"#
}
fn is_parser_keyword(&self) -> bool {
true
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -85,16 +85,19 @@ fn help(
let find: Option<Spanned<String>> = call.get_flag(engine_state, stack, "find")?; let find: Option<Spanned<String>> = call.get_flag(engine_state, stack, "find")?;
let rest: Vec<Spanned<String>> = call.rest(engine_state, stack, 0)?; let rest: Vec<Spanned<String>> = call.rest(engine_state, stack, 0)?;
let full_commands = engine_state.get_signatures_with_examples(false); let commands = engine_state.get_decl_ids_sorted(false);
if let Some(f) = find { if let Some(f) = find {
let search_string = f.item.to_lowercase(); let search_string = f.item.to_lowercase();
let mut found_cmds_vec = Vec::new(); let mut found_cmds_vec = Vec::new();
for (sig, _, is_plugin, is_custom) in full_commands { for decl_id in commands {
let mut cols = vec![]; let mut cols = vec![];
let mut vals = vec![]; let mut vals = vec![];
let decl = engine_state.get_decl(decl_id);
let sig = decl.signature();
let key = sig.name.clone(); let key = sig.name.clone();
let c = sig.usage.clone(); let c = sig.usage.clone();
let e = sig.extra_usage.clone(); let e = sig.extra_usage.clone();
@ -116,13 +119,19 @@ fn help(
cols.push("is_plugin".into()); cols.push("is_plugin".into());
vals.push(Value::Bool { vals.push(Value::Bool {
val: is_plugin, val: decl.is_plugin().is_some(),
span: head, span: head,
}); });
cols.push("is_custom".into()); cols.push("is_custom".into());
vals.push(Value::Bool { vals.push(Value::Bool {
val: is_custom, val: decl.get_block_id().is_some(),
span: head,
});
cols.push("is_keyword".into());
vals.push(Value::Bool {
val: decl.is_parser_keyword(),
span: head, span: head,
}); });
@ -149,10 +158,13 @@ fn help(
let mut found_cmds_vec = Vec::new(); let mut found_cmds_vec = Vec::new();
if rest[0].item == "commands" { if rest[0].item == "commands" {
for (sig, _, is_plugin, is_custom) in full_commands { for decl_id in commands {
let mut cols = vec![]; let mut cols = vec![];
let mut vals = vec![]; let mut vals = vec![];
let decl = engine_state.get_decl(decl_id);
let sig = decl.signature();
let key = sig.name.clone(); let key = sig.name.clone();
let c = sig.usage.clone(); let c = sig.usage.clone();
let e = sig.extra_usage.clone(); let e = sig.extra_usage.clone();
@ -171,13 +183,19 @@ fn help(
cols.push("is_plugin".into()); cols.push("is_plugin".into());
vals.push(Value::Bool { vals.push(Value::Bool {
val: is_plugin, val: decl.is_plugin().is_some(),
span: head, span: head,
}); });
cols.push("is_custom".into()); cols.push("is_custom".into());
vals.push(Value::Bool { vals.push(Value::Bool {
val: is_custom, val: decl.get_block_id().is_some(),
span: head,
});
cols.push("is_keyword".into());
vals.push(Value::Bool {
val: decl.is_parser_keyword(),
span: head, span: head,
}); });
@ -207,7 +225,8 @@ fn help(
name.push_str(&r.item); name.push_str(&r.item);
} }
let output = full_commands let output = engine_state
.get_signatures_with_examples(false)
.iter() .iter()
.filter(|(signature, _, _, _)| signature.name == name) .filter(|(signature, _, _, _)| signature.name == name)
.map(|(signature, examples, _, _)| { .map(|(signature, examples, _, _)| {

View File

@ -23,7 +23,15 @@ impl Command for Hide {
} }
fn extra_usage(&self) -> &str { fn extra_usage(&self) -> &str {
"Symbols are hidden by priority: First aliases, then custom commands, then environment variables." r#"Symbols are hidden by priority: First aliases, then custom commands, then environment variables.
This command is a parser keyword. For details, check
https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages
"#
}
fn is_parser_keyword(&self) -> bool {
true
} }
fn run( fn run(

View File

@ -34,6 +34,15 @@ impl Command for If {
.category(Category::Core) .category(Category::Core)
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check
https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"#
}
fn is_parser_keyword(&self) -> bool {
true
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -26,6 +26,15 @@ impl Command for Let {
.category(Category::Core) .category(Category::Core)
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check
https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"#
}
fn is_parser_keyword(&self) -> bool {
true
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -25,6 +25,15 @@ impl Command for Module {
.category(Category::Core) .category(Category::Core)
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check
https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"#
}
fn is_parser_keyword(&self) -> bool {
true
}
fn run( fn run(
&self, &self,
_engine_state: &EngineState, _engine_state: &EngineState,

View File

@ -41,6 +41,15 @@ impl Command for Register {
.category(Category::Core) .category(Category::Core)
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check
https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"#
}
fn is_parser_keyword(&self) -> bool {
true
}
fn run( fn run(
&self, &self,
_engine_state: &EngineState, _engine_state: &EngineState,

View File

@ -26,6 +26,15 @@ impl Command for Source {
"Runs a script file in the current context." "Runs a script file in the current context."
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check
https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"#
}
fn is_parser_keyword(&self) -> bool {
true
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -23,6 +23,15 @@ impl Command for Use {
.category(Category::Core) .category(Category::Core)
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check
https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"#
}
fn is_parser_keyword(&self) -> bool {
true
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -1002,6 +1002,12 @@ pub fn create_scope(
span, span,
}); });
cols.push("is_keyword".into());
vals.push(Value::Bool {
val: decl.is_parser_keyword(),
span,
});
cols.push("is_extern".to_string()); cols.push("is_extern".to_string());
vals.push(Value::Bool { vals.push(Value::Bool {
val: decl.is_known_external(), val: decl.is_known_external(),

View File

@ -46,6 +46,11 @@ pub trait Command: Send + Sync + CommandClone {
self.name().contains(' ') self.name().contains(' ')
} }
// Is a parser keyword (source, def, etc.)
fn is_parser_keyword(&self) -> bool {
false
}
// Is a plugin command (returns plugin's path, encoding and type of shell // Is a plugin command (returns plugin's path, encoding and type of shell
// if the declaration is a plugin) // if the declaration is a plugin)
fn is_plugin(&self) -> Option<(&PathBuf, &str, &Option<PathBuf>)> { fn is_plugin(&self) -> Option<(&PathBuf, &str, &Option<PathBuf>)> {