1
Fork 0

Add terminal_width debugging flag

This commit is contained in:
Esteban Küber 2019-08-14 17:57:28 -07:00
parent 9980796d6d
commit 21f2e93345
10 changed files with 50 additions and 23 deletions

View file

@ -1292,6 +1292,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"show macro backtraces even for non-local macros"), "show macro backtraces even for non-local macros"),
teach: bool = (false, parse_bool, [TRACKED], teach: bool = (false, parse_bool, [TRACKED],
"show extended diagnostic help"), "show extended diagnostic help"),
terminal_width: Option<usize> = (None, parse_opt_uint, [UNTRACKED],
"set the current terminal width"),
continue_parse_after_error: bool = (false, parse_bool, [TRACKED], continue_parse_after_error: bool = (false, parse_bool, [TRACKED],
"attempt to recover from parse errors (experimental)"), "attempt to recover from parse errors (experimental)"),
dep_tasks: bool = (false, parse_bool, [UNTRACKED], dep_tasks: bool = (false, parse_bool, [UNTRACKED],

View file

@ -1055,6 +1055,7 @@ fn default_emitter(
Some(source_map.clone()), Some(source_map.clone()),
short, short,
sopts.debugging_opts.teach, sopts.debugging_opts.teach,
sopts.debugging_opts.terminal_width,
), ),
Some(dst) => EmitterWriter::new( Some(dst) => EmitterWriter::new(
dst, dst,
@ -1062,6 +1063,7 @@ fn default_emitter(
short, short,
false, // no teach messages when writing to a buffer false, // no teach messages when writing to a buffer
false, // no colors when writing to a buffer false, // no colors when writing to a buffer
None, // no terminal width
), ),
}; };
Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing)) Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing))
@ -1375,7 +1377,7 @@ pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
let emitter: Box<dyn Emitter + sync::Send> = match output { let emitter: Box<dyn Emitter + sync::Send> = match output {
config::ErrorOutputType::HumanReadable(kind) => { config::ErrorOutputType::HumanReadable(kind) => {
let (short, color_config) = kind.unzip(); let (short, color_config) = kind.unzip();
Box::new(EmitterWriter::stderr(color_config, None, short, false)) Box::new(EmitterWriter::stderr(color_config, None, short, false, None))
} }
config::ErrorOutputType::Json { pretty, json_rendered } => config::ErrorOutputType::Json { pretty, json_rendered } =>
Box::new(JsonEmitter::basic(pretty, json_rendered)), Box::new(JsonEmitter::basic(pretty, json_rendered)),
@ -1389,7 +1391,7 @@ pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
let emitter: Box<dyn Emitter + sync::Send> = match output { let emitter: Box<dyn Emitter + sync::Send> = match output {
config::ErrorOutputType::HumanReadable(kind) => { config::ErrorOutputType::HumanReadable(kind) => {
let (short, color_config) = kind.unzip(); let (short, color_config) = kind.unzip();
Box::new(EmitterWriter::stderr(color_config, None, short, false)) Box::new(EmitterWriter::stderr(color_config, None, short, false, None))
} }
config::ErrorOutputType::Json { pretty, json_rendered } => config::ErrorOutputType::Json { pretty, json_rendered } =>
Box::new(JsonEmitter::basic(pretty, json_rendered)), Box::new(JsonEmitter::basic(pretty, json_rendered)),

View file

@ -1135,11 +1135,13 @@ pub fn report_ices_to_stderr_if_any<F: FnOnce() -> R, R>(f: F) -> Result<R, Erro
// Thread panicked without emitting a fatal diagnostic // Thread panicked without emitting a fatal diagnostic
eprintln!(""); eprintln!("");
let emitter = let emitter = Box::new(errors::emitter::EmitterWriter::stderr(
Box::new(errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto, errors::ColorConfig::Auto,
None, None,
false, false,
false)); false,
None,
));
let handler = errors::Handler::with_emitter(true, None, emitter); let handler = errors::Handler::with_emitter(true, None, emitter);
// a .span_bug or .bug call has already printed what // a .span_bug or .bug call has already printed what

View file

@ -51,9 +51,11 @@ impl HumanReadableErrorType {
dst: Box<dyn Write + Send>, dst: Box<dyn Write + Send>,
source_map: Option<Lrc<SourceMapperDyn>>, source_map: Option<Lrc<SourceMapperDyn>>,
teach: bool, teach: bool,
terminal_width: Option<usize>,
) -> EmitterWriter { ) -> EmitterWriter {
let (short, color_config) = self.unzip(); let (short, color_config) = self.unzip();
EmitterWriter::new(dst, source_map, short, teach, color_config.suggests_using_colors()) let color = color_config.suggests_using_colors();
EmitterWriter::new(dst, source_map, short, teach, color, terminal_width)
} }
} }
@ -296,6 +298,7 @@ pub struct EmitterWriter {
short_message: bool, short_message: bool,
teach: bool, teach: bool,
ui_testing: bool, ui_testing: bool,
terminal_width: Option<usize>,
} }
#[derive(Debug)] #[derive(Debug)]
@ -306,11 +309,13 @@ pub struct FileWithAnnotatedLines {
} }
impl EmitterWriter { impl EmitterWriter {
pub fn stderr(color_config: ColorConfig, pub fn stderr(
source_map: Option<Lrc<SourceMapperDyn>>, color_config: ColorConfig,
short_message: bool, source_map: Option<Lrc<SourceMapperDyn>>,
teach: bool) short_message: bool,
-> EmitterWriter { teach: bool,
terminal_width: Option<usize>,
) -> EmitterWriter {
let dst = Destination::from_stderr(color_config); let dst = Destination::from_stderr(color_config);
EmitterWriter { EmitterWriter {
dst, dst,
@ -318,6 +323,7 @@ impl EmitterWriter {
short_message, short_message,
teach, teach,
ui_testing: false, ui_testing: false,
terminal_width,
} }
} }
@ -327,6 +333,7 @@ impl EmitterWriter {
short_message: bool, short_message: bool,
teach: bool, teach: bool,
colored: bool, colored: bool,
terminal_width: Option<usize>,
) -> EmitterWriter { ) -> EmitterWriter {
EmitterWriter { EmitterWriter {
dst: Raw(dst, colored), dst: Raw(dst, colored),
@ -334,6 +341,7 @@ impl EmitterWriter {
short_message, short_message,
teach, teach,
ui_testing: false, ui_testing: false,
terminal_width,
} }
} }
@ -1295,7 +1303,9 @@ impl EmitterWriter {
width_offset + annotated_file.multiline_depth + 1 width_offset + annotated_file.multiline_depth + 1
}; };
let column_width = if self.ui_testing { let column_width = if let Some(width) = self.terminal_width {
width
} else if self.ui_testing {
140 140
} else { } else {
term_size::dimensions().map(|(w, _)| w - code_offset).unwrap_or(140) term_size::dimensions().map(|(w, _)| w - code_offset).unwrap_or(140)

View file

@ -383,7 +383,7 @@ impl Handler {
cm: Option<Lrc<SourceMapperDyn>>, cm: Option<Lrc<SourceMapperDyn>>,
flags: HandlerFlags) flags: HandlerFlags)
-> Handler { -> Handler {
let emitter = Box::new(EmitterWriter::stderr(color_config, cm, false, false)); let emitter = Box::new(EmitterWriter::stderr(color_config, cm, false, false, None));
Handler::with_emitter_and_flags(emitter, flags) Handler::with_emitter_and_flags(emitter, flags)
} }

View file

@ -193,6 +193,7 @@ pub fn new_handler(error_format: ErrorOutputType,
source_map.map(|cm| cm as _), source_map.map(|cm| cm as _),
short, short,
sessopts.debugging_opts.teach, sessopts.debugging_opts.teach,
sessopts.debugging_opts.terminal_width,
).ui_testing(ui_testing) ).ui_testing(ui_testing)
) )
}, },

