#![allow(dead_code)]
use crate::components::language::Lang;
use std::collections::HashMap;
pub fn build_doc_map(lang: &Lang) -> HashMap<usize, String> {
let mut map = HashMap::new();
collect_docs(lang, &mut map);
map
}
pub fn build_doc_map_from_slice(items: &[Lang]) -> HashMap<usize, String> {
let mut map = HashMap::new();
attach_from_slice(items, &mut map);
for item in items {
collect_docs(item, &mut map);
}
map
}
fn collect_docs(lang: &Lang, map: &mut HashMap<usize, String>) {
match lang {
Lang::Lines { value, .. } => {
attach_from_slice(value, map);
for item in value {
collect_docs(item, map);
}
}
Lang::Module { body, .. } => {
attach_from_slice(body, map);
for item in body {
collect_docs(item, map);
}
}
_ => {}
}
}
fn attach_from_slice(items: &[Lang], map: &mut HashMap<usize, String>) {
let mut pending: Vec<String> = Vec::new();
for item in items {
match item {
Lang::Comment { value, .. } => {
pending.push(value.trim().to_string());
}
other => {
if !pending.is_empty() {
let doc = pending.join("\n");
let offset = other.get_help_data().get_offset();
map.insert(offset, doc);
pending.clear();
}
}
}
}
}