Skip to content

Column number should start at 1 and not 0 #17

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

Closed
GodTamIt opened this issue Nov 25, 2019 · 2 comments
Closed

Column number should start at 1 and not 0 #17

GodTamIt opened this issue Nov 25, 2019 · 2 comments

Comments

@GodTamIt
Copy link
Contributor

Given this code:

let snippet = Snippet {
    title: Some("failed to parse file".to_owned()),
    footer: vec![],
    slices: vec![Slice {
        source: r#"This is an example
content of the slice
which will be annotated
with the list of annotations below."#
            .to_string(),
        line_start: 26,
        origin: Some("chris.beep".to_owned()),
        fold: false,
        annotations: vec![SourceAnnotation {
            label: "hello world".to_owned(),
            annotation_type: AnnotationType::Error,
            range: (13, 20),
        }],
    }],
};

This results in the following output:

error: failed to parse file
  --> chris.beep:26:13
   |
26 | This is an example
   |              ^^^^^^^ hello world
27 | content of the slice
28 | which will be annotated
29 | with the list of annotations below.

Because the output should be for humans, shouldn't the location be chris.beep:26:14?

@digama0
Copy link
Contributor

digama0 commented Jan 5, 2020

I just run across this issue as well. It also affects editors like VS Code that parse console output for expressions of the form foo.txt:1:2 and turn them into links into the file foo.txt, line 1, column 2 (1-based).

I think the fix is the following (in from_snippet.rs:95) but I don't know what needs fixing for tests and such:

        let mut col = 1;
        let mut row = slice.line_start;

        for item in body.iter() {
            if let DisplayLine::Source {
                line: DisplaySourceLine::Content { range, .. },
                ..
            } = item
            {
                if annotation.range.0 >= range.0 && annotation.range.0 <= range.1 {
                    println!("hi");
-                   col = annotation.range.0 - range.0;
+                   col = annotation.range.0 - range.0 + 1;
                    break;
                }
                row += 1;
            }
        }

GodTamIt added a commit to GodTamIt/annotate-snippets-rs that referenced this issue Jan 12, 2020
This is a small change to start column numbers from 1 instead of 0.

Issue: rust-lang#17
@GodTamIt
Copy link
Contributor Author

Should be fixed with #22 landing now. Closing this.

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

No branches or pull requests

2 participants