Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: introduce primary param in label #413

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ diagnostic error code: ruget::api::bad_json
- [... handler options](#-handler-options)
- [... dynamic diagnostics](#-dynamic-diagnostics)
- [... syntax highlighting](#-syntax-highlighting)
- [... primary label](#-primary-label)
- [... collection of labels](#-collection-of-labels)
- [Acknowledgements](#acknowledgements)
- [License](#license)
Expand Down Expand Up @@ -689,6 +690,37 @@ trait to [`MietteHandlerOpts`] by calling the
[`with_syntax_highlighting`](MietteHandlerOpts::with_syntax_highlighting)
method. See the [`highlighters`] module docs for more details.

#### ... primary label

You can use the `primary` parameter to `label` to indicate that the label
is the primary label.

```rust
#[derive(Debug, Diagnostic, Error)]
#[error("oops!")]
struct MyError {
#[label(primary, "main issue")]
primary_span: SourceSpan,

#[label("other label")]
other_span: SourceSpan,
}
```

The `primary` parameter can be used at most once:

```rust
#[derive(Debug, Diagnostic, Error)]
#[error("oops!")]
struct MyError {
#[label(primary, "main issue")]
primary_span: SourceSpan,

#[label(primary, "other label")] // Error: Cannot have more than one primary label.
other_span: SourceSpan,
}
```

#### ... collection of labels

When the number of labels is unknown, you can use a collection of `SourceSpan`
Expand Down