Remove DiagMessage::FluentIdentifier
This commit is contained in:
parent
13c38730d9
commit
ea8733133c
2 changed files with 8 additions and 105 deletions
|
|
@ -230,9 +230,6 @@ pub fn fallback_fluent_bundle(
|
|||
})))
|
||||
}
|
||||
|
||||
/// Identifier for the Fluent message/attribute corresponding to a diagnostic message.
|
||||
type FluentId = Cow<'static, str>;
|
||||
|
||||
/// Abstraction over a message in a subdiagnostic (i.e. label, note, help, etc) to support both
|
||||
/// translatable and non-translatable diagnostic messages.
|
||||
///
|
||||
|
|
@ -244,18 +241,9 @@ type FluentId = Cow<'static, str>;
|
|||
pub enum SubdiagMessage {
|
||||
/// Non-translatable diagnostic message.
|
||||
Str(Cow<'static, str>),
|
||||
/// Identifier of a Fluent message. Instances of this variant are generated by the
|
||||
/// `Subdiagnostic` derive.
|
||||
FluentIdentifier(FluentId),
|
||||
/// An inline Fluent message. Instances of this variant are generated by the
|
||||
/// `Subdiagnostic` derive.
|
||||
Inline(Cow<'static, str>),
|
||||
/// Attribute of a Fluent message. Needs to be combined with a Fluent identifier to produce an
|
||||
/// actual translated message. Instances of this variant are generated by the `fluent_messages`
|
||||
/// macro.
|
||||
///
|
||||
/// <https://projectfluent.org/fluent/guide/attributes.html>
|
||||
FluentAttr(FluentId),
|
||||
}
|
||||
|
||||
impl From<String> for SubdiagMessage {
|
||||
|
|
@ -288,12 +276,6 @@ pub enum DiagMessage {
|
|||
/// are translated when they are added to the parent diagnostic. This is one of the ways
|
||||
/// this variant of `DiagMessage` is produced.
|
||||
Str(Cow<'static, str>),
|
||||
/// Identifier for a Fluent message (with optional attribute) corresponding to the diagnostic
|
||||
/// message. Yet to be translated.
|
||||
///
|
||||
/// <https://projectfluent.org/fluent/guide/hello.html>
|
||||
/// <https://projectfluent.org/fluent/guide/attributes.html>
|
||||
FluentIdentifier(FluentId, Option<FluentId>),
|
||||
/// An inline Fluent message, containing the to be translated diagnostic message.
|
||||
Inline(Cow<'static, str>),
|
||||
}
|
||||
|
|
@ -305,27 +287,16 @@ impl DiagMessage {
|
|||
/// - If the `SubdiagMessage` is non-translatable then return the message as a `DiagMessage`.
|
||||
/// - If `self` is non-translatable then return `self`'s message.
|
||||
pub fn with_subdiagnostic_message(&self, sub: SubdiagMessage) -> Self {
|
||||
let attr = match sub {
|
||||
SubdiagMessage::Str(s) => return DiagMessage::Str(s),
|
||||
SubdiagMessage::FluentIdentifier(id) => {
|
||||
return DiagMessage::FluentIdentifier(id, None);
|
||||
}
|
||||
SubdiagMessage::Inline(s) => return DiagMessage::Inline(s),
|
||||
SubdiagMessage::FluentAttr(attr) => attr,
|
||||
};
|
||||
|
||||
match self {
|
||||
DiagMessage::FluentIdentifier(id, _) => {
|
||||
DiagMessage::FluentIdentifier(id.clone(), Some(attr))
|
||||
}
|
||||
_ => panic!("Tried to add a subdiagnostic to a message without a fluent identifier"),
|
||||
match sub {
|
||||
SubdiagMessage::Str(s) => DiagMessage::Str(s),
|
||||
SubdiagMessage::Inline(s) => DiagMessage::Inline(s),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_str(&self) -> Option<&str> {
|
||||
match self {
|
||||
DiagMessage::Str(s) => Some(s),
|
||||
DiagMessage::FluentIdentifier(_, _) | DiagMessage::Inline(_) => None,
|
||||
DiagMessage::Inline(_) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -355,10 +326,6 @@ impl From<DiagMessage> for SubdiagMessage {
|
|||
fn from(val: DiagMessage) -> Self {
|
||||
match val {
|
||||
DiagMessage::Str(s) => SubdiagMessage::Str(s),
|
||||
DiagMessage::FluentIdentifier(id, None) => SubdiagMessage::FluentIdentifier(id),
|
||||
// There isn't really a sensible behaviour for this because it loses information but
|
||||
// this is the most sensible of the behaviours.
|
||||
DiagMessage::FluentIdentifier(_, Some(attr)) => SubdiagMessage::FluentAttr(attr),
|
||||
DiagMessage::Inline(s) => SubdiagMessage::Inline(s),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue