forked from extern/nushell
nu-cli/completions: added completion for $nu (#5303)
This commit is contained in:
parent
cc78446ffd
commit
b9eb213f36
@ -1,8 +1,10 @@
|
||||
use crate::completions::Completer;
|
||||
use nu_engine::eval_variable;
|
||||
use nu_protocol::{
|
||||
engine::{EngineState, Stack, StateWorkingSet},
|
||||
Span, Value,
|
||||
};
|
||||
|
||||
use reedline::Suggestion;
|
||||
use std::sync::Arc;
|
||||
|
||||
@ -65,6 +67,48 @@ impl Completer for VariableCompletion {
|
||||
return output;
|
||||
}
|
||||
|
||||
// Completions for $nu.<tab>
|
||||
if var_str.as_str() == "$nu" {
|
||||
// Eval nu var
|
||||
if let Ok(nuval) = eval_variable(
|
||||
&self.engine_state,
|
||||
&self.stack,
|
||||
nu_protocol::NU_VARIABLE_ID,
|
||||
nu_protocol::Span {
|
||||
start: current_span.start,
|
||||
end: current_span.end,
|
||||
},
|
||||
) {
|
||||
// Find recursively the values for sublevels
|
||||
// if no sublevels are set it returns the current value
|
||||
let value = recursive_value(nuval, self.var_context.1.clone());
|
||||
|
||||
match value {
|
||||
Value::Record {
|
||||
cols,
|
||||
vals: _,
|
||||
span: _,
|
||||
} => {
|
||||
// Add all the columns as completion
|
||||
for item in cols {
|
||||
output.push(Suggestion {
|
||||
value: item,
|
||||
description: None,
|
||||
extra: None,
|
||||
span: current_span,
|
||||
});
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
_ => {
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Completion other variable types
|
||||
if let Some(var_id) = var_id {
|
||||
// Extract the variable value from the stack
|
||||
|
@ -11,6 +11,6 @@ pub use documentation::get_full_help;
|
||||
pub use env::*;
|
||||
pub use eval::{
|
||||
eval_block, eval_call, eval_expression, eval_expression_with_input, eval_operator,
|
||||
eval_subexpression,
|
||||
eval_subexpression, eval_variable,
|
||||
};
|
||||
pub use glob_from::glob_from;
|
||||
|
Loading…
Reference in New Issue
Block a user