mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 19:07:42 +02:00
Add back command completions
This commit is contained in:
@ -1,10 +1,11 @@
|
||||
use crate::prelude::*;
|
||||
use derive_new::new;
|
||||
use rustyline::completion::{Completer, FilenameCompleter};
|
||||
|
||||
#[derive(new)]
|
||||
crate struct NuCompleter {
|
||||
pub file_completer: FilenameCompleter,
|
||||
//pub commands: indexmap::IndexMap<String, Arc<dyn Command>>,
|
||||
pub commands: CommandRegistry,
|
||||
}
|
||||
|
||||
impl NuCompleter {
|
||||
@ -14,7 +15,7 @@ impl NuCompleter {
|
||||
pos: usize,
|
||||
context: &rustyline::Context,
|
||||
) -> rustyline::Result<(usize, Vec<rustyline::completion::Pair>)> {
|
||||
//let commands: Vec<String> = self.commands.keys().cloned().collect();
|
||||
let commands: Vec<String> = self.commands.names();
|
||||
|
||||
let mut completions = self.file_completer.complete(line, pos, context)?.1;
|
||||
|
||||
@ -45,7 +46,6 @@ impl NuCompleter {
|
||||
replace_pos -= 1;
|
||||
}
|
||||
|
||||
/*
|
||||
for command in commands.iter() {
|
||||
let mut pos = replace_pos;
|
||||
let mut matched = true;
|
||||
@ -63,13 +63,12 @@ impl NuCompleter {
|
||||
}
|
||||
|
||||
if matched {
|
||||
completions.push(CompletionPair {
|
||||
completions.push(rustyline::completion::Pair {
|
||||
display: command.clone(),
|
||||
replacement: command.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
Ok((replace_pos, completions))
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ impl Clone for FilesystemShell {
|
||||
path: self.path.clone(),
|
||||
completer: NuCompleter {
|
||||
file_completer: FilenameCompleter::new(),
|
||||
commands: self.completer.commands.clone(),
|
||||
},
|
||||
hinter: HistoryHinter {},
|
||||
}
|
||||
@ -25,23 +26,28 @@ impl Clone for FilesystemShell {
|
||||
}
|
||||
|
||||
impl FilesystemShell {
|
||||
pub fn basic() -> Result<FilesystemShell, std::io::Error> {
|
||||
pub fn basic(commands: CommandRegistry) -> Result<FilesystemShell, std::io::Error> {
|
||||
let path = std::env::current_dir()?;
|
||||
|
||||
Ok(FilesystemShell {
|
||||
path: path.to_string_lossy().to_string(),
|
||||
completer: NuCompleter {
|
||||
file_completer: FilenameCompleter::new(),
|
||||
commands,
|
||||
},
|
||||
hinter: HistoryHinter {},
|
||||
})
|
||||
}
|
||||
|
||||
pub fn with_location(path: String) -> Result<FilesystemShell, std::io::Error> {
|
||||
pub fn with_location(
|
||||
path: String,
|
||||
commands: CommandRegistry,
|
||||
) -> Result<FilesystemShell, std::io::Error> {
|
||||
Ok(FilesystemShell {
|
||||
path,
|
||||
completer: NuCompleter {
|
||||
file_completer: FilenameCompleter::new(),
|
||||
commands,
|
||||
},
|
||||
hinter: HistoryHinter {},
|
||||
})
|
||||
|
@ -1,5 +1,6 @@
|
||||
use crate::commands::command::EvaluatedStaticCommandArgs;
|
||||
use crate::errors::ShellError;
|
||||
use crate::prelude::*;
|
||||
use crate::shell::filesystem_shell::FilesystemShell;
|
||||
use crate::shell::shell::Shell;
|
||||
use crate::stream::OutputStream;
|
||||
@ -12,9 +13,11 @@ pub struct ShellManager {
|
||||
}
|
||||
|
||||
impl ShellManager {
|
||||
pub fn basic() -> Result<ShellManager, Box<dyn Error>> {
|
||||
pub fn basic(commands: CommandRegistry) -> Result<ShellManager, Box<dyn Error>> {
|
||||
Ok(ShellManager {
|
||||
shells: Arc::new(Mutex::new(vec![Box::new(FilesystemShell::basic()?)])),
|
||||
shells: Arc::new(Mutex::new(vec![Box::new(FilesystemShell::basic(
|
||||
commands,
|
||||
)?)])),
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user