Variable completions and better ls

This commit is contained in:
JT 2021-10-05 15:46:24 +13:00
parent 14426433aa
commit 31ce8c1e33
3 changed files with 39 additions and 2 deletions

View File

@ -32,6 +32,40 @@ impl Completer for NuCompleter {
for flat in flattened {
if pos >= flat.0.start && pos <= flat.0.end {
let prefix = working_set.get_span_contents(flat.0);
if prefix.starts_with(b"$") {
let mut output = vec![];
for scope in &working_set.delta.scope {
for v in &scope.vars {
if v.0.starts_with(prefix) {
output.push((
reedline::Span {
start: flat.0.start - offset,
end: flat.0.end - offset,
},
String::from_utf8_lossy(v.0).to_string(),
));
}
}
}
for scope in &engine_state.scope {
for v in &scope.vars {
if v.0.starts_with(prefix) {
output.push((
reedline::Span {
start: flat.0.start - offset,
end: flat.0.end - offset,
},
String::from_utf8_lossy(v.0).to_string(),
));
}
}
}
return output;
}
match &flat.1 {
nu_parser::FlatShape::Custom(custom_completion) => {
let prefix = working_set.get_span_contents(flat.0).to_vec();

View File

@ -36,6 +36,9 @@ impl Command for Ls {
let path = std::path::Path::new(&result);
if path.is_dir() {
if !result.ends_with(std::path::MAIN_SEPARATOR) {
result.push(std::path::MAIN_SEPARATOR);
}
result.push('*');
}

View File

@ -12,12 +12,12 @@ pub struct EngineState {
vars: Vec<Type>,
decls: Vec<Box<dyn Command>>,
blocks: Vec<Block>,
scope: Vec<ScopeFrame>,
pub scope: Vec<ScopeFrame>,
}
#[derive(Debug)]
pub struct ScopeFrame {
vars: HashMap<Vec<u8>, VarId>,
pub vars: HashMap<Vec<u8>, VarId>,
decls: HashMap<Vec<u8>, DeclId>,
aliases: HashMap<Vec<u8>, Vec<Span>>,
modules: HashMap<Vec<u8>, BlockId>,