Add terminal_width debugging flag
This commit is contained in:
parent
9980796d6d
commit
21f2e93345
@ -1292,6 +1292,8 @@ fn parse_symbol_mangling_version(
|
||||
"show macro backtraces even for non-local macros"),
|
||||
teach: bool = (false, parse_bool, [TRACKED],
|
||||
"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],
|
||||
"attempt to recover from parse errors (experimental)"),
|
||||
dep_tasks: bool = (false, parse_bool, [UNTRACKED],
|
||||
|
@ -1055,6 +1055,7 @@ fn default_emitter(
|
||||
Some(source_map.clone()),
|
||||
short,
|
||||
sopts.debugging_opts.teach,
|
||||
sopts.debugging_opts.terminal_width,
|
||||
),
|
||||
Some(dst) => EmitterWriter::new(
|
||||
dst,
|
||||
@ -1062,6 +1063,7 @@ fn default_emitter(
|
||||
short,
|
||||
false, // no teach messages 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))
|
||||
@ -1375,7 +1377,7 @@ pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
|
||||
let emitter: Box<dyn Emitter + sync::Send> = match output {
|
||||
config::ErrorOutputType::HumanReadable(kind) => {
|
||||
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 } =>
|
||||
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 {
|
||||
config::ErrorOutputType::HumanReadable(kind) => {
|
||||
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 } =>
|
||||
Box::new(JsonEmitter::basic(pretty, json_rendered)),
|
||||
|
@ -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
|
||||
eprintln!("");
|
||||
|
||||
let emitter =
|
||||
Box::new(errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
|
||||
None,
|
||||
false,
|
||||
false));
|
||||
let emitter = Box::new(errors::emitter::EmitterWriter::stderr(
|
||||
errors::ColorConfig::Auto,
|
||||
None,
|
||||
false,
|
||||
false,
|
||||
None,
|
||||
));
|
||||
let handler = errors::Handler::with_emitter(true, None, emitter);
|
||||
|
||||
// a .span_bug or .bug call has already printed what
|
||||
|
@ -51,9 +51,11 @@ pub fn new_emitter(
|
||||
dst: Box<dyn Write + Send>,
|
||||
source_map: Option<Lrc<SourceMapperDyn>>,
|
||||
teach: bool,
|
||||
terminal_width: Option<usize>,
|
||||
) -> EmitterWriter {
|
||||
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,
|
||||
teach: bool,
|
||||
ui_testing: bool,
|
||||
terminal_width: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -306,11 +309,13 @@ pub struct FileWithAnnotatedLines {
|
||||
}
|
||||
|
||||
impl EmitterWriter {
|
||||
pub fn stderr(color_config: ColorConfig,
|
||||
source_map: Option<Lrc<SourceMapperDyn>>,
|
||||
short_message: bool,
|
||||
teach: bool)
|
||||
-> EmitterWriter {
|
||||
pub fn stderr(
|
||||
color_config: ColorConfig,
|
||||
source_map: Option<Lrc<SourceMapperDyn>>,
|
||||
short_message: bool,
|
||||
teach: bool,
|
||||
terminal_width: Option<usize>,
|
||||
) -> EmitterWriter {
|
||||
let dst = Destination::from_stderr(color_config);
|
||||
EmitterWriter {
|
||||
dst,
|
||||
@ -318,6 +323,7 @@ pub fn stderr(color_config: ColorConfig,
|
||||
short_message,
|
||||
teach,
|
||||
ui_testing: false,
|
||||
terminal_width,
|
||||
}
|
||||
}
|
||||
|
||||
@ -327,6 +333,7 @@ pub fn new(
|
||||
short_message: bool,
|
||||
teach: bool,
|
||||
colored: bool,
|
||||
terminal_width: Option<usize>,
|
||||
) -> EmitterWriter {
|
||||
EmitterWriter {
|
||||
dst: Raw(dst, colored),
|
||||
@ -334,6 +341,7 @@ pub fn new(
|
||||
short_message,
|
||||
teach,
|
||||
ui_testing: false,
|
||||
terminal_width,
|
||||
}
|
||||
}
|
||||
|
||||
@ -1295,7 +1303,9 @@ fn emit_message_default(
|
||||
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
|
||||
} else {
|
||||
term_size::dimensions().map(|(w, _)| w - code_offset).unwrap_or(140)
|
||||
|
@ -383,7 +383,7 @@ pub fn with_tty_emitter_and_flags(color_config: ColorConfig,
|
||||
cm: Option<Lrc<SourceMapperDyn>>,
|
||||
flags: HandlerFlags)
|
||||
-> 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)
|
||||
}
|
||||
|
||||
|
@ -193,6 +193,7 @@ pub fn new_handler(error_format: ErrorOutputType,
|
||||
source_map.map(|cm| cm as _),
|
||||
short,
|
||||
sessopts.debugging_opts.teach,
|
||||
sessopts.debugging_opts.terminal_width,
|
||||
).ui_testing(ui_testing)
|
||||
)
|
||||
},
|
||||
|
@ -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
|
||||
// send all the errors that libsyntax emits directly into a `Sink` instead of stderr.
|
||||
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
|
||||
let handler = Handler::with_emitter(false, None, box emitter);
|
||||
let sess = ParseSess::with_span_handler(handler, cm);
|
||||
|
@ -219,7 +219,7 @@ fn flush(&mut self) -> io::Result<()> {
|
||||
}
|
||||
let buf = BufWriter::default();
|
||||
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);
|
||||
let output = Arc::try_unwrap(output.0).unwrap().into_inner().unwrap();
|
||||
let output = String::from_utf8(output).unwrap();
|
||||
|
@ -10,7 +10,14 @@
|
||||
use syntax_pos::{BytePos, Span};
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -144,11 +144,14 @@ fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &
|
||||
println!("text: {:?}", source_map.span_to_snippet(span));
|
||||
}
|
||||
|
||||
let emitter = EmitterWriter::new(Box::new(Shared { data: output.clone() }),
|
||||
Some(source_map.clone()),
|
||||
false,
|
||||
false,
|
||||
false);
|
||||
let emitter = EmitterWriter::new(
|
||||
Box::new(Shared { data: output.clone() }),
|
||||
Some(source_map.clone()),
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
None,
|
||||
);
|
||||
let handler = Handler::with_emitter(true, None, Box::new(emitter));
|
||||
handler.span_err(msp, "foo");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user