forked from extern/nushell
Move completions to DeclId (#4801)
* Move completions to DeclId * fmt * fmt
This commit is contained in:
parent
643cce8a6f
commit
12bf23faa6
@ -1,7 +1,7 @@
|
|||||||
use nu_engine::eval_block;
|
use nu_engine::eval_call;
|
||||||
use nu_parser::{flatten_expression, parse, trim_quotes, FlatShape};
|
use nu_parser::{flatten_expression, parse, trim_quotes, FlatShape};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Expr,
|
ast::{Call, Expr},
|
||||||
engine::{EngineState, Stack, StateWorkingSet},
|
engine::{EngineState, Stack, StateWorkingSet},
|
||||||
PipelineData, Span, Value, CONFIG_VARIABLE_ID,
|
PipelineData, Span, Value, CONFIG_VARIABLE_ID,
|
||||||
};
|
};
|
||||||
@ -275,16 +275,9 @@ impl NuCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
match &flat.1 {
|
match &flat.1 {
|
||||||
FlatShape::Custom(custom_completion) => {
|
FlatShape::Custom(decl_id) => {
|
||||||
//let prefix = working_set.get_span_contents(flat.0).to_vec();
|
//let prefix = working_set.get_span_contents(flat.0).to_vec();
|
||||||
|
|
||||||
let (block, ..) = parse(
|
|
||||||
&mut working_set,
|
|
||||||
None,
|
|
||||||
custom_completion.as_bytes(),
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut stack = Stack::new();
|
let mut stack = Stack::new();
|
||||||
// Set up our initial config to start from
|
// Set up our initial config to start from
|
||||||
if let Some(conf) = &self.config {
|
if let Some(conf) = &self.config {
|
||||||
@ -300,13 +293,18 @@ impl NuCompleter {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = eval_block(
|
let result = eval_call(
|
||||||
&self.engine_state,
|
&self.engine_state,
|
||||||
&mut stack,
|
&mut stack,
|
||||||
&block,
|
&Call {
|
||||||
|
decl_id: *decl_id,
|
||||||
|
head: new_span,
|
||||||
|
positional: vec![],
|
||||||
|
named: vec![],
|
||||||
|
redirect_stdout: true,
|
||||||
|
redirect_stderr: true,
|
||||||
|
},
|
||||||
PipelineData::new(new_span),
|
PipelineData::new(new_span),
|
||||||
true,
|
|
||||||
true,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
fn map_completions<'a>(
|
fn map_completions<'a>(
|
||||||
|
@ -24,7 +24,7 @@ pub fn eval_operator(op: &Expression) -> Result<Operator, ShellError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eval_call(
|
pub fn eval_call(
|
||||||
engine_state: &EngineState,
|
engine_state: &EngineState,
|
||||||
caller_stack: &mut Stack,
|
caller_stack: &mut Stack,
|
||||||
call: &Call,
|
call: &Call,
|
||||||
|
@ -10,6 +10,7 @@ pub use column::get_columns;
|
|||||||
pub use documentation::{generate_docs, get_brief_help, get_documentation, get_full_help};
|
pub use documentation::{generate_docs, get_brief_help, get_documentation, get_full_help};
|
||||||
pub use env::*;
|
pub use env::*;
|
||||||
pub use eval::{
|
pub use eval::{
|
||||||
eval_block, eval_expression, eval_expression_with_input, eval_operator, eval_subexpression,
|
eval_block, eval_call, eval_expression, eval_expression_with_input, eval_operator,
|
||||||
|
eval_subexpression,
|
||||||
};
|
};
|
||||||
pub use glob_from::glob_from;
|
pub use glob_from::glob_from;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use nu_protocol::ast::{Block, Expr, Expression, ImportPatternMember, PathMember, Pipeline};
|
use nu_protocol::ast::{Block, Expr, Expression, ImportPatternMember, PathMember, Pipeline};
|
||||||
|
use nu_protocol::DeclId;
|
||||||
use nu_protocol::{engine::StateWorkingSet, Span};
|
use nu_protocol::{engine::StateWorkingSet, Span};
|
||||||
use std::fmt::{Display, Formatter, Result};
|
use std::fmt::{Display, Formatter, Result};
|
||||||
|
|
||||||
@ -28,7 +29,7 @@ pub enum FlatShape {
|
|||||||
GlobPattern,
|
GlobPattern,
|
||||||
Variable,
|
Variable,
|
||||||
Flag,
|
Flag,
|
||||||
Custom(String),
|
Custom(DeclId),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for FlatShape {
|
impl Display for FlatShape {
|
||||||
@ -76,7 +77,7 @@ pub fn flatten_expression(
|
|||||||
expr: &Expression,
|
expr: &Expression,
|
||||||
) -> Vec<(Span, FlatShape)> {
|
) -> Vec<(Span, FlatShape)> {
|
||||||
if let Some(custom_completion) = &expr.custom_completion {
|
if let Some(custom_completion) = &expr.custom_completion {
|
||||||
return vec![(expr.span, FlatShape::Custom(custom_completion.clone()))];
|
return vec![(expr.span, FlatShape::Custom(*custom_completion))];
|
||||||
}
|
}
|
||||||
|
|
||||||
match &expr.expr {
|
match &expr.expr {
|
||||||
|
@ -2451,13 +2451,19 @@ pub fn parse_shape_name(
|
|||||||
);
|
);
|
||||||
let command_name = trim_quotes(split[1].as_bytes());
|
let command_name = trim_quotes(split[1].as_bytes());
|
||||||
|
|
||||||
return (
|
let decl_id = working_set.find_decl(command_name);
|
||||||
SyntaxShape::Custom(
|
|
||||||
Box::new(shape),
|
if let Some(decl_id) = decl_id {
|
||||||
String::from_utf8_lossy(command_name).to_string(),
|
return (SyntaxShape::Custom(Box::new(shape), decl_id), err);
|
||||||
),
|
} else {
|
||||||
err,
|
return (
|
||||||
);
|
shape,
|
||||||
|
Some(ParseError::UnknownCommand(Span {
|
||||||
|
start: span.start + split[0].len() + 1,
|
||||||
|
end: span.end,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return (SyntaxShape::Any, Some(ParseError::UnknownType(span)));
|
return (SyntaxShape::Any, Some(ParseError::UnknownType(span)));
|
||||||
}
|
}
|
||||||
@ -3713,7 +3719,7 @@ pub fn parse_value(
|
|||||||
match shape {
|
match shape {
|
||||||
SyntaxShape::Custom(shape, custom_completion) => {
|
SyntaxShape::Custom(shape, custom_completion) => {
|
||||||
let (mut expression, err) = parse_value(working_set, span, shape);
|
let (mut expression, err) = parse_value(working_set, span, shape);
|
||||||
expression.custom_completion = Some(custom_completion.clone());
|
expression.custom_completion = Some(*custom_completion);
|
||||||
(expression, err)
|
(expression, err)
|
||||||
}
|
}
|
||||||
SyntaxShape::Number => parse_number(bytes, span),
|
SyntaxShape::Number => parse_number(bytes, span),
|
||||||
|
@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
use super::{Expr, Operator};
|
use super::{Expr, Operator};
|
||||||
use crate::ast::ImportPattern;
|
use crate::ast::ImportPattern;
|
||||||
|
use crate::DeclId;
|
||||||
use crate::{engine::StateWorkingSet, BlockId, Signature, Span, Type, VarId, IN_VARIABLE_ID};
|
use crate::{engine::StateWorkingSet, BlockId, Signature, Span, Type, VarId, IN_VARIABLE_ID};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
@ -9,7 +10,7 @@ pub struct Expression {
|
|||||||
pub expr: Expr,
|
pub expr: Expr,
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub ty: Type,
|
pub ty: Type,
|
||||||
pub custom_completion: Option<String>,
|
pub custom_completion: Option<DeclId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Expression {
|
impl Expression {
|
||||||
|
@ -2,7 +2,7 @@ use std::fmt::Display;
|
|||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::Type;
|
use crate::{DeclId, Type};
|
||||||
|
|
||||||
/// The syntactic shapes that values must match to be passed into a command. You can think of this as the type-checking that occurs when you call a function.
|
/// The syntactic shapes that values must match to be passed into a command. You can think of this as the type-checking that occurs when you call a function.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
@ -90,7 +90,7 @@ pub enum SyntaxShape {
|
|||||||
Record,
|
Record,
|
||||||
|
|
||||||
/// A custom shape with custom completion logic
|
/// A custom shape with custom completion logic
|
||||||
Custom(Box<SyntaxShape>, String),
|
Custom(Box<SyntaxShape>, DeclId),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SyntaxShape {
|
impl SyntaxShape {
|
||||||
|
@ -51,7 +51,7 @@ impl Type {
|
|||||||
Type::Unknown => SyntaxShape::Any,
|
Type::Unknown => SyntaxShape::Any,
|
||||||
Type::Error => SyntaxShape::Any,
|
Type::Error => SyntaxShape::Any,
|
||||||
Type::Binary => SyntaxShape::Binary,
|
Type::Binary => SyntaxShape::Binary,
|
||||||
Type::Custom => SyntaxShape::Custom(Box::new(SyntaxShape::Any), String::new()),
|
Type::Custom => SyntaxShape::Any,
|
||||||
Type::Signature => SyntaxShape::Signature,
|
Type::Signature => SyntaxShape::Signature,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user