mirror of
https://github.com/danbulant/nushell
synced 2026-06-11 18:51:07 +00:00
* Refactor all completion logic into `NuCompleter` This is the next step to improving completions. Previously, completion logic was scattered about (`FilesystemShell`, `NuCompleter`, `Helper`, and `ShellManager`). By unifying the core logic into a central location, it will be easier to take the next steps in improving completion. * Update context.rs Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
40 lines
889 B
Rust
40 lines
889 B
Rust
use nu_errors::ShellError;
|
|
|
|
use crate::context;
|
|
|
|
#[derive(Debug, Eq, PartialEq)]
|
|
pub struct Suggestion {
|
|
pub display: String,
|
|
pub replacement: String,
|
|
}
|
|
|
|
pub struct Context<'a>(&'a context::Context, &'a rustyline::Context<'a>);
|
|
|
|
impl<'a> Context<'a> {
|
|
pub fn new(a: &'a context::Context, b: &'a rustyline::Context<'a>) -> Context<'a> {
|
|
Context(a, b)
|
|
}
|
|
}
|
|
|
|
impl<'a> AsRef<context::Context> for Context<'a> {
|
|
fn as_ref(&self) -> &context::Context {
|
|
self.0
|
|
}
|
|
}
|
|
|
|
impl<'a> AsRef<rustyline::Context<'a>> for Context<'a> {
|
|
fn as_ref(&self) -> &rustyline::Context<'a> {
|
|
self.1
|
|
}
|
|
}
|
|
|
|
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>;
|
|
}
|