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

Commit 2ec09d2

Browse files
oppiliappanHendrik van Antwerpen
authored andcommitted
load DebugInfo into each node during deserialization
1 parent 4e2c9d6 commit 2ec09d2

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

stack-graphs/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ 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"]
2019

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

stack-graphs/src/serde.rs

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,31 @@ impl StackGraph {
136136
Node::JumpToScope { .. } | Node::Root { .. } => None,
137137
};
138138

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-
};
139+
if let Some(handle) = handle {
140+
// load source-info of each node
141+
if let Some(source_info) = n.source_info() {
142+
*graph.source_info_mut(handle) = crate::graph::SourceInfo {
143+
span: source_info.span.clone(),
144+
syntax_type: source_info
145+
.syntax_type
146+
.as_ref()
147+
.map(|st| graph.add_string(st.as_str())),
148+
..Default::default()
149+
};
150+
}
151+
152+
// load debug-info of each node
153+
if let Some(debug_info) = n.debug_info() {
154+
*graph.debug_info_mut(handle) = debug_info.data.iter().fold(
155+
crate::graph::DebugInfo::default(),
156+
|mut info, entry| {
157+
let key = graph.add_string(entry.key.as_str());
158+
let value = graph.add_string(entry.value.as_str());
159+
info.add(key, value);
160+
info
161+
},
162+
);
163+
}
148164
}
149165
}
150166
Ok(())
@@ -262,6 +278,20 @@ impl Node {
262278
}
263279
.as_ref()
264280
}
281+
282+
fn debug_info(&self) -> Option<&DebugInfo> {
283+
match self {
284+
Self::DropScopes { debug_info, .. } => debug_info,
285+
Self::JumpToScope { debug_info, .. } => debug_info,
286+
Self::PopScopedSymbol { debug_info, .. } => debug_info,
287+
Self::PopSymbol { debug_info, .. } => debug_info,
288+
Self::PushScopedSymbol { debug_info, .. } => debug_info,
289+
Self::PushSymbol { debug_info, .. } => debug_info,
290+
Self::Root { debug_info, .. } => debug_info,
291+
Self::Scope { debug_info, .. } => debug_info,
292+
}
293+
.as_ref()
294+
}
265295
}
266296

267297
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]

0 commit comments

Comments
 (0)