Giter VIP home page Giter VIP logo

miette's People

Contributors

andrewhickman avatar attila-lin avatar benjamin-l avatar bnjjj avatar boshen avatar cad97 avatar cormacrelf avatar dbanty avatar erratic-pattern avatar g-plane avatar gankra avatar gavrilikhin-d avatar icewind1991 avatar jdonszelmann avatar manicmarrc avatar matthiasbeyer avatar mattx avatar nahor avatar nathanwhit avatar olson-sean-k avatar phantomical avatar sunshowers avatar tailhook avatar thelostlambda avatar theneikos avatar trapincho avatar virtualritz avatar waywardmonkeys avatar zanieb avatar zkat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

miette's Issues

`Report` doesn't forward diagnostic fields

The wrapper Diagnostic types that Report uses should be marked as transparent diagnostics, so stuff like snippets and codes show up when you .context() on something. Oops!

Snippet-level help/info text

Miette currently only supports a single "help" message, at the end of a whole diagnostic. It might be handy to do something like what rustc does, where multiple info/help messages can be attached to snippets themselves? This might potentially be resolved instead by whatever #47 ends up looking like, with the addition of multiple "footer" labels (help/info/suggestion/etc).

derive: snippet support

The current derive macro supports code, help, and derive, but doesn't really handle the snippet part of miette. Extend the macro so that you can write stuff like this:

#[derive(Debug, Error, Diagnostic)]
#[diagnostic(code(math::bad_arithmetic))]
#[error("Tried to add a {bad_type} to a {good_type}")]
pub struct MyErr {
  good_type: Type,
  bad_type: Type,
  bad_var: Var,
  src: PathBuf,

  // The overall span of code that will be rendered.
  #[context(src, "This region is where things went wrong")]
  ctx: SourceSpan,

  // A highlight (basically something to underline)
  #[highlight(ctx, "This is a {bad_type}")]
  bad_var_span: SourceSpan,

  // Can have multiple highlights.
  #[highlight(ctx, "This is a {good_type}")]
  good_var_span: SourceSpan,
}

Label span is rendered incorrectly in report.

I'm implementing Diagnostic manually for an error type so that it can provide different labels depending on the nature of the error. While testing, I noticed this report, which seems to render the span of the here label incorrectly:

Error: glob::rule

  x invalid glob expression: singular tree wildcard `**` in alternative

   ,----
 1 | {foo,**,bar,baz}
   : ^^^^^^^^|^^^^^^^
   :         |`-- here
   :         `-- in this alternative
   `----

I printed the LabeledSpans provided by Diagnostic::labels and they look correct to me:

[LabeledSpan { label: Some("in this alternative"), span: SourceSpan { offset: SourceOffset(0), length: SourceOffset(16) } }, LabeledSpan { label: Some("here"), span: SourceSpan { offset: SourceOffset(5), length: SourceOffset(2) } }]

Note that the span for the here label has an offset of 5 and length of 2, which should isolate ** in the source text for this error. I've tried relocating the token that ultimately emits this error and the span always appears correct but renders in the same way (spanning the entire alternative token). It almost looks as if the span is being replaced by the span of the in this alternative label.

I'm using version 3.0.0 of miette and other cases using as many as three separate labels render as expected. Any ideas? Thanks!

More flexible and customizable ReportHandler situation

The default reporters are fantastic, and there's even hooks to customize them with, but you're kinda stuck with the overall look beyond what the GraphicalTheme provides.

It's not ideal for everyone using miette to have "the miette look". It should be possible (and easy!) to piece together your own handler while still taking advantage of the fairly complex snippet and such reporting code.

This might also involve merging the graphical and narrated handlers into two modes of one big handler (maybe even include #29 in that). Also all the logic for switching between them and figuring out some terminal specific things.

`#[document_codes]` attribute macro

So it turns out that derive macros can't expand anything in-place: they can only generate new code in a completely different area.

We need a #[document_codes] attribute macro that you can slap at the toplevel of anything using the Diagnostic derive, which goes through and adds #[doc(alias = "my::code::here")] to the error struct or enum, in the appropriate places.

This might be tricky because you're injecting stuff in the middle of a tokenstream, but maybe it's easier than it sounds?

Support for multiple diagnostics

