From 66517799a0962d614ca5747ffc9a9a9503ec9782 Mon Sep 17 00:00:00 2001 From: HJfod <60038575+HJfod@users.noreply.github.com> Date: Sun, 19 Feb 2023 19:02:55 +0200 Subject: [PATCH] remove overloads from member functions list and just show their count --- src/builder/builder.rs | 3 +++ src/builder/traits.rs | 22 +++++++++++++++------- templates/script.js | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/builder/builder.rs b/src/builder/builder.rs index 0f9e536..3331085 100644 --- a/src/builder/builder.rs +++ b/src/builder/builder.rs @@ -267,6 +267,9 @@ impl<'e> Builder<'e> { &self.config.output_dir.join("functions.json"), serde_json::to_string( &self.root.nav().suboptions_titles(self.config.clone()) + .into_iter() + .map(|(n, c)| if c > 0 { format!("{} ({})", n, c + 1) } else { n }) + .collect::>() ).map_err(|e| format!("Unable to save metadata {e}"))? ).map_err(|e| format!("Unable to save metadata {e}"))?; diff --git a/src/builder/traits.rs b/src/builder/traits.rs index 02bc54f..b94e714 100644 --- a/src/builder/traits.rs +++ b/src/builder/traits.rs @@ -1,6 +1,6 @@ use clang::{Entity, EntityKind, Accessibility}; -use std::{path::PathBuf, sync::Arc}; +use std::{path::PathBuf, sync::Arc, collections::HashMap}; use tokio::task::JoinHandle; @@ -205,17 +205,25 @@ impl NavItem { NavItem::Root(name.map(|s| s.into()), items) } - pub fn suboptions_titles(&self, config: Arc) -> Vec { + pub fn suboptions_titles(&self, config: Arc) -> HashMap { match self { - NavItem::Link(name, _, _, suboptions) => suboptions.clone() - .into_iter() - .map(|o| format!("{}::{}", name, o.title)) - .collect(), + NavItem::Link(name, _, _, suboptions) => { + let mut res = HashMap::new(); + for opt in suboptions.iter().map(|o| format!("{}::{}", name, o.title)) { + if let Some(r) = res.get_mut(&opt) { + *r += 1; + } + else { + res.insert(opt, 0); + } + } + res + }, NavItem::Dir(name, items, _, _) => items.iter() .flat_map(|i| i.suboptions_titles(config.clone())) .into_iter() - .map(|t| format!("{}::{}", name, t)) + .map(|(t, count)| (format!("{}::{}", name, t), count)) .collect(), NavItem::Root(_, items) => items.iter() diff --git a/templates/script.js b/templates/script.js index 51906a9..78d5a61 100644 --- a/templates/script.js +++ b/templates/script.js @@ -293,7 +293,7 @@ function updateNav() { const match = furryMatchMany([name], searchQuery, '::'); if (match) { const node = document.createElement('a'); - const url = `${FLASH_OUTPUT_URL}/classes/${f.join('/')}#${name}`; + const url = `${FLASH_OUTPUT_URL}/classes/${f.join('/')}#${name.replace(/\s+\([0-9]+\)/, '')}`; node.setAttribute('href', url); node.addEventListener('click', e => { navigate(url);