session: opt for enabling directionality markers
Add an option for enabling and disabling Fluent's directionality isolation markers in output. Disabled by default as these can render in some terminals and applications. Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
e27389b068
commit
3c2f864ffb
13 changed files with 27 additions and 18 deletions
|
@ -1173,7 +1173,7 @@ static DEFAULT_HOOK: SyncLazy<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send +
|
|||
/// hook.
|
||||
pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
|
||||
let fallback_bundle =
|
||||
rustc_errors::fallback_fluent_bundle().expect("failed to load fallback fluent bundle");
|
||||
rustc_errors::fallback_fluent_bundle(false).expect("failed to load fallback fluent bundle");
|
||||
let emitter = Box::new(rustc_errors::emitter::EmitterWriter::stderr(
|
||||
rustc_errors::ColorConfig::Auto,
|
||||
None,
|
||||
|
|
|
@ -101,6 +101,7 @@ pub fn fluent_bundle(
|
|||
sysroot: &Path,
|
||||
requested_locale: Option<LanguageIdentifier>,
|
||||
additional_ftl_path: Option<&Path>,
|
||||
with_directionality_markers: bool,
|
||||
) -> Result<Option<Lrc<FluentBundle>>, TranslationBundleError> {
|
||||
if requested_locale.is_none() && additional_ftl_path.is_none() {
|
||||
return Ok(None);
|
||||
|
@ -120,7 +121,7 @@ pub fn fluent_bundle(
|
|||
// vice-versa). These are disabled because they are sometimes visible in the error output, but
|
||||
// may be worth investigating in future (for example: if type names are left-to-right and the
|
||||
// surrounding diagnostic messages are right-to-left, then these might be helpful).
|
||||
bundle.set_use_isolating(false);
|
||||
bundle.set_use_isolating(with_directionality_markers);
|
||||
|
||||
// If the user requests the default locale then don't try to load anything.
|
||||
if !requested_fallback_locale && let Some(requested_locale) = requested_locale {
|
||||
|
@ -169,13 +170,15 @@ pub fn fluent_bundle(
|
|||
|
||||
/// Return the default `FluentBundle` with standard "en-US" diagnostic messages.
|
||||
#[instrument(level = "trace")]
|
||||
pub fn fallback_fluent_bundle() -> Result<Lrc<FluentBundle>, TranslationBundleError> {
|
||||
pub fn fallback_fluent_bundle(
|
||||
with_directionality_markers: bool,
|
||||
) -> Result<Lrc<FluentBundle>, TranslationBundleError> {
|
||||
let fallback_resource = FluentResource::try_new(FALLBACK_FLUENT_RESOURCE.to_string())
|
||||
.map_err(TranslationBundleError::from)?;
|
||||
trace!(?fallback_resource);
|
||||
let mut fallback_bundle = FluentBundle::new(vec![langid!("en-US")]);
|
||||
// See comment in `fluent_bundle`.
|
||||
fallback_bundle.set_use_isolating(false);
|
||||
fallback_bundle.set_use_isolating(with_directionality_markers);
|
||||
fallback_bundle.add_resource(fallback_resource).map_err(TranslationBundleError::from)?;
|
||||
let fallback_bundle = Lrc::new(fallback_bundle);
|
||||
Ok(fallback_bundle)
|
||||
|
|
|
@ -40,7 +40,7 @@ fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) {
|
|||
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
|
||||
sm.new_source_file(Path::new("test.rs").to_owned().into(), code.to_owned());
|
||||
let fallback_bundle =
|
||||
crate::fallback_fluent_bundle().expect("failed to load fallback fluent bundle");
|
||||
crate::fallback_fluent_bundle(false).expect("failed to load fallback fluent bundle");
|
||||
|
||||
let output = Arc::new(Mutex::new(Vec::new()));
|
||||
let je = JsonEmitter::new(
|
||||
|
|
|
@ -127,8 +127,8 @@ fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &
|
|||
create_default_session_if_not_set_then(|_| {
|
||||
let output = Arc::new(Mutex::new(Vec::new()));
|
||||
|
||||
let fallback_bundle =
|
||||
rustc_errors::fallback_fluent_bundle().expect("failed to load fallback fluent bundle");
|
||||
let fallback_bundle = rustc_errors::fallback_fluent_bundle(false)
|
||||
.expect("failed to load fallback fluent bundle");
|
||||
let source_map = Lrc::new(SourceMap::new(FilePathMapping::empty()));
|
||||
source_map.new_source_file(Path::new("test.rs").to_owned().into(), file_text.to_owned());
|
||||
|
||||
|
|
|
@ -1482,6 +1482,8 @@ options! {
|
|||
"language identifier for diagnostic output"),
|
||||
translate_additional_ftl: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
|
||||
"additional fluent translation to preferentially use (for testing translation)"),
|
||||
translate_directionality_markers: bool = (false, parse_bool, [TRACKED],
|
||||
"emit directionality isolation markers in translated diagnostics"),
|
||||
tune_cpu: Option<String> = (None, parse_opt_string, [TRACKED],
|
||||
"select processor to schedule for (`rustc --print target-cpus` for details)"),
|
||||
thinlto: Option<bool> = (None, parse_opt_bool, [TRACKED],
|
||||
|
|
|
@ -175,7 +175,7 @@ impl ParseSess {
|
|||
/// Used for testing.
|
||||
pub fn new(file_path_mapping: FilePathMapping) -> Self {
|
||||
let fallback_bundle =
|
||||
fallback_fluent_bundle().expect("failed to load fallback fluent bundle");
|
||||
fallback_fluent_bundle(false).expect("failed to load fallback fluent bundle");
|
||||
let sm = Lrc::new(SourceMap::new(file_path_mapping));
|
||||
let handler = Handler::with_tty_emitter(
|
||||
ColorConfig::Auto,
|
||||
|
@ -214,7 +214,7 @@ impl ParseSess {
|
|||
|
||||
pub fn with_silent_emitter(fatal_note: Option<String>) -> Self {
|
||||
let fallback_bundle =
|
||||
fallback_fluent_bundle().expect("failed to load fallback fluent bundle");
|
||||
fallback_fluent_bundle(false).expect("failed to load fallback fluent bundle");
|
||||
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
|
||||
let fatal_handler =
|
||||
Handler::with_tty_emitter(ColorConfig::Auto, false, None, None, None, fallback_bundle);
|
||||
|
|
|
@ -1218,9 +1218,12 @@ pub fn build_session(
|
|||
&sysroot,
|
||||
sopts.debugging_opts.translate_lang.clone(),
|
||||
sopts.debugging_opts.translate_additional_ftl.as_deref(),
|
||||
sopts.debugging_opts.translate_directionality_markers,
|
||||
)
|
||||
.expect("failed to load fluent bundle");
|
||||
let fallback_bundle = fallback_fluent_bundle().expect("failed to load fallback fluent bundle");
|
||||
let fallback_bundle =
|
||||
fallback_fluent_bundle(sopts.debugging_opts.translate_directionality_markers)
|
||||
.expect("failed to load fallback fluent bundle");
|
||||
let emitter =
|
||||
default_emitter(&sopts, registry, source_map.clone(), bundle, fallback_bundle, write_dest);
|
||||
|
||||
|
@ -1455,7 +1458,8 @@ pub enum IncrCompSession {
|
|||
}
|
||||
|
||||
fn early_error_handler(output: config::ErrorOutputType) -> rustc_errors::Handler {
|
||||
let fallback_bundle = fallback_fluent_bundle().expect("failed to load fallback fluent bundle");
|
||||
let fallback_bundle =
|
||||
fallback_fluent_bundle(false).expect("failed to load fallback fluent bundle");
|
||||
let emitter: Box<dyn Emitter + sync::Send> = match output {
|
||||
config::ErrorOutputType::HumanReadable(kind) => {
|
||||
let (short, color_config) = kind.unzip();
|
||||
|
|
|
@ -144,7 +144,7 @@ crate fn new_handler(
|
|||
debugging_opts: &DebuggingOptions,
|
||||
) -> rustc_errors::Handler {
|
||||
let fallback_bundle =
|
||||
rustc_errors::fallback_fluent_bundle().expect("failed to load fallback fluent bundle");
|
||||
rustc_errors::fallback_fluent_bundle(false).expect("failed to load fallback fluent bundle");
|
||||
let emitter: Box<dyn Emitter + sync::Send> = match error_format {
|
||||
ErrorOutputType::HumanReadable(kind) => {
|
||||
let (short, color_config) = kind.unzip();
|
||||
|
|
|
@ -537,7 +537,7 @@ crate fn make_test(
|
|||
// Any errors in parsing should also appear when the doctest is compiled for real, so just
|
||||
// send all the errors that librustc_ast emits directly into a `Sink` instead of stderr.
|
||||
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
|
||||
let fallback_bundle = rustc_errors::fallback_fluent_bundle()
|
||||
let fallback_bundle = rustc_errors::fallback_fluent_bundle(false)
|
||||
.expect("failed to load fallback fluent bundle");
|
||||
supports_color = EmitterWriter::stderr(
|
||||
ColorConfig::Auto,
|
||||
|
|
|
@ -32,8 +32,8 @@ struct SyntaxChecker<'a, 'tcx> {
|
|||
impl<'a, 'tcx> SyntaxChecker<'a, 'tcx> {
|
||||
fn check_rust_syntax(&self, item: &clean::Item, dox: &str, code_block: RustCodeBlock) {
|
||||
let buffer = Lrc::new(Lock::new(Buffer::default()));
|
||||
let fallback_bundle =
|
||||
rustc_errors::fallback_fluent_bundle().expect("failed to load fallback fluent bundle");
|
||||
let fallback_bundle = rustc_errors::fallback_fluent_bundle(false)
|
||||
.expect("failed to load fallback fluent bundle");
|
||||
let emitter = BufferEmitter { buffer: Lrc::clone(&buffer), fallback_bundle };
|
||||
|
||||
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
|
||||
|
|
|
@ -621,7 +621,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) {
|
|||
let filename = FileName::anon_source_code(&code);
|
||||
|
||||
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
|
||||
let fallback_bundle = rustc_errors::fallback_fluent_bundle()
|
||||
let fallback_bundle = rustc_errors::fallback_fluent_bundle(false)
|
||||
.expect("failed to load fallback fluent bundle");
|
||||
let emitter = EmitterWriter::new(
|
||||
Box::new(io::sink()),
|
||||
|
|
|
@ -165,7 +165,7 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
|
|||
// Separate the output with an empty line
|
||||
eprintln!();
|
||||
|
||||
let fallback_bundle = rustc_errors::fallback_fluent_bundle()
|
||||
let fallback_bundle = rustc_errors::fallback_fluent_bundle(false)
|
||||
.expect("failed to load fallback fluent bundle");
|
||||
let emitter = Box::new(rustc_errors::emitter::EmitterWriter::stderr(
|
||||
rustc_errors::ColorConfig::Auto,
|
||||
|
|
|
@ -114,7 +114,7 @@ fn default_handler(
|
|||
let emitter = if hide_parse_errors {
|
||||
silent_emitter()
|
||||
} else {
|
||||
let fallback_bundle = rustc_errors::fallback_fluent_bundle()
|
||||
let fallback_bundle = rustc_errors::fallback_fluent_bundle(false)
|
||||
.expect("failed to load fallback fluent bundle");
|
||||
Box::new(EmitterWriter::stderr(
|
||||
color_cfg,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue