forked from extern/nushell
fix unhelpful error message with '@' custom completion (#8620)
# Description with such a line ```nu extern err [--flag: string@] ``` this pr changes the error message from ```nu Error: nu::parser::unknown_command × Unknown command. ╭─[entry #69:1:1] 1 │ extern err [--flag: string@] · ▲ · ╰── unknown command ╰──── ``` to ```nu Error: nu::parser::parse_mismatch × Parse mismatch during operation. ╭─[entry #69:1:1] 1 │ extern err [--flag: string@] · ▲ · ╰── expected command name ╰──── ```
This commit is contained in:
parent
05f1b41275
commit
d9a888528a
@ -3082,27 +3082,25 @@ pub fn parse_shape_name(
|
|||||||
b"var-with-opt-type" => SyntaxShape::VarWithOptType,
|
b"var-with-opt-type" => SyntaxShape::VarWithOptType,
|
||||||
_ => {
|
_ => {
|
||||||
if bytes.contains(&b'@') {
|
if bytes.contains(&b'@') {
|
||||||
let str = String::from_utf8_lossy(bytes);
|
let split: Vec<_> = bytes.split(|b| b == &b'@').collect();
|
||||||
let split: Vec<_> = str.split('@').collect();
|
|
||||||
let (shape, err) = parse_shape_name(
|
let shape_span = Span::new(span.start, span.start + split[0].len());
|
||||||
working_set,
|
let cmd_span = Span::new(span.start + split[0].len() + 1, span.end);
|
||||||
split[0].as_bytes(),
|
let (shape, err) = parse_shape_name(working_set, split[0], shape_span);
|
||||||
Span::new(span.start, span.start + split[0].len()),
|
|
||||||
);
|
let command_name = trim_quotes(split[1]);
|
||||||
let command_name = trim_quotes(split[1].as_bytes());
|
|
||||||
|
if command_name.is_empty() {
|
||||||
|
let err = ParseError::Expected("a command name".into(), cmd_span);
|
||||||
|
return (SyntaxShape::Any, Some(err));
|
||||||
|
}
|
||||||
|
|
||||||
let decl_id = working_set.find_decl(command_name, &Type::Any);
|
let decl_id = working_set.find_decl(command_name, &Type::Any);
|
||||||
|
|
||||||
if let Some(decl_id) = decl_id {
|
if let Some(decl_id) = decl_id {
|
||||||
return (SyntaxShape::Custom(Box::new(shape), decl_id), err);
|
return (SyntaxShape::Custom(Box::new(shape), decl_id), err);
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (shape, Some(ParseError::UnknownCommand(cmd_span)));
|
||||||
shape,
|
|
||||||
Some(ParseError::UnknownCommand(Span::new(
|
|
||||||
span.start + split[0].len() + 1,
|
|
||||||
span.end,
|
|
||||||
))),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return (SyntaxShape::Any, Some(ParseError::UnknownType(span)));
|
return (SyntaxShape::Any, Some(ParseError::UnknownType(span)));
|
||||||
|
Loading…
Reference in New Issue
Block a user