Skip to main content

vvv_engine/protocol/
answer.rs

1//! What a question about the tree comes back as: plain data over the facts
2//! the model holds, for the CLI to print, the JSON to carry, an agent to read.
3
4use vvv_core::RelPath;
5
6use serde::{Deserialize, Serialize};
7
8use crate::Reach;
9use vvv_core::{Address, ImportRef, Position, Symbol};
10
11/// One import statement in the file and, when the layout can follow it,
12/// where it leads.
13#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
14#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
15pub struct Dep {
16    #[serde(flatten)]
17    pub import: ImportRef,
18    /// Where the import starts, as a line and column.
19    pub start: Position,
20    /// What the path spells, as the layout places it.
21    #[serde(default, skip_serializing_if = "Option::is_none")]
22    pub address: Option<Address>,
23    /// The declaration the address reaches through re-exports, when that is
24    /// somewhere else: `vvv_core::text::span::Span` for `use vvv_core::Span`.
25    #[serde(default, skip_serializing_if = "Option::is_none")]
26    pub origin: Option<Address>,
27    /// The file declaring what the import reaches — the origin's when known.
28    #[serde(default, skip_serializing_if = "Option::is_none")]
29    pub file: Option<RelPath>,
30}
31
32/// A file that imports from the one asked about.
33#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
34#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
35pub struct Importer {
36    pub path: RelPath,
37    #[serde(flatten)]
38    pub import: ImportRef,
39    pub start: Position,
40}
41
42/// A declaration as the graph holds it: placed, with its reach.
43#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
44#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
45pub struct Placed {
46    pub path: RelPath,
47    #[serde(flatten)]
48    pub symbol: Symbol,
49    /// Where the declaration's name starts, as a line and column.
50    pub start: Position,
51    pub address: Address,
52    pub reach: Reach,
53}