MCPcopy Create free account
hub / github.com/hashintel/hash / debug_attachments

Function debug_attachments

libs/error-stack/src/fmt/mod.rs:894–946  ·  view source on GitHub ↗
(
    position: Position,
    frames: impl IntoIterator<Item = &'a Frame>,
    config: &mut Config,
)

Source from the content-addressed store, hash-verified

892}
893
894fn debug_attachments<'a>(
895 position: Position,
896 frames: impl IntoIterator<Item = &'a Frame>,
897 config: &mut Config,
898) -> Lines {
899 let last = matches!(position, Position::Final);
900
901 let (opaque, entries) = debug_attachments_invoke(frames, config);
902 let opaque = opaque.render();
903
904 // Calculate the expected end length, by adding all values that have would contribute to the
905 // line count later.
906 let len = entries.len() + opaque.as_ref().map_or(0, |_| 1);
907 let lines = entries.into_iter().map(|value| {
908 value
909 .lines()
910 .map(ToOwned::to_owned)
911 .map(|line| {
912 Line::new().push(Instruction::Value {
913 value: line,
914 style: Style::new(),
915 })
916 })
917 .collect::<Vec<_>>()
918 });
919
920 // indentation for every first line, use `Instruction::Attachment`, otherwise use minimal
921 // indent omit that indent when we're the last value
922 lines
923 .chain(opaque.into_iter().map(|line| line.into_lines().into_vec()))
924 .enumerate()
925 .flat_map(|(idx, lines)| {
926 let position = match idx {
927 pos if pos + 1 == len && last => Position::Final,
928 0 => Position::First,
929 _ => Position::Inner,
930 };
931
932 lines.into_iter().enumerate().map(move |(idx, line)| {
933 if idx == 0 {
934 line.push(Instruction::Attachment { position })
935 } else {
936 line.push(
937 Indent::no_group()
938 .visible(!matches!(position, Position::Final))
939 .spacing(Spacing::Minimal)
940 .into(),
941 )
942 }
943 })
944 })
945 .collect()
946}
947
948fn debug_render(head: Lines, contexts: VecDeque<Lines>, sources: Vec<Lines>) -> Lines {
949 let len = sources.len();

Callers 1

debug_frameFunction · 0.85

Calls 12

debug_attachments_invokeFunction · 0.85
collectMethod · 0.80
into_linesMethod · 0.80
spacingMethod · 0.80
visibleMethod · 0.80
pushMethod · 0.65
renderMethod · 0.45
lenMethod · 0.45
as_refMethod · 0.45
mapMethod · 0.45
into_iterMethod · 0.45
into_vecMethod · 0.45

Tested by

no test coverage detected