Commit Graph

190 Commits

Author SHA1 Message Date
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
Aria Beingessner 0b445dc2b4
fix(tests): disable doctest that doesn't work with default feature flags (#248) 2023-03-30 09:19:51 -07:00
Aria Beingessner 159f2b354b
fix(colors): change unicode to default to ansi (#249) 2023-03-30 09:18:52 -07:00
Yoni Feng 566d6be6e3
misc(perf): nit perf improvements (#244) 2023-03-29 20:21:40 -07:00
George Pollard 443d240f49
fix(atty): Switch out `atty` for `is-terminal` (#229) 2023-03-13 21:10:21 -07:00
Erich Gubler ed486c959d
feat(protocol): implement `Ord` for `Severity` (#240)
Fixes: https://github.com/zkat/miette/issues/239
2023-03-01 15:48:11 -08:00
dalance 3497508aa9
fix(graphical): Fix wrong severity of related errors (#234) 2023-02-08 16:26:27 -08:00
Lucas Kent ebc61b5cf8
docs: Mention miette::miette! macro under "... in application code" (#233) 2023-01-30 10:21:50 -08:00
Benjamin Lee 8b56d277ef
fix(graphical): Fix panic with span extending past end of line (#221)
Fixes: #215 

This also changes the behavior with spans including a CRLF line-ending.
Before the panic bug was introduced, these were rendered with the CRLF
being two visual columns wide. Now, any span extending past the EOL is
treated as including one extra visual column.
2022-11-23 16:35:13 -08:00
Sean Lynch c857595e1a
feat(SourceCode): Implement SourceCode for Vec<u8> (#216) 2022-11-06 17:42:33 -08:00
Benjamin Lee b8810ee3d8
fix(graphical): Fix panic with zero-width span at end of line (#204)
This was introduced in 196c09ce7a, and is
a simple off-by-one error.
2022-10-28 16:20:10 -07:00
Rain ec7df952eb tests: add tests to ensure that boxed reports forward all methods
In previous commits we found that boxed reports weren't forwarding every
method. Add a test to ensure that they do.
2022-10-24 19:04:51 -07:00
Rain 1a27033d7a feat(error): impl AsRef<dyn StdError> for Report
This seems like an easy implementation to fill out, and will be used for
tests in the following commit.
2022-10-24 19:04:51 -07:00
Rain 3fc5c04cbb fix(wrapper): complete forwarding Diagnostic implementations
They were missing `diagnostic_source()` which was recently added.
2022-10-24 19:04:51 -07:00
Rain 0660d2f43c feat(report): `Report::new_boxed`
This is already currently accessible with `miette!`, but I missed that
because it isn't clearly documented. Add a constructor to mirror
`Report::new` and `Report::msg`.
2022-10-24 19:04:51 -07:00
Benjamin Lee 196c09ce7a
fix(graphical): Align highlights correctly with wide unicode characters and tabs (#202)
Fixes: https://github.com/zkat/miette/issues/97
Fixes: https://github.com/zkat/miette/issues/87

Tabs are always expanded to spaces by the graphical handler, and `tab_width` now defaults to 4. Instead of replacing every tab with a fixed number of spaces, spaces are used to align to the next tabstop. `tab_width` controls the space between tabstops rather than the fixed width of each tab character.

Co-authored-by: Benjamin Lee <benjamin@computer.surgery>
2022-09-10 14:20:37 -07:00
Nathan Whitaker 5f3429b062
fix(miri): Resolve Miri's concerns around unsafe code (#197) 2022-08-25 08:30:18 -07:00
Pig Fang 12279f83a8
docs: remove sentence about `cargo-edit` (#198) 2022-08-21 08:33:51 -07:00
Luca Palmieri b9ea587159
feat(graphical): Allow miette users to opt-out of the rendering of the cause chain (#192)
Fixes: https://github.com/zkat/miette/issues/191
2022-08-09 17:32:02 -07:00
Andrew Hickman c3e6c98336
fix(utils): Fix off-by-one error in SourceOffset::from_location (#190) 2022-08-02 14:38:22 -07:00
Leon Breedt c95f58c87a
feat(json): `causes` support (#188)
Fixes: https://github.com/zkat/miette/issues/187
2022-07-31 11:47:06 -07:00
Kat Marchán e286c705fd
fix(docs): readme was getting cut off during generation
Fixes: https://github.com/zkat/miette/issues/174
2022-07-24 10:24:07 -07:00
Rain 12dc40070a
fix(graphical): handle an empty source (#183)
In some cases the source can be completely empty -- handle that in a reasonable fashion.
2022-07-08 19:41:12 -07:00
Andrew Hickman 85da6a8407
feat(protocol): Implement SourceCode for Arc<str> (and similar types) (#181) 2022-06-25 10:58:56 -07:00
Benjamin Lee 1816b06a2e
feat(theme): restructure automatic color selection (#177)
Fixes: https://github.com/zkat/miette/issues/176

Change the default ansi color theme to use colors that are more similar
to the colors from the default RGB theme. In particular, don't use red
for any of the span labels, since that color is also used for errors.

BREAKING CHANGES:
* the default theme now prefers ANSI colors, even if RGB is supported
* `MietteHandlerOpts::ansi_colors` is removed
* `MietteHandlerOpts::rgb_color` now takes an enum that controls the
  color format used when color support is enabled, and has no effect
  otherwise.
2022-06-24 08:30:36 -07:00
Aria Beingessner b193d3c002
fix(json): Don't escape single-quotes, that's not valid json (#180) 2022-06-24 08:28:01 -07:00