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)
This commit is contained in:
commit
c89bc54d4f
13 changed files with 287 additions and 230 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue