use alpha2_diagnose::{Node, Path, Segment};
use super::ids::{IdIndex, Namespace};
use crate::{
AudioNodeRef, DataOwner, EffectOwner, EffectProblem, LintIssue, LintOwner, ModelError,
ShapeLintOwner, ShapeOwner,
};
#[derive(Clone, Copy, Debug)]
pub enum Anchor<'a> {
Root,
Source(&'a str),
EffectResource(&'a str),
Composition(&'a str),
Node {
composition: &'a str,
node: &'a str,
},
Track(&'a str),
Clip(&'a str),
DataSet(&'a str),
Bus(&'a str),
TrackAudio(&'a str),
Transition {
track: &'a str,
from_clip: &'a str,
to_clip: &'a str,
},
Cue {
track: &'a str,
index: usize,
},
}
#[derive(Clone, Debug)]
pub enum Inner<'a> {
Here,
Field(String),
Nested(String),
Text(&'a str),
Key(&'a str, &'a str),
Param(&'a str, &'a str),
}
#[derive(Clone, Debug)]
pub struct Locus {
pub path: Path,
pub subject: Option<Node>,
pub related: Option<Path>,
}
pub struct Locator<'a> {
tree: &'a Node,
root: &'a Path,
index: &'a IdIndex,
}
impl<'a> Locator<'a> {
#[must_use]
pub const fn new(tree: &'a Node, root: &'a Path, index: &'a IdIndex) -> Self {
Self { tree, root, index }
}
#[must_use]
pub const fn index(&self) -> &IdIndex {
self.index
}
#[must_use]
pub const fn tree(&self) -> &Node {
self.tree
}
fn exists(&self, path: &Path) -> bool {
self.tree.at(path).is_some()
}
#[must_use]
pub fn anchor_path(&self, anchor: Anchor<'_>) -> Option<Path> {
let index = self.index;
match anchor {
Anchor::Root => Some(self.root.clone()),
Anchor::Source(id) => first(index.paths(Namespace::Source, id)),
Anchor::EffectResource(id) => first(index.paths(Namespace::EffectResource, id)),
Anchor::Composition(id) => first(index.paths(Namespace::Composition, id)),
Anchor::Node { composition, node } => first(index.node(composition, node))
.or_else(|| first(index.paths(Namespace::Composition, composition))),
Anchor::Track(id) => first(index.paths(Namespace::Track, id)),
Anchor::TrackAudio(id) => first(index.paths(Namespace::Track, id))
.map(|track| track.key("audio"))
.filter(|path| self.exists(path))
.or_else(|| first(index.paths(Namespace::Track, id))),
Anchor::Clip(id) => first(index.paths(Namespace::Clip, id)),
Anchor::DataSet(id) => first(index.paths(Namespace::DataSet, id)),
Anchor::Bus(id) => first(index.paths(Namespace::Bus, id)),
Anchor::Transition {
track,
from_clip,
to_clip,
} => index
.transition(track, from_clip, to_clip)
.cloned()
.or_else(|| first(index.paths(Namespace::Track, track))),
Anchor::Cue { track, index: cue } => {
let track_path = first(index.paths(Namespace::Track, track))?;
let path = track_path.key("captions").key("cues").index(cue);
Some(if self.exists(&path) { path } else { track_path })
}
}
}
#[must_use]
pub fn subject(anchor: Anchor<'_>) -> Option<Node> {
let one =
|kind: &str, id: &str| Node::map([("type", Node::text(kind)), (kind, Node::text(id))]);
Some(match anchor {
Anchor::Root => return None,
Anchor::Source(id) => one("source", id),
Anchor::EffectResource(id) => one("effect_resource", id),
Anchor::Composition(id) => one("composition", id),
Anchor::Node { composition, node } => Node::map([
("type", Node::text("composition_node")),
("composition", Node::text(composition)),
("node", Node::text(node)),
]),
Anchor::Track(id) | Anchor::TrackAudio(id) => one("track", id),
Anchor::Clip(id) => one("clip", id),
Anchor::DataSet(id) => one("data_set", id),
Anchor::Bus(id) => one("bus", id),
Anchor::Transition {
track,
from_clip,
to_clip,
} => Node::map([
("type", Node::text("transition")),
("track", Node::text(track)),
("from_clip", Node::text(from_clip)),
("to_clip", Node::text(to_clip)),
]),
Anchor::Cue { track, index } => Node::map([
("type", Node::text("cue")),
("track", Node::text(track)),
(
"index",
Node::integer(i64::try_from(index).unwrap_or(i64::MAX)),
),
]),
})
}
#[must_use]
pub fn locate(&self, anchor: Anchor<'_>, inner: &Inner<'_>) -> Locus {
let subject = Self::subject(anchor);
let Some(base) = self.anchor_path(anchor) else {
return Locus {
path: self.root.clone(),
subject,
related: None,
};
};
let path = match inner {
Inner::Here => base,
Inner::Field(relative) => self.deepest(&base, relative),
Inner::Nested(relative) => self.nested(&base, relative),
Inner::Text(value) => find_text(self.tree, &base, value).unwrap_or(base),
Inner::Param(id, name) => find_text(self.tree, &base, id)
.and_then(|id| id.parent())
.map_or(base, |effect| {
self.existing_prefix(&effect.key("params").key(*name))
}),
Inner::Key(field, key) => {
let named = base.join_text(field).map(|held| held.key(*key));
match named {
Ok(named) if self.exists(&named) => named,
_ => self.deepest(&base, field),
}
}
};
Locus {
path,
subject,
related: None,
}
}
fn deepest(&self, base: &Path, relative: &str) -> Path {
let Ok(full) = base.join_text(relative) else {
return base.clone();
};
self.existing_prefix(&full)
}
fn existing_prefix(&self, full: &Path) -> Path {
let mut path = full.clone();
while !self.exists(&path) {
if path.pop().is_none() {
return self.root.clone();
}
}
path
}
fn nested(&self, base: &Path, relative: &str) -> Path {
let Ok(direct) = base.join_text(relative) else {
return base.clone();
};
if self.exists(&direct) {
return direct;
}
let mut best = self.existing_prefix(&direct);
if let Some(entries) = self.tree.at(base).and_then(Node::as_map) {
for entry in entries {
let Ok(candidate) = base.key(entry.key.as_str()).join_text(relative) else {
continue;
};
if self.exists(&candidate) {
return candidate;
}
let prefix = self.existing_prefix(&candidate);
if prefix.segments().len() > best.segments().len() + 1 {
best = prefix;
}
}
}
best
}
#[must_use]
pub fn error(&self, error: &ModelError) -> Locus {
if let Some(locus) = self.repeated(error) {
return locus;
}
if matches!(error, ModelError::EmptyIdentifier) {
return Locus {
path: first_empty_id(self.tree, self.root),
subject: None,
related: None,
};
}
let (anchor, inner) = error_place(error, self.tree, self.index);
let mut locus = self.locate(anchor, &inner);
if let ModelError::OverlappingClips { first: earlier, .. } = error {
locus.related = first(self.index.paths(Namespace::Clip, earlier.as_str()));
}
locus
}
fn repeated(&self, error: &ModelError) -> Option<Locus> {
let (places, anchor): (&[Path], Anchor<'_>) = match error {
ModelError::DuplicateDataSetId(id) => (
self.index.paths(Namespace::DataSet, id.as_str()),
Anchor::DataSet(id.as_str()),
),
ModelError::DuplicateSourceId(id) => (
self.index.paths(Namespace::Source, id.as_str()),
Anchor::Source(id.as_str()),
),
ModelError::DuplicateEffectResourceId(id) => (
self.index.paths(Namespace::EffectResource, id.as_str()),
Anchor::EffectResource(id.as_str()),
),
ModelError::DuplicateTrackId(id) => (
self.index.paths(Namespace::Track, id.as_str()),
Anchor::Track(id.as_str()),
),
ModelError::DuplicateClipId(id) => (
self.index.paths(Namespace::Clip, id.as_str()),
Anchor::Clip(id.as_str()),
),
ModelError::DuplicateCompositionId(id) => (
self.index.paths(Namespace::Composition, id.as_str()),
Anchor::Composition(id.as_str()),
),
ModelError::DuplicateNodeId { composition, node } => (
self.index.node(composition.as_str(), node.as_str()),
Anchor::Node {
composition: composition.as_str(),
node: node.as_str(),
},
),
ModelError::DuplicateAudioBus { bus } => (
self.index.paths(Namespace::Bus, bus.as_str()),
Anchor::Bus(bus.as_str()),
),
ModelError::DuplicateTransition {
track,
first,
second,
} => {
let matching: Vec<&Path> = self
.index
.transitions()
.iter()
.filter(|place| {
place.track == track.as_str()
&& ((place.from_clip == first.as_str()
&& place.to_clip == second.as_str())
|| (place.from_clip == second.as_str()
&& place.to_clip == first.as_str()))
})
.map(|place| &place.path)
.collect();
let [earlier, .., later] = matching.as_slice() else {
return None;
};
return Some(Locus {
path: (*later).clone(),
subject: Self::subject(Anchor::Track(track.as_str())),
related: Some((*earlier).clone()),
});
}
_ => return None,
};
let [first, second, ..] = places else {
return None;
};
Some(Locus {
path: second.key("id"),
subject: Self::subject(anchor),
related: Some(first.key("id")),
})
.filter(|locus| self.exists(&locus.path))
}
#[must_use]
pub fn lint(&self, issue: &LintIssue) -> Locus {
let (anchor, inner) = lint_place(issue);
let mut locus = self.locate(anchor, &inner);
if let LintIssue::HiddenClip { by, .. } = issue {
locus.related = first(self.index.paths(Namespace::Clip, by.as_str()));
}
locus
}
}
fn first(places: &[Path]) -> Option<Path> {
places.first().cloned()
}
fn find_text(tree: &Node, base: &Path, value: &str) -> Option<Path> {
fn walk(node: &Node, path: &mut Path, value: &str) -> bool {
if node.as_str() == Some(value) {
return true;
}
if let Some(entries) = node.as_map() {
for entry in entries {
path.push(Segment::Key(entry.key.clone()));
if walk(&entry.value, path, value) {
return true;
}
path.pop();
}
} else if let Some(items) = node.as_list() {
for (index, item) in items.iter().enumerate() {
path.push(Segment::Index(index));
if walk(item, path, value) {
return true;
}
path.pop();
}
}
false
}
let mut path = base.clone();
walk(tree.at(base)?, &mut path, value).then_some(path)
}
fn first_empty_id(tree: &Node, root: &Path) -> Path {
fn walk(node: &Node, path: &mut Path) -> bool {
if let Some(entries) = node.as_map() {
for entry in entries {
path.push(Segment::Key(entry.key.clone()));
let names_id = entry.key == "id" || entry.key.ends_with("_id");
if (names_id && entry.value.as_str() == Some("")) || walk(&entry.value, path) {
return true;
}
path.pop();
}
} else if let Some(items) = node.as_list() {
for (index, item) in items.iter().enumerate() {
path.push(Segment::Index(index));
if walk(item, path) {
return true;
}
path.pop();
}
}
false
}
let mut path = root.clone();
if walk(tree, &mut path) {
path
} else {
root.clone()
}
}
fn audio_anchor(node: &AudioNodeRef) -> Anchor<'_> {
match node {
AudioNodeRef::Track(track) => Anchor::TrackAudio(track.as_str()),
AudioNodeRef::Bus(bus) => Anchor::Bus(bus.as_str()),
}
}
fn audio_id(node: &AudioNodeRef) -> &str {
match node {
AudioNodeRef::Track(track) => track.as_str(),
AudioNodeRef::Bus(bus) => bus.as_str(),
}
}
fn shape_anchor(owner: &ShapeOwner) -> Anchor<'_> {
match owner {
ShapeOwner::Source(source) => Anchor::Source(source.as_str()),
ShapeOwner::Clip(clip) => Anchor::Clip(clip.as_str()),
ShapeOwner::Node { composition, node } => Anchor::Node {
composition: composition.as_str(),
node: node.as_str(),
},
}
}
fn data_anchor(owner: &DataOwner) -> Anchor<'_> {
match owner {
DataOwner::Clip(clip) => Anchor::Clip(clip.as_str()),
DataOwner::Track(track) => Anchor::Track(track.as_str()),
DataOwner::Master => Anchor::Root,
DataOwner::Bus(bus) => Anchor::Bus(bus.as_str()),
DataOwner::Transition { track, from, to } => Anchor::Transition {
track: track.as_str(),
from_clip: from.as_str(),
to_clip: to.as_str(),
},
DataOwner::Node { composition, node } => Anchor::Node {
composition: composition.as_str(),
node: node.as_str(),
},
DataOwner::Source(source) => Anchor::Source(source.as_str()),
}
}
fn effect_anchor(owner: &EffectOwner) -> Anchor<'_> {
match owner {
EffectOwner::Node { composition, node } => Anchor::Node {
composition: composition.as_str(),
node: node.as_str(),
},
EffectOwner::Transition { track, from, to } => Anchor::Transition {
track: track.as_str(),
from_clip: from.as_str(),
to_clip: to.as_str(),
},
EffectOwner::Source(source) => Anchor::Source(source.as_str()),
}
}
fn field(relative: &str) -> Inner<'static> {
Inner::Field(relative.to_owned())
}
fn data_set_inner(problem: &crate::DataProblem) -> Inner<'static> {
use crate::DataProblem as P;
match problem {
P::IdTooLong => field("id"),
P::UnknownSource(_) | P::SourceWithoutMedia(_) => field("anchor.source_id"),
P::ChannelCount | P::ChannelName => field("channels"),
P::TooManyValues | P::ValueCount => field("values"),
P::InvalidValue { index } => Inner::Field(format!("values[{index}]")),
P::TimesNotAscending | P::NegativeTime => field("times"),
P::TooManyItems | P::InvalidItem { .. } => Inner::Here,
P::InvalidMadeBy => field("made_by"),
P::InvalidMadeFrom(part) => Inner::Field(format!("made_from.{part}")),
}
}
fn effect_inner<'a>(id: &'a str, problem: &'a EffectProblem) -> Inner<'a> {
match problem {
EffectProblem::UnknownParam(name) | EffectProblem::InvalidParam(name) => {
Inner::Param(id, name)
}
_ => Inner::Text(id),
}
}
#[expect(clippy::too_many_lines, reason = "one arm per variant")]
fn error_place<'a>(
error: &'a ModelError,
tree: &'a Node,
index: &'a IdIndex,
) -> (Anchor<'a>, Inner<'a>) {
use ModelError as E;
match error {
E::UnsupportedSchemaVersion { .. } => (Anchor::Root, field("schema_version")),
E::TooManyDataSets { .. } => (Anchor::Root, field("data")),
E::DuplicateDataSetId(id) => (Anchor::DataSet(id.as_str()), Inner::Here),
E::InvalidDataSet { data, problem } => {
(Anchor::DataSet(data.as_str()), data_set_inner(problem))
}
E::InvalidDataBinding { owner, at, .. } => {
let inner = match owner {
DataOwner::Master => Inner::Field(format!("audio.{at}")),
_ => Inner::Nested(at.clone()),
};
(data_anchor(owner), inner)
}
E::EmptyIdentifier => (Anchor::Root, Inner::Here),
E::DuplicateSourceId(id)
| E::InvalidCompositionSource { source: id }
| E::InvalidAdjustmentSource { source: id } => (Anchor::Source(id.as_str()), Inner::Here),
E::DuplicateEffectResourceId(id) => (Anchor::EffectResource(id.as_str()), Inner::Here),
E::DuplicateTrackId(id) => (Anchor::Track(id.as_str()), Inner::Here),
E::DuplicateClipId(id) => (Anchor::Clip(id.as_str()), Inner::Here),
E::EmptyLocator { source } => (Anchor::Source(source.as_str()), field("locator")),
E::AudioOnImage { source } => (Anchor::Source(source.as_str()), field("has_audio")),
E::InvalidProvider { source } => (Anchor::Source(source.as_str()), field("provider")),
E::InvalidFingerprint { source } => (Anchor::Source(source.as_str()), field("fingerprint")),
E::ContradictoryColor { source } => {
(Anchor::Source(source.as_str()), field("color_metadata"))
}
E::InvalidGenerator { source } => (Anchor::Source(source.as_str()), field("generator")),
E::InvalidShape { owner, at, .. } | E::InvalidLayout { owner, at, .. } => {
(shape_anchor(owner), Inner::Nested(at.clone()))
}
E::InvalidTextRunStyle { owner, run } => {
(shape_anchor(owner), Inner::Nested(format!("text[{run}]")))
}
E::EmptyEffectResourceLocator { resource } => {
(Anchor::EffectResource(resource.as_str()), field("locator"))
}
E::UnknownEffectResource { clip, resource } => {
(Anchor::Clip(clip.as_str()), Inner::Text(resource.as_str()))
}
E::EmptyClipRange { clip }
| E::InvalidVisualProperties { clip }
| E::InvalidAudioProperties { clip }
| E::FrameDrawsTooManyNodes { clip, .. } => (
Anchor::Clip(clip.as_str()),
match error {
E::InvalidVisualProperties { .. } => field("visual"),
E::InvalidAudioProperties { .. } => field("audio"),
_ => Inner::Here,
},
),
E::NegativeClipRange { clip } | E::OverlappingClips { second: clip, .. } => {
(Anchor::Clip(clip.as_str()), field("timeline_range"))
}
E::UnknownClipSource { clip, .. } | E::IncompatibleClipSource { clip, .. } => {
(Anchor::Clip(clip.as_str()), field("source_id"))
}
E::InvalidTrackAudio { track } => (Anchor::TrackAudio(track.as_str()), Inner::Here),
E::InvalidMasterAudio => (Anchor::Root, field("audio")),
E::InvalidAudioBus { bus } | E::DuplicateAudioBus { bus } => {
(Anchor::Bus(bus.as_str()), Inner::Here)
}
E::InvalidAudioSend { from, to } => (audio_anchor(from), Inner::Text(to.as_str())),
E::UnknownAudioBus { from, bus } => (audio_anchor(from), Inner::Text(bus.as_str())),
E::AudioRoutingCycle { node } => (audio_anchor(node), Inner::Here),
E::TooManyAudioBuses { .. } => (Anchor::Root, field("audio.buses")),
E::UnknownAudioSidechain { owner, sidechain } => (
owner.as_ref().map_or(Anchor::Root, audio_anchor),
match owner {
Some(_) => Inner::Text(audio_id(sidechain)),
None => field("audio"),
},
),
E::UnknownComposition { clip, composition } => (
Anchor::Clip(clip.as_str()),
Inner::Text(composition.as_str()),
),
E::InvalidClipComposition { clip } => (Anchor::Clip(clip.as_str()), field("composition")),
E::DuplicateCompositionId(composition)
| E::InvalidCompositionPorts { composition }
| E::CompositionUsesItself { composition }
| E::CompositionNestedTooDeep { composition, .. } => {
(Anchor::Composition(composition.as_str()), Inner::Here)
}
E::InvalidNodeId { composition, node } | E::DuplicateNodeId { composition, node } => (
Anchor::Node {
composition: composition.as_str(),
node: node.as_str(),
},
field("id"),
),
E::TooManyCompositionNodes { composition, .. } => {
(Anchor::Composition(composition.as_str()), field("nodes"))
}
E::InvalidNode { composition, node }
| E::CompositionCycle { composition, node }
| E::InvalidTimeOffset {
composition, node, ..
} => (
Anchor::Node {
composition: composition.as_str(),
node: node.as_str(),
},
Inner::Here,
),
E::UnknownNodeInput {
composition,
node,
target,
..
} => (
Anchor::Node {
composition: composition.as_str(),
node: node.as_str(),
},
Inner::Text(target.as_str()),
),
E::UnknownCompositionOutput { composition, .. } => {
(Anchor::Composition(composition.as_str()), field("output"))
}
E::InvalidNodeSource {
composition,
node,
source,
} => (
Anchor::Node {
composition: composition.as_str(),
node: node.as_str(),
},
Inner::Text(source.as_str()),
),
E::UnknownGroupComposition {
composition,
node,
target,
} => (
Anchor::Node {
composition: composition.as_str(),
node: node.as_str(),
},
Inner::Text(target.as_str()),
),
E::InvalidAdjustmentTransition { track, clip } => {
let around = index.transitions().iter().find(|place| {
place.track == track.as_str()
&& (place.from_clip == clip.as_str() || place.to_clip == clip.as_str())
});
match around {
Some(place) => (
Anchor::Transition {
track: track.as_str(),
from_clip: &place.from_clip,
to_clip: &place.to_clip,
},
field("effect"),
),
None => (Anchor::Clip(clip.as_str()), Inner::Here),
}
}
E::InvalidEffect { owner, id, problem } => {
(effect_anchor(owner), effect_inner(id, problem))
}
E::UnknownNodeResource {
composition,
node,
resource,
} => (
Anchor::Node {
composition: composition.as_str(),
node: node.as_str(),
},
Inner::Text(resource.as_str()),
),
E::UnknownSourceResource { source, resource } => (
Anchor::Source(source.as_str()),
Inner::Text(resource.as_str()),
),
E::InvalidClipMask { clip } => (Anchor::Clip(clip.as_str()), field("masks")),
E::InvalidCaptions { track } | E::TooManyDerivedCues { track } => {
(Anchor::Track(track.as_str()), field("captions"))
}
E::UnknownCaptionStyle { track, cue, name } => (
Anchor::Cue {
track: track.as_str(),
index: *cue,
},
Inner::Text(name.as_str()),
),
E::InvalidCaptionCueStyle { track, cue } => (
Anchor::Cue {
track: track.as_str(),
index: *cue,
},
Inner::Here,
),
E::InvalidTimeMap { clip, .. } | E::TooManyLoopPasses { clip, .. } => {
(Anchor::Clip(clip.as_str()), field("time_map"))
}
E::InvalidMatte { clip } => (Anchor::Clip(clip.as_str()), field("matte")),
E::InvalidFrameInterpolation { clip } => {
(Anchor::Clip(clip.as_str()), field("frame_interpolation"))
}
E::InvalidClipTransition { track }
| E::TransitionCycle { track, .. }
| E::DuplicateTransition { track, .. }
| E::TooManyTransitions { track, .. } => {
(Anchor::Track(track.as_str()), field("transitions"))
}
E::UnwritableTime { .. } | E::TooManyAudioEffects { .. } | E::TooMuchAudioDelay { .. } => {
(Anchor::Root, Inner::Here)
}
E::TooManyEffectResources { .. } => (Anchor::Root, field("effect_resources")),
E::TooManyCompositions { .. } | E::TooManyInlinedNodes { .. } => {
(Anchor::Root, field("compositions"))
}
E::TooManySources { .. } => (Anchor::Root, field("sources")),
E::TooManyTracks { .. } | E::TooManyClips { .. } => {
(Anchor::Root, field("timeline.tracks"))
}
E::TooManyClipsOnTrack { track, .. } => (Anchor::Track(track.as_str()), field("clips")),
E::TooManyCaptionCues { track, .. } => {
(Anchor::Track(track.as_str()), field("captions.cues"))
}
E::ZeroCanvasDimension => {
let zero = |key: &str| {
tree.get("settings")
.and_then(|settings| settings.get(key))
.is_some_and(|value| value.as_number().is_some_and(|n| n.as_f64() == 0.0))
};
let key = if zero("width") || !zero("height") {
"settings.width"
} else {
"settings.height"
};
(Anchor::Root, field(key))
}
E::CanvasDimensionTooLarge { .. } | E::CanvasPixelBudgetExceeded { .. } => {
(Anchor::Root, field("settings"))
}
E::InvalidBackground => (Anchor::Root, field("settings.background")),
E::InvalidColorPipeline => (Anchor::Root, field("settings.color")),
E::InvalidShutter(_) => (Anchor::Root, field("settings.shutter")),
E::UnsupportedSampleRate { .. } => (Anchor::Root, field("settings.sample_rate")),
}
}
fn lint_anchor(owner: &LintOwner) -> Anchor<'_> {
match owner {
LintOwner::Clip { clip } => Anchor::Clip(clip.as_str()),
LintOwner::Transition {
track,
from_clip,
to_clip,
} => Anchor::Transition {
track: track.as_str(),
from_clip: from_clip.as_str(),
to_clip: to_clip.as_str(),
},
LintOwner::Cue { track, index }
| LintOwner::CueRun {
track, cue: index, ..
} => Anchor::Cue {
track: track.as_str(),
index: *index,
},
LintOwner::CompositionNode { composition, node } => Anchor::Node {
composition: composition.as_str(),
node: node.as_str(),
},
LintOwner::Source { source } => Anchor::Source(source.as_str()),
LintOwner::CaptionTrack { track } => Anchor::Track(track.as_str()),
}
}
fn lint_owner_inner(owner: &LintOwner, relative: Option<&str>) -> Inner<'static> {
let prefix = match owner {
LintOwner::CaptionTrack { .. } => Some("captions".to_owned()),
LintOwner::CueRun { run, .. } => Some(format!("runs[{run}]")),
_ => None,
};
match (prefix, relative) {
(Some(prefix), Some(relative)) => Inner::Nested(format!("{prefix}.{relative}")),
(Some(prefix), None) => Inner::Field(prefix),
(None, Some(relative)) => Inner::Nested(relative.to_owned()),
(None, None) => Inner::Here,
}
}
fn shape_lint_anchor(owner: &ShapeLintOwner) -> Anchor<'_> {
match owner {
ShapeLintOwner::Source { source } => Anchor::Source(source.as_str()),
ShapeLintOwner::Node { composition, node } => Anchor::Node {
composition: composition.as_str(),
node: node.as_str(),
},
}
}
fn lint_place(issue: &LintIssue) -> (Anchor<'_>, Inner<'_>) {
use LintIssue as L;
match issue {
L::UnreachedKeyframe {
owner, property, ..
} => (lint_anchor(owner), lint_owner_inner(owner, Some(property))),
L::OffFrameBoundary { owner, edge, .. } => {
let edge = match edge {
crate::LintEdge::Start => "start",
crate::LintEdge::End => "end",
};
let relative = match owner {
LintOwner::Clip { .. } | LintOwner::Transition { .. } => {
format!("timeline_range.{edge}")
}
_ => edge.to_owned(),
};
(lint_anchor(owner), lint_owner_inner(owner, Some(&relative)))
}
L::EmptyTextAnimator { owner, at } | L::HighlightWithoutTimedRuns { owner, at } => {
(lint_anchor(owner), lint_owner_inner(owner, Some(at)))
}
L::MotionBlurWithoutMotion { owner } => (
lint_anchor(owner),
lint_owner_inner(owner, Some("motion_blur")),
),
L::HiddenClip { clip, .. } | L::ManyShiftedReads { clip, .. } => {
(Anchor::Clip(clip.as_str()), Inner::Here)
}
L::SubFrameClip { clip } => (Anchor::Clip(clip.as_str()), field("timeline_range")),
L::ShortTransition {
track,
from_clip,
to_clip,
} => (
Anchor::Transition {
track: track.as_str(),
from_clip: from_clip.as_str(),
to_clip: to_clip.as_str(),
},
Inner::Here,
),
L::UnusedSource { source } => (Anchor::Source(source.as_str()), Inner::Here),
L::HdrSource { source } => (Anchor::Source(source.as_str()), field("color_metadata")),
L::EmptySubpath { owner, at } | L::PaintWithoutGeometry { owner, at } => {
(shape_lint_anchor(owner), Inner::Nested(at.clone()))
}
L::UnusedCaptionStyle { track, style } => (
Anchor::Track(track.as_str()),
Inner::Key("captions.styles", style.as_str()),
),
L::StaleData { data, .. } => (Anchor::DataSet(data.as_str()), field("made_from")),
}
}