From c672a65d59876a3fbc353315f6d351676e5ce290 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 18 Aug 2020 21:26:39 +0200 Subject: [PATCH] Add item type to the IndexItem struct Previously, we only used the name and the description to represent index items. Therefore we consider e. g. the std::u8 module and the std::u8 primitive to be the same. With this patch, we also take the item type into account when comparing index items. --- CHANGELOG.md | 6 ++++++ src/index.rs | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d35c83..40d993d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ SPDX-License-Identifier: MIT # Changelog for rusty-man +## Unreleased + +- Improve handling of different items with same name: + - Add the item type to the item list if multiple matches are found in the + search index. + ## v0.2.0 (2020-08-11) This minor release adds support for syntax highlighting of code snippets and diff --git a/src/index.rs b/src/index.rs index 2d896e2..9544cfe 100644 --- a/src/index.rs +++ b/src/index.rs @@ -31,15 +31,16 @@ pub struct Index { #[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)] pub struct IndexItem { pub name: doc::Fqn, + pub ty: doc::ItemType, pub description: String, } impl fmt::Display for IndexItem { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if self.description.is_empty() { - write!(f, "{}", &self.name) + write!(f, "{} ({})", &self.name, self.ty.name()) } else { - write!(f, "{}: {}", &self.name, &self.description) + write!(f, "{} ({}): {}", &self.name, self.ty.name(), &self.description) } } } @@ -194,6 +195,7 @@ impl Index { log::info!("Found index match '{}'", full_name); matches.push(IndexItem { name: full_name, + ty: item.ty, description: item.desc.clone(), }); }