Skip to content

Commit 03b0856

Browse files
Add aliases in the search as well
1 parent 57bcabc commit 03b0856

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/librustdoc/html/render.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -873,9 +873,13 @@ themePicker.onclick = function() {{
873873
}
874874

875875
fn show_item(item: &IndexItem, krate: &str) -> String {
876-
format!("{{'crate':'{}','ty':'{}','name':'{}','path':'{}','parent':{}}}",
877-
krate, item.ty, item.name, item.path,
878-
if let Some(p) = item.parent_idx { p.to_string() } else { "null".to_owned() })
876+
format!("{{'crate':'{}','ty':{},'name':'{}','path':'{}'{}}}",
877+
krate, item.ty as usize, item.name, item.path,
878+
if let Some(p) = item.parent_idx {
879+
format!(",'parent':{}", p)
880+
} else {
881+
String::new()
882+
})
879883
}
880884

881885
let dst = cx.dst.join("aliases.js");

src/librustdoc/html/static/main.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,11 +1012,21 @@
10121012
}
10131013
}
10141014

1015-
return {
1015+
var ret = {
10161016
'in_args': sortResults(results_in_args, true),
10171017
'returned': sortResults(results_returned, true),
10181018
'others': sortResults(results),
10191019
};
1020+
if (ALIASES[window.currentCrate][query.raw]) {
1021+
var aliases = ALIASES[window.currentCrate][query.raw];
1022+
for (var i = 0; i < aliases.length; ++i) {
1023+
ret['others'].unshift(aliases[i]);
1024+
if (ret['others'].length > MAX_RESULTS) {
1025+
ret['others'].pop();
1026+
}
1027+
}
1028+
}
1029+
return ret;
10201030
}
10211031

10221032
/**
@@ -1202,11 +1212,11 @@
12021212
array.forEach(function(item) {
12031213
var name, type, href, displayPath;
12041214

1205-
if (shown.indexOf(item) !== -1) {
1215+
if (shown.indexOf(item.ty) !== -1) {
12061216
return;
12071217
}
12081218

1209-
shown.push(item);
1219+
shown.push(item.ty);
12101220
name = item.name;
12111221
type = itemTypes[item.ty];
12121222

0 commit comments

Comments
 (0)