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

Annotate range cannot match \t #58

Closed
tisonkun opened this issue Jun 25, 2023 · 2 comments
Closed

Annotate range cannot match \t #58

tisonkun opened this issue Jun 25, 2023 · 2 comments

Comments

@tisonkun
Copy link

tisonkun commented Jun 25, 2023

use std::fs;
use std::path::PathBuf;

use annotate_snippets::display_list::{DisplayList, FormatOptions};
use annotate_snippets::snippet::{AnnotationType, Slice, Snippet, SourceAnnotation};

fn main() {
    let sql = fs::read_to_string(PathBuf::from("21.sql")).unwrap();
    let source = sql.as_str();

    println!("source: {:?}", source);
    println!("capture: {}", &source[51..52]);

    let snippet = Snippet {
        title: None,
        footer: vec![],
        slices: vec![Slice {
            source,
            line_start: 1,
            origin: None,
            annotations: vec![SourceAnnotation {
                range: (51, 52),
                label: "",
                annotation_type: AnnotationType::Error,
            }],
            fold: false,
        }],
        opt: FormatOptions {
            color: true,
            ..Default::default()
        },
    };

    println!("{}", DisplayList::from(snippet));
}

... output:

source: "-- using default substitutions\r\n\r\n\r\nselect\r\n\ts_name,\r\n\tcount(*) as numwait\r\nfrom\r\n\tsupplier,\r\n\tlineitem l1,\r\n\torders,\r\n\tnation\r\nwhere\r\n\ts_suppkey = l1.l_suppkey\r\n\tand o_orderkey = l1.l_orderkey\r\n\tand o_orderstatus = 'F'\r\n\tand l1.l_receiptdate > l1.l_commitdate\r\n\tand exists (\r\n\t\tselect\r\n\t\t\t*\r\n\t\tfrom\r\n\t\t\tlineitem l2\r\n\t\twhere\r\n\t\t\tl2.l_orderkey = l1.l_orderkey\r\n\t\t\tand l2.l_suppkey <> l1.l_suppkey\r\n\t)\r\n\tand not exists (\r\n\t\tselect\r\n\t\t\t*\r\n\t\tfrom\r\n\t\t\tlineitem l3\r\n\t\twhere\r\n\t\t\tl3.l_orderkey = l1.l_orderkey\r\n\t\t\tand l3.l_suppkey <> l1.l_suppkey\r\n\t\t\tand l3.l_receiptdate > l3.l_commitdate\r\n\t)\r\n\tand s_nationkey = n_nationkey\r\n\tand n_name = 'SAUDI ARABIA'\r\ngroup by\r\n\ts_name\r\norder by\r\n\tnumwait desc,\r\n\ts_name;\r\n"
capture: ,
   |
 1 | -- using default substitutions
 2 | 
 3 | 
 4 | select
 5 |    s_name,
   |       ^
 6 |    count(*) as numwait
 7 | from
 8 |    supplier,
 9 |    lineitem l1,
10 |    orders,
11 |    nation
12 | where
13 |    s_suppkey = l1.l_suppkey
14 |    and o_orderkey = l1.l_orderkey
15 |    and o_orderstatus = 'F'
16 |    and l1.l_receiptdate > l1.l_commitdate
17 |    and exists (
18 |            select
19 |                    *
20 |            from
21 |                    lineitem l2
22 |            where
23 |                    l2.l_orderkey = l1.l_orderkey
24 |                    and l2.l_suppkey <> l1.l_suppkey
25 |    )
26 |    and not exists (
27 |            select
28 |                    *
29 |            from
30 |                    lineitem l3
31 |            where
32 |                    l3.l_orderkey = l1.l_orderkey
33 |                    and l3.l_suppkey <> l1.l_suppkey
34 |                    and l3.l_receiptdate > l3.l_commitdate
35 |    )
36 |    and s_nationkey = n_nationkey
37 |    and n_name = 'SAUDI ARABIA'
38 | group by
39 |    s_name
40 | order by
41 |    numwait desc,
42 |    s_name;

If I change all \r\n to \n, it can correctly point at ,.

If I change all \t to spaces and correct count the span (I have a outer fn to count chars, here it becomes 54..55), it can correctly point at ,

  • Env: macOS
  • Lib Version: 0.9.1
@tisonkun
Copy link
Author

No. The problem is not about \r\n, it's about \t.

@tisonkun tisonkun changed the title Annotate range cannot match among \n and \r\n Annotate range cannot match \t Jun 25, 2023
@epage
Copy link
Contributor

epage commented Mar 13, 2024

Closing in favor of #25

@epage epage closed this as not planned Won't fix, can't repro, duplicate, stale Mar 13, 2024
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