mirror of
https://github.com/nushell/nushell.git
synced 2024-12-17 04:31:21 +01:00
Merge pull request #95 from nushell/var_compl_better_ls
Variable completions and better ls
This commit is contained in:
commit
e3ce58475b
@ -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();
|
||||
|
@ -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('*');
|
||||
}
|
||||
|
||||
|
@ -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>,
|
||||
|
Loading…
Reference in New Issue
Block a user