Skip to content

Re-enable corrected error line printing and highlighting #681

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
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/comp/syntax/codemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
alt (sp) {
case (some(?ssp)) {
ss = span_to_str(ssp, cm);

// FIXME: we're not able to look up lines read from .rc files yet.
// maybe_lines = some(span_to_lines(ssp, cm));

maybe_lines = some(span_to_lines(ssp, cm));
}
case (none) { }
}
Expand All @@ -85,7 +82,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
// get access to the necessary lines.
auto rdr = io::file_reader(lines.name);
auto file = str::unsafe_from_bytes(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
auto max_lines = 6u;
Expand All @@ -98,7 +95,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
// Print the offending lines
for (uint line in display_lines) {
io::stdout().write_str(#fmt("%s:%u ", fm.name, 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")) {
s += "\n";
}
Expand All @@ -116,7 +113,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 (vec::len(lines.lines) == 1u) {
auto lo = codemap::lookup_pos(cm, option::get(sp).lo);
auto lo = lookup_pos(cm, option::get(sp).lo);
auto digits = 0u;
auto num = lines.lines.(0) / 10u;

Expand All @@ -129,7 +126,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
while (left > 0u) { str::push_char(s, ' '); left -= 1u; }

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) {
// the ^ already takes up one space
auto width = hi.col - lo.col - 1u;
Expand Down Expand Up @@ -168,13 +165,14 @@ fn span_to_lines(span sp, codemap::codemap cm) -> @file_lines {
}

fn get_line(filemap fm, int line, &str file) -> str {
let uint begin = fm.lines.(line) - fm.start_pos;
let uint end;
if ((line as uint) + 1u >= vec::len(fm.lines)) {
end = str::byte_len(file);
} else {
end = fm.lines.(line + 1);
end = fm.lines.(line + 1) - fm.start_pos;
}
ret str::slice(file, fm.lines.(line), end);
ret str::slice(file, begin, end);
}

fn get_filemap(codemap cm, str filename) -> filemap {
Expand Down