mirror of
https://github.com/nushell/nushell
synced 2024-12-28 14:03:09 +00:00
Add flag completions (#817)
This commit is contained in:
parent
89d852f76c
commit
310ecb79b6
1 changed files with 26 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
|||
use nu_engine::eval_block;
|
||||
use nu_parser::{flatten_expression, parse};
|
||||
use nu_protocol::{
|
||||
ast::Statement,
|
||||
ast::{Expr, Statement},
|
||||
engine::{EngineState, Stack, StateWorkingSet},
|
||||
PipelineData, Span,
|
||||
};
|
||||
|
@ -196,6 +196,31 @@ impl NuCompleter {
|
|||
offset,
|
||||
);
|
||||
}
|
||||
if prefix.starts_with(b"-") {
|
||||
// this might be a flag, let's see
|
||||
if let Expr::Call(call) = &expr.expr {
|
||||
let decl = working_set.get_decl(call.decl_id);
|
||||
let sig = decl.signature();
|
||||
|
||||
let mut output = vec![];
|
||||
|
||||
for named in &sig.named {
|
||||
let mut named = named.long.as_bytes().to_vec();
|
||||
named.insert(0, b'-');
|
||||
named.insert(0, b'-');
|
||||
if named.starts_with(prefix) {
|
||||
output.push((
|
||||
reedline::Span {
|
||||
start: flat.0.start - offset,
|
||||
end: flat.0.end - offset,
|
||||
},
|
||||
String::from_utf8_lossy(&named).to_string(),
|
||||
));
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
match &flat.1 {
|
||||
nu_parser::FlatShape::Custom(custom_completion) => {
|
||||
|
|
Loading…
Reference in a new issue