forked from extern/nushell
Add aliases to command completions (#4708)
This commit is contained in:
parent
97b3e4a233
commit
47d5501f9f
@ -141,7 +141,7 @@ impl NuCompleter {
|
||||
) -> Vec<(reedline::Span, String)> {
|
||||
let prefix = working_set.get_span_contents(span);
|
||||
|
||||
let mut results = working_set
|
||||
let results = working_set
|
||||
.find_commands_by_prefix(prefix)
|
||||
.into_iter()
|
||||
.map(move |x| {
|
||||
@ -152,8 +152,23 @@ impl NuCompleter {
|
||||
},
|
||||
String::from_utf8_lossy(&x).to_string(),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
});
|
||||
|
||||
let results_aliases =
|
||||
working_set
|
||||
.find_aliases_by_prefix(prefix)
|
||||
.into_iter()
|
||||
.map(move |x| {
|
||||
(
|
||||
reedline::Span {
|
||||
start: span.start - offset,
|
||||
end: span.end - offset,
|
||||
},
|
||||
String::from_utf8_lossy(&x).to_string(),
|
||||
)
|
||||
});
|
||||
|
||||
let mut results = results.chain(results_aliases).collect::<Vec<_>>();
|
||||
|
||||
let prefix = working_set.get_span_contents(span);
|
||||
let prefix = String::from_utf8_lossy(prefix).to_string();
|
||||
|
@ -462,6 +462,16 @@ impl EngineState {
|
||||
output
|
||||
}
|
||||
|
||||
pub fn find_aliases_by_prefix(&self, name: &[u8]) -> Vec<Vec<u8>> {
|
||||
self.scope
|
||||
.iter()
|
||||
.rev()
|
||||
.flat_map(|scope| &scope.aliases)
|
||||
.filter(|decl| decl.0.starts_with(name))
|
||||
.map(|decl| decl.0.clone())
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn get_span_contents(&self, span: &Span) -> &[u8] {
|
||||
for (contents, start, finish) in &self.file_contents {
|
||||
if span.start >= *start && span.end <= *finish {
|
||||
@ -1248,6 +1258,18 @@ impl<'a> StateWorkingSet<'a> {
|
||||
output
|
||||
}
|
||||
|
||||
pub fn find_aliases_by_prefix(&self, name: &[u8]) -> Vec<Vec<u8>> {
|
||||
self.delta
|
||||
.scope
|
||||
.iter()
|
||||
.rev()
|
||||
.flat_map(|scope| &scope.aliases)
|
||||
.filter(|decl| decl.0.starts_with(name))
|
||||
.map(|decl| decl.0.clone())
|
||||
.chain(self.permanent_state.find_aliases_by_prefix(name))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn get_block(&self, block_id: BlockId) -> &Block {
|
||||
let num_permanent_blocks = self.permanent_state.num_blocks();
|
||||
if block_id < num_permanent_blocks {
|
||||
|
Loading…
Reference in New Issue
Block a user