mirror of
https://github.com/nushell/nushell.git
synced 2024-10-17 15:52:50 +02:00
9f85b10fcb
The completion engine maps completion locations to spans on a line, which indicate whther to complete a command name, flag name, argument, and so on. Initial implementation is simplistic, with some rough edges, since it relies heavily on the parser's interpretation. For example du - if asking for completions, `-` is considered a positional argument by the parser, but the user is likely looking for a flag. These scenarios will be addressed in a series of progressive enhancements to the engine.
32 lines
788 B
Rust
32 lines
788 B
Rust
use rustyline::completion::FilenameCompleter;
|
|
|
|
use crate::completion::{Context, Suggestion};
|
|
|
|
pub struct Completer {
|
|
inner: FilenameCompleter,
|
|
}
|
|
|
|
impl Completer {
|
|
pub fn new() -> Completer {
|
|
Completer {
|
|
inner: FilenameCompleter::new(),
|
|
}
|
|
}
|
|
|
|
pub fn complete(&self, _ctx: &Context<'_>, partial: &str) -> Vec<Suggestion> {
|
|
let expanded = nu_parser::expand_ndots(partial);
|
|
|
|
if let Ok((_pos, pairs)) = self.inner.complete_path(&expanded, expanded.len()) {
|
|
pairs
|
|
.into_iter()
|
|
.map(|v| Suggestion {
|
|
replacement: v.replacement,
|
|
display: v.display,
|
|
})
|
|
.collect()
|
|
} else {
|
|
Vec::new()
|
|
}
|
|
}
|
|
}
|