forked from extern/nushell
Add flag completions (#817)
This commit is contained in:
parent
89d852f76c
commit
310ecb79b6
@ -1,7 +1,7 @@
|
|||||||
use nu_engine::eval_block;
|
use nu_engine::eval_block;
|
||||||
use nu_parser::{flatten_expression, parse};
|
use nu_parser::{flatten_expression, parse};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Statement,
|
ast::{Expr, Statement},
|
||||||
engine::{EngineState, Stack, StateWorkingSet},
|
engine::{EngineState, Stack, StateWorkingSet},
|
||||||
PipelineData, Span,
|
PipelineData, Span,
|
||||||
};
|
};
|
||||||
@ -196,6 +196,31 @@ impl NuCompleter {
|
|||||||
offset,
|
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 {
|
match &flat.1 {
|
||||||
nu_parser::FlatShape::Custom(custom_completion) => {
|
nu_parser::FlatShape::Custom(custom_completion) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user