mirror of
https://github.com/nushell/nushell.git
synced 2024-12-12 02:02:32 +01:00
03c9eaf005
In Nu we have variables (E.g. $var-name) and these contain `Value` types. This means we can bind to variables any structured data and column path syntax (E.g. `$variable.path.to`) allows flexibility for "querying" said structures. Here we offer completions for these. For example, in a Nushell session the variable `$nu` contains environment values among other things. If we wanted to see in the screen some environment variable (say the var `SHELL`) we do: ``` > echo $nu.env.SHELL ``` with completions we can now do: `echo $nu.env.S[\TAB]` and we get suggestions that start at the column path `$nu.env` with vars starting with the letter `S` in this case `SHELL` appears in the suggestions.
32 lines
819 B
Rust
32 lines
819 B
Rust
use crate::{Signature, Value};
|
|
use nu_source::Spanned;
|
|
use std::fmt::Debug;
|
|
|
|
pub trait VariableRegistry {
|
|
fn get_variable(&self, name: &Spanned<&str>) -> Option<Value>;
|
|
fn variables(&self) -> Vec<String>;
|
|
}
|
|
|
|
pub trait SignatureRegistry: Debug {
|
|
fn names(&self) -> Vec<String>;
|
|
fn has(&self, name: &str) -> bool;
|
|
fn get(&self, name: &str) -> Option<Signature>;
|
|
fn clone_box(&self) -> Box<dyn SignatureRegistry>;
|
|
}
|
|
|
|
impl SignatureRegistry for Box<dyn SignatureRegistry> {
|
|
fn names(&self) -> Vec<String> {
|
|
(&**self).names()
|
|
}
|
|
|
|
fn has(&self, name: &str) -> bool {
|
|
(&**self).has(name)
|
|
}
|
|
fn get(&self, name: &str) -> Option<Signature> {
|
|
(&**self).get(name)
|
|
}
|
|
fn clone_box(&self) -> Box<dyn SignatureRegistry> {
|
|
(&**self).clone_box()
|
|
}
|
|
}
|