Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit 4e2c9d6

Browse files
oppiliappanHendrik van Antwerpen
authored andcommitted
load SourceInfo into each node during deserialization
the same needs to be done for DebugInfo.
1 parent f4c0b53 commit 4e2c9d6

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

stack-graphs/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ edition = "2018"
1616
copious-debugging = []
1717
serde = ["dep:serde", "lsp-positions/serde"]
1818
json = ["serde", "serde_json", "lsp-positions/serde"]
19+
tree-sitter = ["lsp-positions/tree-sitter"]
1920

2021
[lib]
2122
# All of our tests are in the tests/it "integration" test executable.

stack-graphs/src/serde.rs

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ impl StackGraph {
7575

7676
fn load_nodes(&self, graph: &mut crate::graph::StackGraph) -> Result<(), Error> {
7777
for n in self.nodes.data.as_slice() {
78-
match n {
78+
let handle = match n {
7979
Node::DropScopes { id, .. } => {
8080
let node_id = id.into_node_id(graph)?;
81-
graph.add_drop_scopes_node(node_id);
81+
graph.add_drop_scopes_node(node_id)
8282
}
8383
Node::PopScopedSymbol {
8484
id,
@@ -88,7 +88,7 @@ impl StackGraph {
8888
} => {
8989
let node_id = id.into_node_id(graph)?;
9090
let symbol_handle = graph.add_symbol(symbol.as_str());
91-
graph.add_pop_scoped_symbol_node(node_id, symbol_handle, *is_definition);
91+
graph.add_pop_scoped_symbol_node(node_id, symbol_handle, *is_definition)
9292
}
9393
Node::PopSymbol {
9494
id,
@@ -98,7 +98,7 @@ impl StackGraph {
9898
} => {
9999
let node_id = id.into_node_id(graph)?;
100100
let symbol_handle = graph.add_symbol(symbol.as_str());
101-
graph.add_pop_symbol_node(node_id, symbol_handle, *is_definition);
101+
graph.add_pop_symbol_node(node_id, symbol_handle, *is_definition)
102102
}
103103
Node::PushScopedSymbol {
104104
id,
@@ -110,13 +110,12 @@ impl StackGraph {
110110
let node_id = id.into_node_id(graph)?;
111111
let scope_id = scope.into_node_id(graph)?;
112112
let symbol_handle = graph.add_symbol(symbol.as_str());
113-
114113
graph.add_push_scoped_symbol_node(
115114
node_id,
116115
symbol_handle,
117116
scope_id,
118117
*is_reference,
119-
);
118+
)
120119
}
121120
Node::PushSymbol {
122121
id,
@@ -126,15 +125,26 @@ impl StackGraph {
126125
} => {
127126
let node_id = id.into_node_id(graph)?;
128127
let symbol_handle = graph.add_symbol(symbol.as_str());
129-
graph.add_push_symbol_node(node_id, symbol_handle, *is_reference);
128+
graph.add_push_symbol_node(node_id, symbol_handle, *is_reference)
130129
}
131130
Node::Scope {
132131
id, is_exported, ..
133132
} => {
134133
let node_id = id.into_node_id(graph)?;
135-
graph.add_scope_node(node_id, *is_exported);
134+
graph.add_scope_node(node_id, *is_exported)
136135
}
137-
Node::JumpToScope { .. } | Node::Root { .. } => {}
136+
Node::JumpToScope { .. } | Node::Root { .. } => None,
137+
};
138+
139+
if let (Some(handle), Some(source_info)) = (handle, n.source_info()) {
140+
*graph.source_info_mut(handle) = crate::graph::SourceInfo {
141+
span: source_info.span.clone(),
142+
syntax_type: source_info
143+
.syntax_type
144+
.as_ref()
145+
.map(|st| graph.add_string(st.as_str())),
146+
..Default::default()
147+
};
138148
}
139149
}
140150
Ok(())
@@ -238,6 +248,22 @@ pub enum Node {
238248
},
239249
}
240250

251+
impl Node {
252+
fn source_info(&self) -> Option<&SourceInfo> {
253+
match self {
254+
Self::DropScopes { source_info, .. } => source_info,
255+
Self::JumpToScope { source_info, .. } => source_info,
256+
Self::PopScopedSymbol { source_info, .. } => source_info,
257+
Self::PopSymbol { source_info, .. } => source_info,
258+
Self::PushScopedSymbol { source_info, .. } => source_info,
259+
Self::PushSymbol { source_info, .. } => source_info,
260+
Self::Root { source_info, .. } => source_info,
261+
Self::Scope { source_info, .. } => source_info,
262+
}
263+
.as_ref()
264+
}
265+
}
266+
241267
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
242268
pub struct SourceInfo {
243269
span: lsp_positions::Span,

0 commit comments

Comments
 (0)