Fix error line display slicing.
This commit is contained in:
parent
652da4ca55
commit
df74f2cde9
1 changed files with 7 additions and 5 deletions
|
@ -85,7 +85,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
|
||||||
// get access to the necessary lines.
|
// get access to the necessary lines.
|
||||||
auto rdr = ioivec::file_reader(lines.name);
|
auto rdr = ioivec::file_reader(lines.name);
|
||||||
auto file = str::unsafe_from_bytes_ivec(rdr.read_whole_stream());
|
auto file = str::unsafe_from_bytes_ivec(rdr.read_whole_stream());
|
||||||
auto fm = codemap::get_filemap(cm, lines.name);
|
auto fm = get_filemap(cm, lines.name);
|
||||||
|
|
||||||
// arbitrarily only print up to six lines of the error
|
// arbitrarily only print up to six lines of the error
|
||||||
auto max_lines = 6u;
|
auto max_lines = 6u;
|
||||||
|
@ -99,7 +99,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
|
||||||
for (uint line in display_lines) {
|
for (uint line in display_lines) {
|
||||||
ioivec::stdout().write_str(#fmt("%s:%u ", fm.name,
|
ioivec::stdout().write_str(#fmt("%s:%u ", fm.name,
|
||||||
line + 1u));
|
line + 1u));
|
||||||
auto s = codemap::get_line(fm, line as int, file);
|
auto s = get_line(fm, line as int, file);
|
||||||
if (!str::ends_with(s, "\n")) {
|
if (!str::ends_with(s, "\n")) {
|
||||||
s += "\n";
|
s += "\n";
|
||||||
}
|
}
|
||||||
|
@ -119,6 +119,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
|
||||||
// If there's one line at fault we can easily point to the problem
|
// If there's one line at fault we can easily point to the problem
|
||||||
if (ivec::len(lines.lines) == 1u) {
|
if (ivec::len(lines.lines) == 1u) {
|
||||||
auto lo = codemap::lookup_pos(cm, option::get(sp).lo);
|
auto lo = codemap::lookup_pos(cm, option::get(sp).lo);
|
||||||
|
auto lo = lookup_pos(cm, option::get(sp).lo);
|
||||||
auto digits = 0u;
|
auto digits = 0u;
|
||||||
auto num = lines.lines.(0) / 10u;
|
auto num = lines.lines.(0) / 10u;
|
||||||
|
|
||||||
|
@ -131,7 +132,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
|
||||||
while (left > 0u) { str::push_char(s, ' '); left -= 1u; }
|
while (left > 0u) { str::push_char(s, ' '); left -= 1u; }
|
||||||
|
|
||||||
s += "^";
|
s += "^";
|
||||||
auto hi = codemap::lookup_pos(cm, option::get(sp).hi);
|
auto hi = lookup_pos(cm, option::get(sp).hi);
|
||||||
if (hi.col != lo.col) {
|
if (hi.col != lo.col) {
|
||||||
// the ^ already takes up one space
|
// the ^ already takes up one space
|
||||||
auto width = hi.col - lo.col - 1u;
|
auto width = hi.col - lo.col - 1u;
|
||||||
|
@ -170,13 +171,14 @@ fn span_to_lines(span sp, codemap::codemap cm) -> @file_lines {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_line(filemap fm, int line, &str file) -> str {
|
fn get_line(filemap fm, int line, &str file) -> str {
|
||||||
|
let uint begin = fm.lines.(line) - fm.lines.(0);
|
||||||
let uint end;
|
let uint end;
|
||||||
if ((line as uint) + 1u >= ivec::len(fm.lines)) {
|
if ((line as uint) + 1u >= ivec::len(fm.lines)) {
|
||||||
end = str::byte_len(file);
|
end = str::byte_len(file);
|
||||||
} else {
|
} else {
|
||||||
end = fm.lines.(line + 1);
|
end = fm.lines.(line + 1) - fm.lines.(0);
|
||||||
}
|
}
|
||||||
ret str::slice(file, fm.lines.(line), end);
|
ret str::slice(file, begin, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_filemap(codemap cm, str filename) -> filemap {
|
fn get_filemap(codemap cm, str filename) -> filemap {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue