diff --git a/crates/nu-cli/src/completions/variable_completions.rs b/crates/nu-cli/src/completions/variable_completions.rs index 30796fc118..5a105a0b94 100644 --- a/crates/nu-cli/src/completions/variable_completions.rs +++ b/crates/nu-cli/src/completions/variable_completions.rs @@ -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. + 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 diff --git a/crates/nu-engine/src/lib.rs b/crates/nu-engine/src/lib.rs index 9a7eb1741e..69f18cbc03 100644 --- a/crates/nu-engine/src/lib.rs +++ b/crates/nu-engine/src/lib.rs @@ -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;