Skip to main content

vvv_engine/report/
block.rs

1//! Structured facts retained for every view.
2use crate::protocol::display::Line;
3use crate::{
4    Consumer, Dep, Explanation, Exposed, FileChange, HistoryEntry, ImportSite, Importer, Intent,
5    Match, Notice, Occurrence, OutlineItem, Respelling, Site, Unreferenced,
6};
7use vvv_core::RelPath;
8
9/// One piece of a report, named for what it is so a view can place it.
10#[derive(Debug, Clone)]
11pub enum Block {
12    /// The command and its intent: its own line, then a blank.
13    Title(String),
14    /// A section label.
15    Heading(String),
16    /// The declarations a reference or rename report opens with.
17    Declarations(Vec<Match>),
18    /// Found rows — hits — that a view numbers and groups.
19    Matches(Vec<Match>),
20    /// Occurrences a view judges: a reference, a rename.
21    Verdicts {
22        occurrences: Vec<Occurrence>,
23        /// The files a plan would change, when there is one, so a view can
24        /// mark the rows an edit touches (`±`).
25        plan: Option<ReferencePlan>,
26    },
27    /// Import sites worth a look: unresolved, then unused, then redundant.
28    Imports {
29        unresolved: Vec<ImportSite>,
30        unused: Vec<ImportSite>,
31        redundant: Vec<ImportSite>,
32    },
33    /// What a file imports, grouped by package; `own` is its own, to mark.
34    DepGroups {
35        path: RelPath,
36        imports: Vec<Dep>,
37        own: Option<String>,
38    },
39    /// Who imports a file.
40    Importers(Vec<Importer>),
41    /// What is at a position, and how it is reached.
42    Explanation(Box<Explanation>),
43    /// A file's declarations as a tree, a view aligning the name column.
44    Outline {
45        path: RelPath,
46        items: Vec<OutlineItem>,
47    },
48    /// Where a name is declared: the sites `where` found.
49    Sites(Vec<Site>),
50    SymbolMoveCandidates(Vec<crate::SymbolMoveCandidate>),
51    /// Compact resolved or candidate declaration locations.
52    Locations(Vec<crate::DefinitionLocation>),
53    Relationships(Vec<crate::Relationship>),
54    /// Declarations nothing refers to, and the unsure-token count of each.
55    Dead(Vec<Unreferenced>),
56    /// A package's exposed names, and how many import each.
57    Exposed(Vec<Exposed>),
58    /// The modules that import a declaration, nearest first.
59    Consumers(Vec<Consumer>),
60    /// The ledger, oldest first.
61    History(Vec<HistoryEntry>),
62    /// A batch's steps, in order.
63    Batch(Vec<Intent>),
64    /// What `undo` reversed: moves, then restored files.
65    Undo {
66        moves: Vec<(RelPath, RelPath)>,
67        restored: Vec<RelPath>,
68    },
69    /// A bare line.
70    Line(Line),
71    /// The closing summary: what happened, and what to do next.
72    Summary(Line),
73    /// A hint or a warning.
74    Note(Note),
75    /// The change a plan would make: one file's edits, laid out as a diff.
76    Changes {
77        state: crate::MutationState,
78        files: Vec<FileChange>,
79    },
80    /// A move preview: the changes, and what a plan re-spelled or left by hand.
81    Moved {
82        state: crate::MutationState,
83        files: Vec<FileChange>,
84        respellings: Vec<Respelling>,
85        notices: Vec<Notice>,
86    },
87    /// A vertical gap.
88    Blank,
89}
90
91/// The mutation attached to reference verdicts, retained even when its patch
92/// is hidden by a view.
93#[derive(Debug, Clone)]
94pub struct ReferencePlan {
95    pub state: crate::MutationState,
96    pub files: Vec<FileChange>,
97}
98
99/// A hint or a warning: a view prefixes each.
100#[derive(Debug, Clone)]
101pub enum Note {
102    Hint(String),
103    Warning(Line),
104}
105
106/// The counts a move's summary line reports.
107pub(crate) struct MoveCounts {
108    pub(crate) respellings: usize,
109    pub(crate) structural: usize,
110    pub(crate) notices: usize,
111    pub(crate) files: usize,
112}