mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-03 21:08:18 +00:00
Add node introspection API
Closes #1110 Test Plan: query the introspectNode Endpoint from js Reviewers: Pull Request: https://github.com/GraphiteEditor/Graphite/pull/1183
This commit is contained in:
parent
0af42ee6f9
commit
bea7cc8dd0
6 changed files with 48 additions and 5 deletions
|
@ -50,6 +50,10 @@ impl DynamicExecutor {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn introspect(&self, node_path: &[NodeId]) -> Option<Option<String>> {
|
||||
self.tree.introspect(node_path)
|
||||
}
|
||||
|
||||
pub fn input_type(&self) -> Option<Type> {
|
||||
self.typing_context.type_of(self.output).map(|node_io| node_io.input.clone())
|
||||
}
|
||||
|
@ -99,6 +103,7 @@ impl NodeContainer<'static> {
|
|||
#[derive(Default, Debug, Clone)]
|
||||
pub struct BorrowTree {
|
||||
nodes: HashMap<NodeId, Arc<RwLock<NodeContainer<'static>>>>,
|
||||
source_map: HashMap<Vec<NodeId>, NodeId>,
|
||||
}
|
||||
|
||||
impl BorrowTree {
|
||||
|
@ -123,6 +128,7 @@ impl BorrowTree {
|
|||
node.reset();
|
||||
}
|
||||
old_nodes.remove(&id);
|
||||
self.source_map.retain(|_, nid| *nid != id);
|
||||
}
|
||||
Ok(old_nodes.into_iter().collect())
|
||||
}
|
||||
|
@ -139,6 +145,14 @@ impl BorrowTree {
|
|||
node
|
||||
}
|
||||
|
||||
pub fn introspect(&self, node_path: &[NodeId]) -> Option<Option<String>> {
|
||||
let id = self.source_map.get(node_path)?;
|
||||
let node = self.nodes.get(id)?;
|
||||
let reader = node.read().unwrap();
|
||||
let node = reader.node.as_ref();
|
||||
Some(node.serialize())
|
||||
}
|
||||
|
||||
pub fn get(&self, id: NodeId) -> Option<Arc<RwLock<NodeContainer<'static>>>> {
|
||||
self.nodes.get(&id).cloned()
|
||||
}
|
||||
|
@ -163,6 +177,7 @@ impl BorrowTree {
|
|||
|
||||
pub fn push_node(&mut self, id: NodeId, proto_node: ProtoNode, typing_context: &TypingContext) -> Result<(), String> {
|
||||
let ProtoNode { construction_args, identifier, .. } = proto_node;
|
||||
self.source_map.insert(proto_node.document_node_path, id);
|
||||
|
||||
match construction_args {
|
||||
ConstructionArgs::Value(value) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue