Skip to content

Commit

Permalink
Better handling of tab in error
Browse files Browse the repository at this point in the history
  • Loading branch information
sanxiyn committed May 12, 2016
1 parent 50909f2 commit c331032
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/libsyntax/errors/snippet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,15 @@ impl StyledBuffer {
self.text[line][col] = chr;
self.styles[line][col] = style;
} else {
while self.text[line].len() < col {
self.text[line].push(' ');
let mut i = self.text[line].len();
while i < col {
let s = match self.text[0].get(i) {
Some(&'\t') => '\t',
_ => ' '
};
self.text[line].push(s);
self.styles[line].push(Style::NoStyle);
i += 1;
}
self.text[line].push(chr);
self.styles[line].push(style);
Expand Down
24 changes: 24 additions & 0 deletions src/libsyntax/errors/snippet/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,30 @@ fn make_string(lines: &[RenderedLine]) -> String {
.collect()
}

#[test]
fn tab() {
let file_text = "
fn foo() {
\tbar;
}
";

let cm = Rc::new(CodeMap::new());
let foo = cm.new_filemap_and_lines("foo.rs", file_text);
let span_bar = cm.span_substr(&foo, file_text, "bar", 0);

let mut snippet = SnippetData::new(cm, Some(span_bar));
snippet.push(span_bar, true, None);

let lines = snippet.render_lines();
let text = make_string(&lines);
assert_eq!(&text[..], &"
--> foo.rs:3:2
3 |> \tbar;
|> \t^^^
"[1..]);
}

#[test]
fn one_line() {
let file_text = r#"
Expand Down

0 comments on commit c331032

Please sign in to comment.