cp_ast_core/projection/api.rs
1use super::types::{
2 AvailableAction, CandidateKind, CompletenessSummary, NodeDetail, NotEditableReason,
3 ProjectedNode, SlotEntry,
4};
5use crate::structure::NodeId;
6
7/// The main projection API for viewing AST structure and constraints.
8///
9/// This trait provides read-only views of the AST for UI consumption,
10/// transforming internal representations into display-ready formats.
11pub trait ProjectionAPI {
12 /// Return all nodes in DFS traversal order with display information.
13 #[must_use]
14 fn nodes(&self) -> Vec<ProjectedNode>;
15
16 /// Get named slot entries (children) for a specific node.
17 #[must_use]
18 fn children(&self, node: NodeId) -> Vec<SlotEntry>;
19
20 /// Get detailed information about a node including constraints.
21 #[must_use]
22 fn inspect(&self, node: NodeId) -> Option<NodeDetail>;
23
24 /// Get candidate types that can fill a hole node.
25 #[must_use]
26 fn hole_candidates(&self, hole: NodeId) -> Vec<CandidateKind>;
27
28 /// Get all available actions that can be performed on the AST.
29 #[must_use]
30 fn available_actions(&self) -> Vec<AvailableAction>;
31
32 /// Check if a node cannot be edited and return the reason.
33 #[must_use]
34 fn why_not_editable(&self, node: NodeId) -> Option<NotEditableReason>;
35
36 /// Get a summary of AST completeness status.
37 #[must_use]
38 fn completeness(&self) -> CompletenessSummary;
39}