diff options
| author | bors <bors@rust-lang.org> | 2016-03-24 09:25:02 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-03-24 09:25:02 -0700 |
| commit | dcfb8d72e99425686376298fd793715f35b5d512 (patch) | |
| tree | a202c287d30ee142f1931f5dd02bee256324d7e7 /src/libsyntax/errors | |
| parent | dc1f6831eb0d0e5cca16395f14b7406ff85c4c3d (diff) | |
| parent | b2dfb7c0a267d6f2adb9cbde1e157fc136fcaaab (diff) | |
| download | rust-dcfb8d72e99425686376298fd793715f35b5d512.tar.gz rust-dcfb8d72e99425686376298fd793715f35b5d512.zip | |
Auto merge of #32465 - steveklabnik:rollup, r=steveklabnik
Rollup of 6 pull requests - Successful merges: #32276, #32416, #32452, #32459, #32462, #32464 - Failed merges:
Diffstat (limited to 'src/libsyntax/errors')
| -rw-r--r-- | src/libsyntax/errors/json.rs | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/libsyntax/errors/json.rs b/src/libsyntax/errors/json.rs index 5bb5f4757e0..212a54447a8 100644 --- a/src/libsyntax/errors/json.rs +++ b/src/libsyntax/errors/json.rs @@ -20,7 +20,7 @@ // FIXME spec the JSON output properly. -use codemap::{MultiSpan, CodeMap}; +use codemap::{Span, MultiSpan, CodeMap}; use diagnostics::registry::Registry; use errors::{Level, DiagnosticBuilder, SubDiagnostic, RenderSpan, CodeSuggestion}; use errors::emitter::Emitter; @@ -99,6 +99,16 @@ struct DiagnosticSpan { /// 1-based, character offset. column_start: usize, column_end: usize, + /// Source text from the start of line_start to the end of line_end. + text: Vec<DiagnosticSpanLine>, +} + +#[derive(RustcEncodable)] +struct DiagnosticSpanLine { + text: String, + /// 1-based, character offset in self.text. + highlight_start: usize, + highlight_end: usize, } #[derive(RustcEncodable)] @@ -180,6 +190,7 @@ impl DiagnosticSpan { line_end: end.line, column_start: start.col.0 + 1, column_end: end.col.0 + 1, + text: DiagnosticSpanLine::from_span(span, je), } }).collect() } @@ -202,6 +213,7 @@ impl DiagnosticSpan { line_end: end.line, column_start: 0, column_end: end.col.0 + 1, + text: DiagnosticSpanLine::from_span(span, je), } }).collect() } @@ -217,6 +229,7 @@ impl DiagnosticSpan { line_end: end.line, column_start: 0, column_end: 0, + text: DiagnosticSpanLine::from_span(span, je), } }).collect() } @@ -224,6 +237,31 @@ impl DiagnosticSpan { } } +impl DiagnosticSpanLine { + fn from_span(span: &Span, je: &JsonEmitter) -> Vec<DiagnosticSpanLine> { + let lines = match je.cm.span_to_lines(*span) { + Ok(lines) => lines, + Err(_) => { + debug!("unprintable span"); + return Vec::new(); + } + }; + + let mut result = Vec::new(); + let fm = &*lines.file; + + for line in &lines.lines { + result.push(DiagnosticSpanLine { + text: fm.get_line(line.line_index).unwrap().to_owned(), + highlight_start: line.start_col.0 + 1, + highlight_end: line.end_col.0 + 1, + }); + } + + result + } +} + impl DiagnosticCode { fn map_opt_string(s: Option<String>, je: &JsonEmitter) -> Option<DiagnosticCode> { s.map(|s| { |
