Also match patch in Index::find
Previously, we only compared the type names when searching for matches in the search index. With this patch, we also check the path: If the full name of the item ends with the keyword (prepended with :: to avoid partial matches), we return a match.
This commit is contained in:
parent
61fdf31c0a
commit
bd71f41458
15
src/index.rs
15
src/index.rs
@ -106,17 +106,20 @@ impl Index {
|
||||
}
|
||||
|
||||
pub fn find(&self, keyword: &str) -> Vec<IndexItem> {
|
||||
let keyword = format!("::{}", keyword);
|
||||
let mut matches: Vec<IndexItem> = Vec::new();
|
||||
for (krate, data) in &self.data.crates {
|
||||
for item in &data.items {
|
||||
if item.name == keyword {
|
||||
let path = if item.path.is_empty() {
|
||||
krate
|
||||
} else {
|
||||
&item.path
|
||||
};
|
||||
let full_name = format!("{}::{}", path, &item.name);
|
||||
if full_name.ends_with(&keyword) {
|
||||
matches.push(IndexItem {
|
||||
name: item.name.clone(),
|
||||
path: if item.path.is_empty() {
|
||||
krate.to_owned()
|
||||
} else {
|
||||
item.path.clone()
|
||||
},
|
||||
path: path.to_owned(),
|
||||
description: item.desc.clone(),
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user