diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-04-17 10:31:30 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-17 10:31:30 +0200 |
| commit | c89bc54d4f0174bd7c86693dc3b0500d11d756d2 (patch) | |
| tree | 0130a011c0194dfbcd49b4078e6b6a7be1f138e7 /src/libsyntax | |
| parent | 258e3b3a75a0da006cd492307fc46ef605e774ad (diff) | |
| parent | 5c6a43a58bfb31bcabfd52e2c378cdaa48a68290 (diff) | |
| download | rust-c89bc54d4f0174bd7c86693dc3b0500d11d756d2.tar.gz rust-c89bc54d4f0174bd7c86693dc3b0500d11d756d2.zip | |
Rollup merge of #59128 - oli-obk:colorful_json, r=mark-i-m,eddyb
Emit ansi color codes in the `rendered` field of json diagnostics cc @ljedrz Implemented for https://github.com/rust-lang/rust/pull/56595#issuecomment-447645115 (x.py clippy)
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/json.rs | 31 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/test_snippet.rs | 1 |
3 files changed, 22 insertions, 11 deletions
diff --git a/src/libsyntax/json.rs b/src/libsyntax/json.rs index 838dfc62646..c19b408442a 100644 --- a/src/libsyntax/json.rs +++ b/src/libsyntax/json.rs @@ -14,7 +14,7 @@ use crate::source_map::{SourceMap, FilePathMapping}; use errors::registry::Registry; use errors::{DiagnosticBuilder, SubDiagnostic, CodeSuggestion, SourceMapper}; use errors::{DiagnosticId, Applicability}; -use errors::emitter::{Emitter, EmitterWriter}; +use errors::emitter::{Emitter, HumanReadableErrorType}; use syntax_pos::{MacroBacktrace, Span, SpanLabel, MultiSpan}; use rustc_data_structures::sync::{self, Lrc}; @@ -30,37 +30,46 @@ pub struct JsonEmitter { sm: Lrc<dyn SourceMapper + sync::Send + sync::Sync>, pretty: bool, ui_testing: bool, + json_rendered: HumanReadableErrorType, } impl JsonEmitter { - pub fn stderr(registry: Option<Registry>, - source_map: Lrc<SourceMap>, - pretty: bool) -> JsonEmitter { + pub fn stderr( + registry: Option<Registry>, + source_map: Lrc<SourceMap>, + pretty: bool, + json_rendered: HumanReadableErrorType, + ) -> JsonEmitter { JsonEmitter { dst: Box::new(io::stderr()), registry, sm: source_map, pretty, ui_testing: false, + json_rendered, } } - pub fn basic(pretty: bool) -> JsonEmitter { + pub fn basic(pretty: bool, json_rendered: HumanReadableErrorType) -> JsonEmitter { let file_path_mapping = FilePathMapping::empty(); JsonEmitter::stderr(None, Lrc::new(SourceMap::new(file_path_mapping)), - pretty) + pretty, json_rendered) } - pub fn new(dst: Box<dyn Write + Send>, - registry: Option<Registry>, - source_map: Lrc<SourceMap>, - pretty: bool) -> JsonEmitter { + pub fn new( + dst: Box<dyn Write + Send>, + registry: Option<Registry>, + source_map: Lrc<SourceMap>, + pretty: bool, + json_rendered: HumanReadableErrorType, + ) -> JsonEmitter { JsonEmitter { dst, registry, sm: source_map, pretty, ui_testing: false, + json_rendered, } } @@ -190,7 +199,7 @@ impl Diagnostic { } let buf = BufWriter::default(); let output = buf.clone(); - EmitterWriter::new(Box::new(buf), Some(je.sm.clone()), false, false) + je.json_rendered.new_emitter(Box::new(buf), Some(je.sm.clone()), false) .ui_testing(je.ui_testing).emit(db); let output = Arc::try_unwrap(output.0).unwrap().into_inner().unwrap(); let output = String::from_utf8(output).unwrap(); diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 5557e281a66..3b980fafc2f 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -1920,6 +1920,7 @@ mod tests { let emitter = errors::emitter::EmitterWriter::new(Box::new(io::sink()), Some(sm.clone()), false, + false, false); ParseSess { span_diagnostic: errors::Handler::with_emitter(true, None, Box::new(emitter)), diff --git a/src/libsyntax/test_snippet.rs b/src/libsyntax/test_snippet.rs index 86910ffd894..cba429068fd 100644 --- a/src/libsyntax/test_snippet.rs +++ b/src/libsyntax/test_snippet.rs @@ -57,6 +57,7 @@ fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: & let emitter = EmitterWriter::new(Box::new(Shared { data: output.clone() }), Some(source_map.clone()), false, + false, false); let handler = Handler::with_emitter(true, None, Box::new(emitter)); handler.span_err(msp, "foo"); |
