in src/utilities/tree_sitter_utilities.rs [130:155]
fn accumulate_repeated_tags(
query: &Query, query_matches: Vec<Vec<tree_sitter::QueryCapture>>, source_code: &str,
) -> HashMap<String, String> {
let mut code_snippet_by_tag: HashMap<String, String> = HashMap::new();
let tag_names_by_index: HashMap<usize, &String> =
query.capture_names().iter().enumerate().collect();
// Iterate over each tag name in the query
for tag_name in query.capture_names().iter() {
// Iterate over each query match for this range of code snippet
for captures in query_matches.clone() {
// Iterate over each capture
for capture in captures {
if tag_names_by_index[&(capture.index as usize)].eq(tag_name) {
let code_snippet = &capture.node.utf8_text(source_code.as_bytes()).unwrap();
code_snippet_by_tag
.entry(tag_name.clone())
.and_modify(|x| x.push_str(format!("\n{code_snippet}").as_str()))
.or_insert_with(|| code_snippet.to_string());
}
}
}
// If tag name did not match a code snippet, add an empty string.
code_snippet_by_tag.entry(tag_name.clone()).or_default();
}
code_snippet_by_tag
}