Skip to content

Commit bda37db

Browse files
author
Jesus Lapastora Núñez
committed
simplify getting top-level scopes
1 parent bda615f commit bda37db

File tree

1 file changed

+5
-19
lines changed
  • engine/baml-lib/ast/src/ast/baml_vis

1 file changed

+5
-19
lines changed

engine/baml-lib/ast/src/ast/baml_vis/graph.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -196,28 +196,14 @@ impl<'index, 'pre> GraphBuilder<'index, 'pre> {
196196
}
197197

198198
pub fn build(mut self) -> (Graph<'index>, BamlMap<NodeId, SerializedSpan>) {
199-
let mut tops: Vec<(String, usize, usize, ScopeId)> = Vec::new();
200-
let mut seen_scopes: HashSet<ScopeId> = HashSet::new();
201-
202199
let scope_root = build_scope_roots(self.index);
203200

204-
for h in &self.index.headers {
205-
if seen_scopes.insert(h.scope) {
206-
let root_hid = scope_root[&h.scope];
207-
if !self.nested_targets.contains(&root_hid) {
208-
let root = self.by_hid[&root_hid];
209-
tops.push((
210-
root.span.file.path_buf().to_string_lossy().into_owned(),
211-
root.span.start,
212-
root.span.end,
213-
h.scope,
214-
));
215-
}
216-
}
217-
}
218-
tops.sort_by(|a, b| a.0.cmp(&b.0).then(a.1.cmp(&b.1)).then(a.2.cmp(&b.2)));
201+
let top_scopes = self.index.scopes().filter(|scope| {
202+
let root_hid = &scope_root[scope];
203+
!self.nested_targets.contains(&root_hid)
204+
});
219205

220-
for (_, _, _, scope) in tops {
206+
for scope in top_scopes {
221207
self.build_scope_sequence(scope, None);
222208
}
223209

0 commit comments

Comments
 (0)