mirror of
https://github.com/nushell/nushell.git
synced 2024-11-25 01:43:47 +01:00
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,
|
||||
_ => {
|
||||
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)));
|
||||
|
Loading…
Reference in New Issue
Block a user