forked from extern/nushell
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 {
|
for flat in flattened {
|
||||||
if pos >= flat.0.start && pos <= flat.0.end {
|
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 {
|
match &flat.1 {
|
||||||
nu_parser::FlatShape::Custom(custom_completion) => {
|
nu_parser::FlatShape::Custom(custom_completion) => {
|
||||||
let prefix = working_set.get_span_contents(flat.0).to_vec();
|
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);
|
let path = std::path::Path::new(&result);
|
||||||
if path.is_dir() {
|
if path.is_dir() {
|
||||||
|
if !result.ends_with(std::path::MAIN_SEPARATOR) {
|
||||||
|
result.push(std::path::MAIN_SEPARATOR);
|
||||||
|
}
|
||||||
result.push('*');
|
result.push('*');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,12 +12,12 @@ pub struct EngineState {
|
|||||||
vars: Vec<Type>,
|
vars: Vec<Type>,
|
||||||
decls: Vec<Box<dyn Command>>,
|
decls: Vec<Box<dyn Command>>,
|
||||||
blocks: Vec<Block>,
|
blocks: Vec<Block>,
|
||||||
scope: Vec<ScopeFrame>,
|
pub scope: Vec<ScopeFrame>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ScopeFrame {
|
pub struct ScopeFrame {
|
||||||
vars: HashMap<Vec<u8>, VarId>,
|
pub vars: HashMap<Vec<u8>, VarId>,
|
||||||
decls: HashMap<Vec<u8>, DeclId>,
|
decls: HashMap<Vec<u8>, DeclId>,
|
||||||
aliases: HashMap<Vec<u8>, Vec<Span>>,
|
aliases: HashMap<Vec<u8>, Vec<Span>>,
|
||||||
modules: HashMap<Vec<u8>, BlockId>,
|
modules: HashMap<Vec<u8>, BlockId>,
|
||||||
|
Loading…
Reference in New Issue
Block a user