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:
Herlon Aguiar 2022-04-04 20:31:40 +02:00 committed by GitHub
parent 1e4b33b9c6
commit ef1cf7e634
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,