nushell/crates/nu-completion/src/lib.rs
Andrés N. Robalino 03c9eaf005
Variable completions. (#3666)
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.
2021-06-23 19:21:39 +12:00

41 lines
1.0 KiB
Rust

pub(crate) mod command;
pub(crate) mod completer;
pub(crate) mod engine;
pub(crate) mod flag;
pub(crate) mod matchers;
pub(crate) mod path;
pub(crate) mod variable;
use nu_engine::EvaluationContext;
use nu_protocol::{SignatureRegistry, VariableRegistry};
use matchers::Matcher;
pub use completer::NuCompleter;
#[derive(Debug, Eq, PartialEq)]
pub struct Suggestion {
pub display: String,
pub replacement: String,
}
impl Suggestion {
fn new(display: impl Into<String>, replacement: impl Into<String>) -> Self {
Self {
display: display.into(),
replacement: replacement.into(),
}
}
}
pub trait CompletionContext {
fn signature_registry(&self) -> &dyn SignatureRegistry;
fn scope(&self) -> &dyn nu_parser::ParserScope;
fn source(&self) -> &EvaluationContext;
fn variable_registry(&self) -> &dyn VariableRegistry;
}
pub trait Completer<Context: CompletionContext> {
fn complete(&self, ctx: &Context, partial: &str, matcher: &dyn Matcher) -> Vec<Suggestion>;
}