Move completions to DeclId (#4801)

* Move completions to DeclId

* fmt

* fmt
This commit is contained in:
JT
2022-03-10 02:49:02 -05:00
committed by GitHub
parent 643cce8a6f
commit 12bf23faa6
8 changed files with 37 additions and 30 deletions

View File

@ -1,4 +1,5 @@
use nu_protocol::ast::{Block, Expr, Expression, ImportPatternMember, PathMember, Pipeline};
use nu_protocol::DeclId;
use nu_protocol::{engine::StateWorkingSet, Span};
use std::fmt::{Display, Formatter, Result};
@ -28,7 +29,7 @@ pub enum FlatShape {
GlobPattern,
Variable,
Flag,
Custom(String),
Custom(DeclId),
}
impl Display for FlatShape {
@ -76,7 +77,7 @@ pub fn flatten_expression(
expr: &Expression,
) -> Vec<(Span, FlatShape)> {
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 {

View File

@ -2451,13 +2451,19 @@ pub fn parse_shape_name(
);
let command_name = trim_quotes(split[1].as_bytes());
return (
SyntaxShape::Custom(
Box::new(shape),
String::from_utf8_lossy(command_name).to_string(),
),
err,
);
let decl_id = working_set.find_decl(command_name);
if let Some(decl_id) = decl_id {
return (SyntaxShape::Custom(Box::new(shape), decl_id), err);
} else {
return (
shape,
Some(ParseError::UnknownCommand(Span {
start: span.start + split[0].len() + 1,
end: span.end,
})),
);
}
} else {
return (SyntaxShape::Any, Some(ParseError::UnknownType(span)));
}
@ -3713,7 +3719,7 @@ pub fn parse_value(
match shape {
SyntaxShape::Custom(shape, custom_completion) => {
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)
}
SyntaxShape::Number => parse_number(bytes, span),