Commit Graph

215 Commits

Author SHA1 Message Date
Boshen b30ef81214
fix: setting NO_COLOR should not print ansi codes for non-terminals
closes #380
2024-06-12 00:12:48 +08:00
Sébastien Mischler b82cc81b8e
fix(docs): `alt` attribut for `single-line-example.png` (#372)
* fix(docs): `alt` attribut for `single-line-example.png`

The white line breaks in the `alt` attribute prevented the `single-line-example.png` image from being displayed.

* Revert "fix(docs): `alt` attribut for `single-line-example.png`"

This reverts commit 2e97d568aa.

* fix: image link in `lib.rs` instead of `readme.md`

* feat(docs): cargo make readme
2024-05-01 15:20:01 -07:00
Will Bush ea4296dace
fix(clippy): Fix clippy lints in docs (#365)
* Fix commented out code in lib.rs docs not found in README.md

* Fix clippy lints in README.md and lib.rs
2024-04-12 23:11:30 -07:00
TrapinchO 97766e8d90
docs: fix up previous docs change a bit (#362) 2024-04-03 14:58:36 -07:00
Brooks Rady 3eabbcebf1
fix(graphical): fix nested error wrapping (#358)
Fixes: https://github.com/zkat/miette/issues/333
2024-03-27 16:20:06 -07:00
Yiyu Lin 22b29eec38
docs: use `cargo readme` to update (#351) 2024-02-27 21:58:02 -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
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
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 ab7c066e76
fix(highlighter): ugh, missed another spot 2024-02-03 20:25:23 -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 ab59a7bc9b
feat(MSRV): Actually bump the MSRV to 1.70.0 2024-02-03 19:59:57 -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
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
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
Bruce Mitchener 06b348230a
fix(clippy): Add missing semicolons where nothing is returned. (#293) 2023-09-25 10:33:07 -07:00
Will Crichton db0b7e403a
feat(labels): Add support for primary label in specifying line/col information (#291) 2023-09-20 15:36:33 -07:00
Bruce Mitchener cc81382a60
fix(misc): Improve ci and fix clippy (#290)
* ci: Update actions, replace actions-rs.

* `actions/checkout` is updated from `v1` to the current `v4`.
* `actions-rs/toolchain` is replaced by `dtolnay/rust-toolchain` as
  the `actions-rs` actions haven't been maintained in a long time.

* clippy: Remove unnecessary call to `into_iter`.

The parameter takes `IntoIterator`, so we don't have to call
`into_iter` at the call site.

* clippy: Remove explicit lifetime that can be elided.

* clippy: tests: Fix useless conversion warnings.

* clippy: tests: Remove call to `format!`.

* Fix minimal-versions build.

Due to changes in the nightly compiler, using a recent nightly
requires proc-macro2 1.0.60 or later:

https://github.com/dtolnay/proc-macro2/issues/356

* ci: Use is-terminal 0.4.7 for MSRV builds.

is-terminal 0.4.8 updated its MSRV to 1.63, so we can't use it
with our MSRV of 1.56. Force usage of the older version which has
an older MSRV.
2023-09-20 10:37:40 -07:00
Bruce Mitchener a9c2bae9dc
docs: Improve linking. (#289) 2023-09-18 09:12:56 -07:00
Gavrilikhin Daniil bfacb6329f
doc: document `#[diagnostic(transparent)]` (#266) 2023-07-15 18:46:54 -07:00
Bruce Mitchener c3d4db2618
docs: Fix broken links from macro docs. (#278) 2023-07-07 17:16:53 -07:00
Bennett Hardwick 2e3e5c9d15
feat(protocol): add StdError impl for Box<dyn Diagnostic + Send + Sync> (#273) 2023-06-28 18:58:35 -07:00
Marcel Müller aefe323780
feat(nested): Render inner diagnostics (#170) 2023-05-18 15:41:17 -07:00
kleines Filmröllchen 46adb3bc6a
feat(const): Constify various functions (#263)
This is primarily aimed at making `SourceSpan` and `SourceOffset` usable
in const contexts.

Constifiable functions were found with the
`clippy::missing_const_for_fn` lint, though it reported at least two
false positives.
2023-05-17 15:42:42 -07:00
Gavrilikhin Daniil c25676cb1f
feat(serde): Add `serde` support (#264)
Fixes: https://github.com/zkat/miette/issues/260
2023-05-14 01:43:40 -07:00
Gavrilikhin Daniil 024145dbdd
Add dynamic diagnostic (#262) 2023-05-13 13:59:43 -07:00
Alexander Seiler 675f3411e3
fix(misc): Correct some typos (#255)
Signed-off-by: Alexander Seiler <seileralex@gmail.com>
2023-04-25 21:07:18 -07:00
Kat Marchán adbff65e4e
fix(narrated): put URLs in their own line
This makes it easier for screen readers to access/visit.
2023-04-18 08:55:18 -07:00
Andrew Hickman be3b254751
feat(source): Add getter for NamedSource name (#252) 2023-04-18 08:55:08 -07:00
Kat Marchán b0453215f6
feat(panic): improved backtrace handling
Fixes: https://github.com/zkat/miette/issues/92
2023-03-31 17:08:20 -07:00