nu-cli: directory syntax shape + completions (#5299)

This commit is contained in:
Herlon Aguiar
2022-04-22 22:18:51 +02:00
committed by GitHub
parent 661283c4d2
commit 5ff2ae628b
15 changed files with 211 additions and 9 deletions

View File

@ -25,6 +25,7 @@ pub enum FlatShape {
Record,
Block,
Filepath,
Directory,
DateTime,
GlobPattern,
Variable,
@ -56,6 +57,7 @@ impl Display for FlatShape {
FlatShape::Record => write!(f, "shape_record"),
FlatShape::Block => write!(f, "shape_block"),
FlatShape::Filepath => write!(f, "shape_filepath"),
FlatShape::Directory => write!(f, "shape_directory"),
FlatShape::GlobPattern => write!(f, "shape_globpattern"),
FlatShape::Variable => write!(f, "shape_variable"),
FlatShape::Flag => write!(f, "shape_flag"),
@ -279,6 +281,9 @@ pub fn flatten_expression(
Expr::Filepath(_) => {
vec![(expr.span, FlatShape::Filepath)]
}
Expr::Directory(_) => {
vec![(expr.span, FlatShape::Directory)]
}
Expr::GlobPattern(_) => {
vec![(expr.span, FlatShape::GlobPattern)]
}

View File

@ -1915,6 +1915,33 @@ pub fn parse_full_cell_path(
}
}
pub fn parse_directory(
working_set: &mut StateWorkingSet,
span: Span,
) -> (Expression, Option<ParseError>) {
let bytes = working_set.get_span_contents(span);
let bytes = trim_quotes(bytes);
trace!("parsing: directory");
if let Ok(token) = String::from_utf8(bytes.into()) {
trace!("-- found {}", token);
(
Expression {
expr: Expr::Directory(token),
span,
ty: Type::String,
custom_completion: None,
},
None,
)
} else {
(
garbage(span),
Some(ParseError::Expected("directory".into(), span)),
)
}
}
pub fn parse_filepath(
working_set: &mut StateWorkingSet,
span: Span,
@ -2551,6 +2578,7 @@ pub fn parse_shape_name(
b"cell-path" => SyntaxShape::CellPath,
b"duration" => SyntaxShape::Duration,
b"path" => SyntaxShape::Filepath,
b"directory" => SyntaxShape::Directory,
b"expr" => SyntaxShape::Expression,
b"filesize" => SyntaxShape::Filesize,
b"glob" => SyntaxShape::GlobPattern,
@ -3869,6 +3897,7 @@ pub fn parse_value(
SyntaxShape::Filesize => parse_filesize(working_set, span),
SyntaxShape::Range => parse_range(working_set, span, expand_aliases_denylist),
SyntaxShape::Filepath => parse_filepath(working_set, span),
SyntaxShape::Directory => parse_directory(working_set, span),
SyntaxShape::GlobPattern => parse_glob_pattern(working_set, span),
SyntaxShape::String => parse_string(working_set, span),
SyntaxShape::Binary => parse_binary(working_set, span),
@ -4868,6 +4897,7 @@ pub fn discover_captures_in_expr(
}
}
Expr::Filepath(_) => {}
Expr::Directory(_) => {}
Expr::Float(_) => {}
Expr::FullCellPath(cell_path) => {
let result = discover_captures_in_expr(working_set, &cell_path.head, seen, seen_blocks);