diff --git a/crates/rust-analyzer/src/cli/lsif.rs b/crates/rust-analyzer/src/cli/lsif.rs index b9bb335b05..5e6d286987 100644 --- a/crates/rust-analyzer/src/cli/lsif.rs +++ b/crates/rust-analyzer/src/cli/lsif.rs @@ -212,20 +212,30 @@ impl LsifManager<'_> { in_v: result_id.into(), out_v: result_set_id.into(), })); + let mut edges = token.references.iter().fold( + HashMap::<_, Vec>::new(), + |mut edges, x| { + let entry = + edges.entry((x.range.file_id, x.is_definition)).or_insert_with(Vec::new); + entry.push((*self.range_map.get(&x.range).unwrap()).into()); + edges + }, + ); for x in token.references { - let vertex = *self.range_map.get(&x.range).unwrap(); - self.add_edge(lsif::Edge::Item(lsif::Item { - document: (*self.file_map.get(&x.range.file_id).unwrap()).into(), - property: Some(if x.is_definition { - lsif::ItemKind::Definitions - } else { - lsif::ItemKind::References - }), - edge_data: lsif::EdgeDataMultiIn { - in_vs: vec![vertex.into()], - out_v: result_id.into(), - }, - })); + if let Some(vertices) = edges.remove(&(x.range.file_id, x.is_definition)) { + self.add_edge(lsif::Edge::Item(lsif::Item { + document: (*self.file_map.get(&x.range.file_id).unwrap()).into(), + property: Some(if x.is_definition { + lsif::ItemKind::Definitions + } else { + lsif::ItemKind::References + }), + edge_data: lsif::EdgeDataMultiIn { + in_vs: vertices, + out_v: result_id.into(), + }, + })); + } } } }