View file

@ -427,7 +427,7 @@ pub fn make_test(s: &str,
// Any errors in parsing should also appear when the doctest is compiled for real, so just // Any errors in parsing should also appear when the doctest is compiled for real, so just
// send all the errors that libsyntax emits directly into a `Sink` instead of stderr. // send all the errors that libsyntax emits directly into a `Sink` instead of stderr.
let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let cm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let emitter = EmitterWriter::new(box io::sink(), None, false, false, false); let emitter = EmitterWriter::new(box io::sink(), None, false, false, false, None);
// FIXME(misdreavus): pass `-Z treat-err-as-bug` to the doctest parser // FIXME(misdreavus): pass `-Z treat-err-as-bug` to the doctest parser
let handler = Handler::with_emitter(false, None, box emitter); let handler = Handler::with_emitter(false, None, box emitter);
let sess = ParseSess::with_span_handler(handler, cm); let sess = ParseSess::with_span_handler(handler, cm);

View file

@ -219,7 +219,7 @@ impl Diagnostic {
} }
let buf = BufWriter::default(); let buf = BufWriter::default();
let output = buf.clone(); let output = buf.clone();
je.json_rendered.new_emitter(Box::new(buf), Some(je.sm.clone()), false) je.json_rendered.new_emitter(Box::new(buf), Some(je.sm.clone()), false, None)
.ui_testing(je.ui_testing).emit_diagnostic(db); .ui_testing(je.ui_testing).emit_diagnostic(db);
let output = Arc::try_unwrap(output.0).unwrap().into_inner().unwrap(); let output = Arc::try_unwrap(output.0).unwrap().into_inner().unwrap();
let output = String::from_utf8(output).unwrap(); let output = String::from_utf8(output).unwrap();

View file

@ -10,7 +10,14 @@ use errors::{Handler, emitter::EmitterWriter};
use syntax_pos::{BytePos, Span}; use syntax_pos::{BytePos, Span};
fn mk_sess(sm: Lrc<SourceMap>) -> ParseSess { fn mk_sess(sm: Lrc<SourceMap>) -> ParseSess {
let emitter = EmitterWriter::new(Box::new(io::sink()), Some(sm.clone()), false, false, false); let emitter = errors::emitter::EmitterWriter::new(
Box::new(io::sink()),
Some(sm.clone()),
false,
false,
false,
None,
);
ParseSess::with_span_handler(Handler::with_emitter(true, None, Box::new(emitter)), sm) ParseSess::with_span_handler(Handler::with_emitter(true, None, Box::new(emitter)), sm)
} }

View file

@ -144,11 +144,14 @@ fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &
println!("text: {:?}", source_map.span_to_snippet(span)); println!("text: {:?}", source_map.span_to_snippet(span));
} }
let emitter = EmitterWriter::new(Box::new(Shared { data: output.clone() }), let emitter = EmitterWriter::new(
Some(source_map.clone()), Box::new(Shared { data: output.clone() }),
false, Some(source_map.clone()),
false, false,
false); false,
false,
None,
);
let handler = Handler::with_emitter(true, None, Box::new(emitter)); let handler = Handler::with_emitter(true, None, Box::new(emitter));
handler.span_err(msp, "foo"); handler.span_err(msp, "foo");