MCPcopy Index your code
hub / github.com/endbasic/endbasic / new

Method new

std/src/help.rs:312–358  ·  view source on GitHub ↗

Builds an index of the given `callables` and returns a new collection of help topics.

(callables: &HashMap<SymbolKey, Rc<CallableMetadata>>)

Source from the content-addressed store, hash-verified

310impl Topics {
311 /// Builds an index of the given `callables` and returns a new collection of help topics.
312 fn new(callables: &HashMap<SymbolKey, Rc<CallableMetadata>>) -> Self {
313 fn insert(topics: &mut Trie<String, Box<dyn Topic>>, topic: Box<dyn Topic>) {
314 let key = topic.name().to_ascii_uppercase();
315 topics.insert(key, topic);
316 }
317
318 let mut topics = Trie::default();
319
320 {
321 let mut index = BTreeMap::default();
322
323 for (title, content) in parse_lang_reference(LANG_MD) {
324 let topic = LanguageTopic { name: title, text: content };
325 index.insert(topic.name.to_owned(), topic.text.lines().next().unwrap());
326 insert(&mut topics, Box::from(topic));
327 }
328
329 insert(
330 &mut topics,
331 Box::from(CategoryTopic {
332 name: "Language reference",
333 description: "General language topics",
334 index,
335 }),
336 );
337 }
338
339 let mut categories = HashMap::new();
340 for metadata in callables.values() {
341 let category_title = metadata.category().lines().next().unwrap();
342 categories.entry(category_title).or_insert_with(Vec::default).push(metadata.clone());
343
344 let name = match metadata.return_type() {
345 None => metadata.name().to_owned(),
346 Some(return_type) => format!("{}{}", metadata.name(), return_type.annotation()),
347 };
348
349 insert(&mut topics, Box::from(CallableTopic { name, metadata: metadata.clone() }));
350 }
351 for (name, metadatas) in categories.into_iter() {
352 let description = metadatas.first().expect("Must have at least one symbol").category();
353 let index = callables_to_index(&metadatas);
354 insert(&mut topics, Box::from(CategoryTopic { name, description, index }));
355 }
356
357 Self(topics)
358 }
359
360 /// Returns the given topic named `name`, where `name` can be a prefix.
361 ///

Callers

nothing calls this directly

Calls 15

parse_lang_referenceFunction · 0.85
callables_to_indexFunction · 0.85
valuesMethod · 0.80
categoryMethod · 0.80
pushMethod · 0.80
return_typeMethod · 0.80
firstMethod · 0.80
with_descriptionMethod · 0.80
with_categoryMethod · 0.80
with_syntaxMethod · 0.80
with_asyncMethod · 0.80
insertMethod · 0.45

Tested by

no test coverage detected