* Introduce completion abstractions to nushell. Currently, we rely on rustyline's completion structures. By abstracting this away, we are more flexible to introduce someone elses completion engine, or our own. * Update value_shell.rs Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
27 lines
589 B
Rust
27 lines
589 B
Rust
use nu_errors::ShellError;
|
|
|
|
#[derive(Debug, Eq, PartialEq)]
|
|
pub struct Suggestion {
|
|
pub display: String,
|
|
pub replacement: String,
|
|
}
|
|
|
|
pub struct Context<'a>(pub &'a rustyline::Context<'a>);
|
|
|
|
impl<'a> AsRef<rustyline::Context<'a>> for Context<'a> {
|
|
fn as_ref(&self) -> &rustyline::Context<'a> {
|
|
self.0
|
|
}
|
|
}
|
|
|
|
pub trait Completer {
|
|
fn complete(
|
|
&self,
|
|
line: &str,
|
|
pos: usize,
|
|
ctx: &Context<'_>,
|
|
) -> Result<(usize, Vec<Suggestion>), ShellError>;
|
|
|
|
fn hint(&self, line: &str, pos: usize, ctx: &Context<'_>) -> Option<String>;
|
|
}
|