use proc_macro2::TokenStream;
use quote::quote;
use std::{
- collections::HashMap,
+ collections::{HashMap, HashSet},
fs::File,
io::Read,
path::{Path, PathBuf},
let ident_span = res.ident.span().unwrap();
let path_span = res.resource.span().unwrap();
+ // Set of Fluent attribute names already output, to avoid duplicate type errors - any given
+ // constant created for a given attribute is the same.
+ let mut previous_attrs = HashSet::new();
+
let relative_ftl_path = res.resource.value();
let absolute_ftl_path =
invocation_relative_path_to_absolute(ident_span, &relative_ftl_path);
});
for Attribute { id: Identifier { name: attr_name }, .. } in attributes {
- let attr_snake_name = attr_name.replace("-", "_");
- let snake_name = Ident::new(&format!("{snake_name}_{attr_snake_name}"), span);
+ let snake_name = Ident::new(&attr_name.replace("-", "_"), span);
+ if !previous_attrs.insert(snake_name.clone()) {
+ continue;
+ }
+
constants.extend(quote! {
- pub const #snake_name: crate::DiagnosticMessage =
- crate::DiagnosticMessage::FluentIdentifier(
- std::borrow::Cow::Borrowed(#name),
- Some(std::borrow::Cow::Borrowed(#attr_name))
+ pub const #snake_name: crate::SubdiagnosticMessage =
+ crate::SubdiagnosticMessage::FluentAttr(
+ std::borrow::Cow::Borrowed(#attr_name)
);
});
}
];
#generated
+
+ pub mod _subdiag {
+ pub const note: crate::SubdiagnosticMessage =
+ crate::SubdiagnosticMessage::FluentAttr(std::borrow::Cow::Borrowed("note"));
+ pub const help: crate::SubdiagnosticMessage =
+ crate::SubdiagnosticMessage::FluentAttr(std::borrow::Cow::Borrowed("help"));
+ pub const label: crate::SubdiagnosticMessage =
+ crate::SubdiagnosticMessage::FluentAttr(std::borrow::Cow::Borrowed("label"));
+ pub const suggestion: crate::SubdiagnosticMessage =
+ crate::SubdiagnosticMessage::FluentAttr(std::borrow::Cow::Borrowed("suggestion"));
+ }
}
}
.into()