Right now, miette supports multiple snippets. It also supports a single cause chain (though all .source()s have to be StdError instead of Diagnostic.

It would be nice for miette, maybe at the Report level, to support multiple diagnostics in some way that makes sense. This issue needs some thinking and investigation into actual use-cases before implementation/proposal.

Diagnostic suggestion support

One really cool relatively recent addition to rustc is the ability to add suggestions (in green) that propose specific changes to a snippet and highlight the changed text. It would be nice for this to have first-class support in miette. Maybe it can be implemented by just adding a "type" to DiagnosticSnippet to change its display mode?

Snippet message not rendered when source is not named

This goes back to #23, when the "header" concept was introduced. The header is not rendered at all when the source returns None for .name(). (Back in v0.12 you needed SourceSpan::new_labeled.)

Workaround atm is to give every source a name. But given Source is implemented for unnamed String/Arc<String> miette should be able to render the header without a name.

Using String/ Arc<String>

Error: โ”€โ”€โ”€โ”€[code::here]โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

    ร— std::error::Error display message

 1 โ”‚ one two thre
   ยท     โ”€โ”ฌโ”€
   ยท      โ•ฐโ”€โ”€ highlight message

Using NamedSource

Error: โ”€โ”€โ”€โ”€[code::here]โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

    ร— std::error::Error display message

   โ•ญโ”€โ”€โ”€[example.txt:1:1] snippet message:
 1 โ”‚ one two thre
   ยท     โ”€โ”ฌโ”€
   ยท      โ•ฐโ”€โ”€ highlight message


Now that I figured out the issue, it's like a few lines to edit across a few printers, so lemme give it a go.

While I'm thinking about this, I think we could implement Source on &'static str because these can be cloned just as freely as the others and are obviously 'static. Not super useful except for testing.

Weird tab character rendering

I'm using miette in a parser that deals with tab \t indents and so far noticed the following:

  • miette renders one \t as the number of spaces configured in the terminal (OK)
  • miette counts one \t's width as equal to one space and displays the arrow/label according to this width (Breaks because of the above, but should be possible to deal with by the developer)

So I decided to calculate number of tabs in the line, multiply it by tab width, and add that to the offset minus the number of tabs. Example:

  1. \t\t with tab width 4 = 8
  2. Offset of some char that caused the error is 10
  3. We add 10 + 8 and subtract 2 (number of tabs) and give that number as SourceSpan (16, 0)

In my repro this places the arrow in the correct position. But weird stuff happens if I have a really big offset (exactly 37 and more chars). It either just renders the line without rendering arrow/label or simply panics with this error:

thread 'main' panicked at 'failed printing to stderr: formatter error', library/std/src/io/stdio.rs:935:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Here's a reproduction:
https://github.com/jlkiri/miette-tab-error-repro

Provide clickable links for error codes in terminal output

Some modern terminal support escape codes that can be used to insert clickable links on terminal text. These are used, for example, in GCC's diagnostic output.

It would be great if the error codes output by miette's terminal formatter would be clickable links that directly open the documentation page for the error.

Some information about the terminal escapes for links is here: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda

[Epic]: Nicer reporter

The current reporter is "okay", but it's nothing to write home about. This is a tracking issue for writing a version of the reporter that we can really show off!

full format capabilities for `help()`

Right now, help is pretty limited as far as formatting goes. It should be expanded to allow everything thiserror supports, including shorthand format strings and enum variant access.

forwarding compile test succeeded when it should have failed

I'm getting the following on cargo t:

failures:

---- src\compile_test.rs - compile_test::ForwardWithoutCode (line 113) stdout ----
Test compiled successfully, but it's marked `compile_fail`.
---- src\compile_test.rs - compile_test::ForwardWithoutCode (line 98) stdout ----
Test compiled successfully, but it's marked `compile_fail`.

failures:
    src\compile_test.rs - compile_test::ForwardWithoutCode (line 113)
    src\compile_test.rs - compile_test::ForwardWithoutCode (line 98)

@cormacrelf does this make any sense to you? Did your more recent changes make this issue moot?

Issue with whitespaces and byteoffset

I try to use miette with a parser, if the node parsed is of type error then I use miette to render the error. I have an issue because in miette it seems you're skipping '\n' and whitespaces into the source code. Then when I try to specify my SourceSpan thanks to the byte position it doesn't work at all because it the byte position with whitespaces and in your code you use the source_code string without any whitespaces.

How can I do this correctly ?

example of my code:

let err = ParsingError {
	bad_bit: (node.start_byte(), node.end_byte()).into(), // ISSUE HERE
	src: src.to_string(),
};

Derive macro: single field for multiple snippets

Allowing dynamic list of spans to provide highlights you can be good for using miette to wrap tools like TypeScript (tsc).

Looking at the source code, maybe Vec<SourceSpan> might not cut it, but introducing a new LabelledSourceSpan and allowing everything that is Into<Vec<LabelledSourceSpan>> could also make sense.

What do you think?

Syntax highlighting support

Add support for syntax highlighting through syntect.

I figure this can be done by having the graphical handler take an optional SyntaxSet, and have an optional identifier token method as part of SpanContents, so the renderer can color code accordingly.

The biggest challenge here is designing things such that things are appropriately feature flagged and don't grow binaries too much?

Error message should provide link to ruget + miette bug trackers

In @zkat's tweet https://twitter.com/zkat__/status/1428962008699793412/photo/1, the final message is

This is a bug. It might be in ruget, or it might be in the source
you're using, but it's definitely a bug and should be reported.

The question arises, to whom or what should the bug be reported?

Providing a link to both ruget and miette's Issues pages would be a great start, and if it's not in miette or ruget then whoever is maintaining those projects can guide the submitter to a more appropriate project to file a bug with.

toplevel error footer

Miette should be able to automatically print a static or customizable error message as a footer to all generic errors for you.

For example:

Need help? Check out https://voltpkg.com/troubleshoot/internet::connection::404 <- notice the fact that i can add my custom error code here

address accessibility story

How accessible are these errors? What changes could be made to make them easier to consume for visually impaired folks? We should have a reasonable story for this before 1.0 goes out. Right now, I don't imagine it's very useful to get these error messages.

split off DiagnosticReport + reporters into their own library?

No rush, I think, because the intention is very much that anyone using miette will also probably be using the reporter, but I'm hoping people write their own bespoke reporters against the "protocol".

...maybe that means we need miette-protocol, and miette is the Big Chonker library? That would let us do this refactor without being semver-breaking. ๐Ÿค”

Words on the first line being dropped?

Hey,

First up, this library is dope. Love your work. ๐Ÿš€

I'm having one small issue though - if I have a SourceSpan that points somewhere in the first line of some source code, that first line seems to get chopped.

Here's a test to reproduce:

#[cfg(test)]
mod miette_test {
    use miette::{
        Diagnostic, GraphicalReportHandler, GraphicalTheme, SourceSpan, ThemeCharacters,
        ThemeStyles,
    };
    use thiserror::Error;

    #[derive(Error, Debug, Diagnostic)]
    #[error("some error")]
    #[diagnostic(help("where did the word 'imagine' go!?"))]
    struct SomeError {
        #[source_code]
        some_code: String,
        #[label("'imagine' should come before this")]
        some_span: SourceSpan,
    }

    #[test]
    fn whytho() {
        let mut rendered = String::new();
        let diagnostic = SomeError {
            some_code: "imagine this is some code\n\nyou're seeing all of this line".to_owned(),
            some_span: (8, 0).into(),
        };

        GraphicalReportHandler::new()
            .with_theme(GraphicalTheme {
                characters: ThemeCharacters::ascii(),
                styles: ThemeStyles::none(),
            })
            .with_context_lines(3)
            .render_report(&mut rendered, &diagnostic)
            .unwrap();
        assert_eq!(
            &rendered,
            r#"
  x some error
   ,-[1:1]
 1 | this is some code
   : ^
   : `-- 'imagine' should come before this
 2 | 
 3 | you're seeing all of this line
   `----
  help: where did the word 'imagine' go!?
"#
        );
    }
}

Prepare docs for 1.0

everything, including the derive macro, should be well-documented, with reasonable guide-level documentation showing folks how to use miette!

MietteReporter: Add multiline highlight support

One of the nice things that miette should handle out of the box is having highlights that point to multi-line code blocks.

The protocol as it is right now should be able to handle it just fine, but this seems like just a generally pretty hard thing to write a reporter for, so I'm struggling.

Let me know if you care a lot about this and I'll gladly leave it in your hands, though!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.