improve error when name and parameters are not space-separated (#8958)

# Description
closes #8934

this pr improves the diagnostic emitted when the name and parameters of
either `def`, `def-env` or `extern` are not separated by a space

```nu
Error:
  × no space between name and parameters
   ╭─[entry #1:1:1]
 1 │ def err[] {}
   ·        ▲
   ·        ╰── expected space
   ╰────
  help: consider adding a space between the `def` command's name and its parameters
```

from

```nu
Error: nu::parser::missing_positional

  × Missing required positional argument.
   ╭─[entry #1:1:1]
 1 │ def err[] {}
   ╰────
  help: Usage: def <def_name> <params> <body>
```

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
Co-authored-by: Jelle Besseling <jelle@pingiun.com>
This commit is contained in:
mike
2023-05-12 17:10:40 +03:00
committed by GitHub
parent 5e8754bd85
commit a3bf2bff49
4 changed files with 104 additions and 4 deletions

View File

@ -445,6 +445,16 @@ pub enum ParseError {
#[error("{0}")]
#[diagnostic()]
LabeledError(String, String, #[label("{1}")] Span),
#[error("{error}")]
#[diagnostic(help("{help}"))]
LabeledErrorWithHelp {
error: String,
label: String,
help: String,
#[label("{label}")]
span: Span,
},
}
impl ParseError {
@ -524,6 +534,7 @@ impl ParseError {
ParseError::UnknownOperator(_, _, s) => *s,
ParseError::InvalidLiteral(_, _, s) => *s,
ParseError::NotAConstant(s) => *s,
ParseError::LabeledErrorWithHelp { span: s, .. } => *s,
}
}
}