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:
mike 2023-03-26 11:58:33 +03:00 committed by GitHub
parent 05f1b41275
commit d9a888528a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3082,27 +3082,25 @@ pub fn parse_shape_name(
b"var-with-opt-type" => SyntaxShape::VarWithOptType,
_ => {
if bytes.contains(&b'@') {
let str = String::from_utf8_lossy(bytes);
let split: Vec<_> = str.split('@').collect();
let (shape, err) = parse_shape_name(
working_set,
split[0].as_bytes(),
Span::new(span.start, span.start + split[0].len()),
);
let command_name = trim_quotes(split[1].as_bytes());
let split: Vec<_> = bytes.split(|b| b == &b'@').collect();
let shape_span = Span::new(span.start, span.start + split[0].len());
let cmd_span = Span::new(span.start + split[0].len() + 1, span.end);
let (shape, err) = parse_shape_name(working_set, split[0], shape_span);
let command_name = trim_quotes(split[1]);
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);
if let Some(decl_id) = decl_id {
return (SyntaxShape::Custom(Box::new(shape), decl_id), err);
} else {
return (
shape,
Some(ParseError::UnknownCommand(Span::new(
span.start + split[0].len() + 1,
span.end,
))),
);
return (shape, Some(ParseError::UnknownCommand(cmd_span)));
}
} else {
return (SyntaxShape::Any, Some(ParseError::UnknownType(span)));