11793: LSIF: consolidate references into a single edge where possible. r=Veykril a=khuey



Co-authored-by: Kyle Huey <khuey@kylehuey.com>
This commit is contained in:
bors[bot] 2022-03-25 22:46:15 +00:00 committed by GitHub
commit e30747dfa8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -212,20 +212,30 @@ fn add_token(&mut self, id: TokenId, token: TokenStaticData) {
in_v: result_id.into(),
out_v: result_set_id.into(),
}));
let mut edges = token.references.iter().fold(
HashMap::<_, Vec<lsp_types::NumberOrString>>::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(),
},
}));
}
}
}
}