mirror of
https://github.com/nushell/nushell
synced 2025-01-14 14:14:13 +00:00
feature: Add some context to completions (#5078)
* send current line and position * copy current line * fix error * deleted test completion
This commit is contained in:
parent
1e4b33b9c6
commit
ef1cf7e634
1 changed files with 18 additions and 3 deletions
|
@ -1,9 +1,9 @@
|
|||
use nu_engine::eval_call;
|
||||
use nu_parser::{flatten_expression, parse, trim_quotes, FlatShape};
|
||||
use nu_protocol::{
|
||||
ast::{Call, Expr},
|
||||
ast::{Call, Expr, Expression},
|
||||
engine::{EngineState, Stack, StateWorkingSet},
|
||||
levenshtein_distance, PipelineData, Span, Value, CONFIG_VARIABLE_ID,
|
||||
levenshtein_distance, PipelineData, Span, Type, Value, CONFIG_VARIABLE_ID,
|
||||
};
|
||||
use reedline::{Completer, Suggestion};
|
||||
|
||||
|
@ -224,8 +224,10 @@ impl NuCompleter {
|
|||
fn completion_helper(&self, line: &str, pos: usize) -> Vec<Suggestion> {
|
||||
let mut working_set = StateWorkingSet::new(&self.engine_state);
|
||||
let offset = working_set.next_span_start();
|
||||
let current_line_str = line.trim().to_string();
|
||||
let mut line = line.to_string();
|
||||
line.insert(pos, 'a');
|
||||
let line_pos = pos;
|
||||
let pos = offset + pos;
|
||||
let (output, _err) = parse(
|
||||
&mut working_set,
|
||||
|
@ -330,7 +332,20 @@ impl NuCompleter {
|
|||
&Call {
|
||||
decl_id: *decl_id,
|
||||
head: new_span,
|
||||
positional: vec![],
|
||||
positional: vec![
|
||||
Expression {
|
||||
span: Span { start: 0, end: 0 },
|
||||
ty: Type::String,
|
||||
expr: Expr::String(current_line_str),
|
||||
custom_completion: None,
|
||||
},
|
||||
Expression {
|
||||
span: Span { start: 0, end: 0 },
|
||||
ty: Type::Int,
|
||||
expr: Expr::Int(line_pos as i64),
|
||||
custom_completion: None,
|
||||
},
|
||||
],
|
||||
named: vec![],
|
||||
redirect_stdout: true,
|
||||
redirect_stderr: true,
|
||||
|
|
Loading…
Reference in a new issue