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

Order-preserving error reporting #285

Closed
yannham opened this issue Sep 14, 2020 · 1 comment · Fixed by #286
Closed

Order-preserving error reporting #285

yannham opened this issue Sep 14, 2020 · 1 comment · Fixed by #286

Comments

@yannham
Copy link

yannham commented Sep 14, 2020

Currently, the order in which labels are displayed depends on the respective position of the annotated snippets in the source.
For example, if I do:

let mut files = Files::new();
let id = files.add("<test>", "line 1\nline 2");
let writer = StandardStream::stderr(ColorChoice::Always);
let config = codespan_reporting::term::Config::default();
codespan_reporting::term::emit(&mut writer.lock(), &config, &files, &diag).unwrap();

let diag = Diagnostic::error()
    .with_message("Test bad order")
    .with_labels(vec![Label::primary(id, 7..12).with_message("first msg"),
        Label::primary(id, 0..6).with_message("second msg")]);

codespan_reporting::term::emit(&mut writer.lock(), &config, &files, &diag).unwrap();

I get

error: Test bad order
  ┌─ <test>:1:1
  │
1 │ line 1
  │ ^^^^^^ second msg
2 │ line 2
  │ ^^^^^^ first msg

The second message is reported first. This makes sense for compile-time errors, but in my case I use codespan for an interpreted language and I want to report runtime errors where there is an associated temporal order of the labels, such as printing a callstack for example (a list of successive calls to some functions). In this case I don't want the labels to be re-ordered based on the position of their snippet in the original source file, and I would like the end result to be:

error: Test bad order
  ┌─ <test>:1:1
  │
2 │ line 2
  │ ^^^^^^ first msg
1 │ line 1
  │ ^^^^^^ second msg

Is there a simple way to do that using codespan ?

@Johann150
Copy link
Collaborator

Thanks for your issue, but this was basically already discussed in #231.
This means there is no simple way to do this in the current version of codespan. Maybe by using multiple diagnostics? But other than that I think codespan is not quite intended for what you want to do.

Maybe this should be added to the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants