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.
This commit is contained in:
Robin Krahl 2020-08-18 21:26:39 +02:00
parent 8e97ad269b
commit c672a65d59
No known key found for this signature in database
GPG Key ID: 8E9B0870524F69D8
2 changed files with 10 additions and 2 deletions

View File

@ -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

View File

@ -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(),
});
}