Commit Graph

549 Commits

Author SHA1 Message Date
Yiyu Lin 62cfd221ba
docs: add `severity` example (#350)
Co-authored-by: hzlinyiyu <hzlinyiyu@corp.netease.com>
2024-02-23 07:43:22 -08:00
Boshen 328bf37922
feat(wasm): add feature "fancy-no-syscall" for wasm targets (#349)
Fixes: https://github.com/zkat/miette/issues/346
2024-02-23 07:42:39 -08:00
Nahor 6ea86a2248
fix(redundant-import): fix a warning and CI failure in nightly (#348) 2024-02-21 14:05:17 -08:00
Nahor 7d9dfc6e8e
fix(invalid span): skip the snippet when read_span fails (#347)
Fixes: https://github.com/zkat/miette/issues/219

When a snippet couldn't be read (typically because the span didn't fit
within the source code), it and the rest of the diagnostic were silently
dropped, which was confusing to the developer.
Now, in place of the snippet, print an error message with the name of
the failed label and the error it triggered, then proceed with the rest
of the diagnostic (footer, related, ...)
2024-02-21 13:46:58 -08:00
Nahor 75fea0935e
fix(label-collections): Label collection fixes and cleanup (#343)
* feat(collection): add label(collection) documentation to lib.rs

* feat(collection): remove repeated formatting of label text

Because of a typo, the label text was being formatted multiple times per
label in a collection. With the fix, the text is formatted only once per
collection

* feat(collection): chain iterators rather than extend vector

Since we are going to iterate anyway, instead of growing the label vector,
chain the iterators. This should be more efficient.

In some cases, this also remove a compilation warning about the label
vector being unnecessarily mutable.

* feat(collection): remove unnecessary `OptionalWrapper`

- In a label collection, there is no need for a `None` label. One should
  just not add that label
- Code wise it is also incorrect. The wrapper will be for a vector of
  spans, not for individual spans. It happens to work anyway, but this was
  not the intended use.
2024-02-17 13:46:24 -08:00
Kat Marchán a18a6444d9
chore: Release 2024-02-15 18:18:45 -08:00
Kat Marchán dc77b0cb5b
docs: update changelog 2024-02-15 18:18:32 -08:00
Nahor 03060245d8
feat(collection): add support for collection of labels (#341)
Fixes: https://github.com/zkat/miette/issues/315

Allow errors to have a number of labels determined at runtime.
An example of this is when the rust compiler labels all the arms of
a `match` expression when one of them has an incompatible type

To allow customization of the text for each label in a collection, add
support for using LabeledSpan in collections instead of just regular
spans
2024-02-15 18:14:04 -08:00
Brooks Rady 6f09250cca
feat(source): derive common traits for NamedSource, SourceSpan, and SourceOffset (#340) 2024-02-08 14:16:49 -08:00
Brooks Rady c2f06f6cca
feat(derive): enable more boxed types to be #[diagnostic_source] (#338) 2024-02-07 10:20:18 -08:00
Brooks Rady 6e829f8c0c
fix(tests): revert test-breaking changes of e5c7ae4 (#339)
The commit e5c7ae4 seemed to (potentially erronously?) remove a number of
spaces following the left `|` bar of some graphical report handler tests.
That change had no effect on the `syntax_highlighter_on_real_file()`
test, presumably because the trailing whitespace is removed by
`strip_ansi_escapes::strip_str()`, but it did break the
`triple_adjacent_highlight()` and `non_adjacent_hightlight()` tests.
Restoring the spaces removed in e5c7ae4 fixes the failing tests on main.

* fix(ci): move from minimal-versions to direct-minimal-versions
2024-02-07 10:17:42 -08:00
Kat Marchán ecb01022f0
chore: Release 2024-02-04 17:59:20 -08:00
Kat Marchán ea12e3f781
docs: update changelog 2024-02-04 17:59:06 -08:00
Kat Marchán a4011d174c
feat(deps): bump dependencies
Fixes: https://github.com/zkat/miette/issues/336

BREAKING CHANGE: This bumps owo-colors to 4.0, which is a breaking change because we expose its styles as part of the graphical renderer API
2024-02-04 17:26:25 -08:00
David Calavera c7144ee513
feat(fancy): Add option to change the link display text (#335)
This option allows to globally change the default `(link)` display text with any other text provider by users.
2024-02-04 16:54:18 -08:00
Kat Marchán cf2d8c0b2c
chore: Release 2024-02-03 20:27:47 -08:00
Kat Marchán e515a3c0ec
docs: update changelog 2024-02-03 20:27:39 -08:00
Kat Marchán ab7c066e76
fix(highlighter): ugh, missed another spot 2024-02-03 20:25:23 -08:00
Kat Marchán 3747fccf8d
test: fix some fancy tests after NamedSource change 2024-02-03 20:22:36 -08:00
Kat Marchán 1fa7f5241f
fix(fmt): remove nightly-only fmt flags 2024-02-03 20:14:01 -08:00
Kat Marchán 8b46679c36
fix(graphical): oops. Fix theme issue 2024-02-03 20:12:46 -08:00
Kat Marchán 9596405554
ci: fix is-terminal nonsense 2024-02-03 20:10:38 -08:00
Kat Marchán 5d4b262f7b
chore: Release 2024-02-03 20:01:50 -08:00
Kat Marchán 52b3240386
docs: update changelog 2024-02-03 20:01:25 -08:00
Kat Marchán ab59a7bc9b
feat(MSRV): Actually bump the MSRV to 1.70.0 2024-02-03 19:59:57 -08:00
Kat Marchán 29d000f201
feat(deps): bump some semver-breaking deps to newer versions 2024-02-03 19:50:56 -08:00
Kat Marchán 4c48584f30
feat(deps): remove once_cell dep in favor of `std::sync::OnceLock`
BREAKING CHANGE: This requires an MSRV bump to 1.70.0.
2024-02-03 19:50:33 -08:00
Kat Marchán e5c7ae469e
feat(deps): remove is-terminal dep in favor of `std::io::IsTerminal` 2024-02-03 19:50:30 -08:00
Adam Curtis e65d0a78cc
feat(highlighting): add syntax highlighting support with syntect crate (#313) 2024-02-03 19:47:46 -08:00
Adam Curtis 1df3b1a537
feat(source): Allow inner source type of a NamedSource to be borrowed (#254)
BREAKING CHANGE: This makes the `NamedSource` type generic over its `Source` type, instead of boxing it.
2024-02-03 19:40:17 -08:00
Gavrilikhin Daniil fad0e76ad2
feat(source): use `usize` for length (#265)
BREAKING CHANGE: This changes `SourceSpan`'s length type to `usize`.
2024-02-03 19:38:00 -08:00
Gavrilikhin Daniil 0d5c2ce753
feat(source-code): Don't override provided source code (#300)
BREAKING CHANGE: Source code is no longer overridden if it was provided by the diagnostic's own `source_code()` impl.
2024-02-03 19:33:59 -08:00
John Nunley c0a298e5a8
feat(deps): Bump terminal-size to v0.3.0 (#308)
BREAKING CHANGE: This requires an MSRV bump to 1.70.0.

Signed-off-by: John Nunley <dev@notgull.net>
2024-02-03 19:31:41 -08:00
Boshen f1dc89c076
fix(handler): remove the two extra `is_terminal` sys call from `MietteHandlerOpts::build` (#325)
`GraphicalReportHandler::new()` calls `GraphicalTheme::default()`

7ff4f874d6/src/handlers/graphical.rs (L52)

which calls `std::io::stdout().is_terminal()` and `std::io::stderr().is_terminal()`

7ff4f874d6/src/handlers/theme.rs (L72)

but this default theme is overridden by `with_theme(theme)`.
2024-02-03 19:12:49 -08:00
Brooks Rady cb2ae2e18b
fix(graphical): render cause chains for inner errors (#330)
The default `GraphicalReportHandler` disables the printing of cause
chains for any inner errors (errors `related()` to a source diagnostic)
when it disables nested footer printing. This results in lost cause
chain information when printing with the default report handler.
2024-01-30 16:03:01 -08:00
Benjamin Lee 55bfc42016
tests: improve robustness of color_format tests (#329)
Previously, these tests would have spurious failures when NO_COLOR or
FORCE_COLOR was set in the user's environment, since we weren't clearing
one variable before testing a value for the other one. The previous
version of the code also did not restore environment variable values on
panic, which could cause spurious failures in other tests after one test
fails.
2024-01-11 14:13:00 -08:00
Hytak 19c22143cb
feat(graphical): render disjoint snippets separately for cleaner output (#324) 2024-01-11 10:42:32 -08:00
Zanie Blue b0744462ad
feat(graphical): Add `wrap_lines: bool` option allowing wrapping be disabled entirely (#328) 2024-01-04 10:44:52 -08:00
Jonathan Dönszelmann 7ff4f874d6
fix(graphical): rendering bug on small spans in large spans (#316)
Fixes: https://github.com/zkat/miette/issues/317

It turned out there were two really. One related to how many characters
were added for the arrowheads in the gutter, and one where the gutter
was extended to a number of characters, including ansi escape codes.
However, because ansi escape codes are rather big, there would never be
any extension since the system thought the string was already long
enough, even though you don't actually see the width of those codes.
2023-11-15 11:40:16 -08:00
Jonathan Dönszelmann 865d67c8dd
feat(graphical): support rendering labels that contain newlines (#318)
Fixes: https://github.com/zkat/miette/issues/85
2023-11-15 10:39:29 -08:00
Jonathan Dönszelmann 251d6d5929
fix(docs): add example to README and docs fixing #96 (#319) 2023-11-15 10:35:46 -08:00
Zanie Blue fd77257cee
feat(graphical): Expose additional `textwrap` options (#321) 2023-11-15 10:34:24 -08:00
ManicMarrc c7ba5b7e52
feat(derive): Make `miette-derive` be able to be turned off (#304) 2023-11-09 13:22:47 -08:00
Benjamin Lee 3d6f903df0
fix(formatting): Fix formatting bug when an empty span is not aligned to a char boundary (#314)
Previous output looked like this:

---- single_line_with_wide_char_unaligned_span_empty stdout ----
Error: oops::my::bad

  × oops!
   ╭─[bad_file.rs:2:4]
 1 │ source
 2 │   👼🏼text
   ·   ─▲
   ·    ╰── this bit here
 3 │     here
   ╰────
  help: try doing it better next time?

Note that the .max(start + 1) term is still necessary in the nonempty
branch, since it's possible to have a nonempty span covering zero-width
text.

* remove uncessary if statement

start > end in all cases.
2023-11-09 13:21:32 -08:00
Matt a8b4ae012a
fix(graphical): Extend error text span to whole code points (#312)
Fixes: https://github.com/zkat/miette/issues/223

This fixes a panic when an error starts inside a Unicode code point. The
range is extended to start (or end) at the beginning (or end) of the
character inside which the byte offset is located.
2023-11-02 09:33:55 -07:00
Andre Meyering d37ada876a
docs(README): Move import of `NamedResult` to where it is used (#309)
An example in README.md makes use of `miette::NamedResult` .
It is imported in the second "example-step", but already used in the first one. Beginners, that copy the example step-by-step to understand it, will run into compile errors, as `NamedResult` was not imported.
2023-10-23 10:09:00 -07:00
Gavrilikhin Daniil 88d00e0e20
feat(derive): Allow optional sources in derive (#301)
Fixes: https://github.com/zkat/miette/issues/217
2023-10-20 20:50:15 -07:00
Thomas Versteeg ba313282a8
docs: typo in README.md (#295)
Dynamic diagnostics example contains a macro invocation without a '!' symbol.
2023-09-29 06:56:09 -07:00
Bruce Mitchener 06b348230a
fix(clippy): Add missing semicolons where nothing is returned. (#293) 2023-09-25 10:33:07 -07:00
Bruce Mitchener 1f448e4775
fix(tests): Fix `cargo test` with default features. (#294)
A couple of tests require `fancy-no-backtrace`, so mark them
accordingly.
2023-09-25 10:31:44 -07:00