Skip to main content

textlane_core/models/
file.rs

1use crate::models::position::UnistPosition;
2
3/// The document a pipeline processes: where it came from and what plugins reported about it.
4#[derive(Clone, Debug, Default)]
5pub struct File {
6    pub path: Option<String>,
7    /// The text the tree was parsed from, which byte spans point into.
8    pub value: Option<String>,
9    pub messages: Vec<Message>,
10    /// What plugins store for whoever reads the result, as vfile's `data` holds it.
11    pub data: serde_json::Map<String, serde_json::Value>,
12}
13
14/// A diagnostic a plugin reported, as vfile-message does.
15#[derive(Clone, Debug, PartialEq, Eq)]
16pub struct Message {
17    pub reason: String,
18    pub source: Option<String>,
19    pub rule: Option<String>,
20    /// Where in the file the message is about.
21    pub place: Option<UnistPosition>,
22}
23
24impl File {
25    pub fn new() -> Self {
26        Self::default()
27    }
28
29    /// Record a warning against the file.
30    pub fn warn(&mut self, reason: impl Into<String>, rule: Option<&str>) {
31        self.messages.push(Message {
32            reason: reason.into(),
33            source: None,
34            rule: rule.map(str::to_string),
35            place: None,
36        });
37    }
38}