Preserve order when grouping references.

This commit is contained in:
Kyle Huey 2022-03-22 12:38:59 -07:00
parent 0583919919
commit af1aa86ac0

View file

@ -212,7 +212,7 @@ impl LsifManager<'_> {
in_v: result_id.into(), in_v: result_id.into(),
out_v: result_set_id.into(), out_v: result_set_id.into(),
})); }));
let edges = token.references.iter().fold( let mut edges = token.references.iter().fold(
HashMap::<_, Vec<lsp_types::NumberOrString>>::new(), HashMap::<_, Vec<lsp_types::NumberOrString>>::new(),
|mut edges, x| { |mut edges, x| {
let entry = let entry =
@ -221,16 +221,21 @@ impl LsifManager<'_> {
edges edges
}, },
); );
for ((file_id, is_definition), vertices) in edges.into_iter() { for x in token.references {
self.add_edge(lsif::Edge::Item(lsif::Item { if let Some(vertices) = edges.remove(&(x.range.file_id, x.is_definition)) {
document: (*self.file_map.get(&file_id).unwrap()).into(), self.add_edge(lsif::Edge::Item(lsif::Item {
property: Some(if is_definition { document: (*self.file_map.get(&x.range.file_id).unwrap()).into(),
lsif::ItemKind::Definitions property: Some(if x.is_definition {
} else { lsif::ItemKind::Definitions
lsif::ItemKind::References } else {
}), lsif::ItemKind::References
edge_data: lsif::EdgeDataMultiIn { in_vs: vertices, out_v: result_id.into() }, }),
})); edge_data: lsif::EdgeDataMultiIn {
in_vs: vertices,
out_v: result_id.into(),
},
}));
}
} }
} }
} }