Rollup merge of #71724 - GuillaumeGomez:doc-alias-improvements, r=ollie27
Doc alias improvements After [this message](https://github.com/rust-lang/rust/issues/50146#issuecomment-496601755), I realized that the **doc alias**. So this PR does the followings: * Align the alias discovery on items added into the search-index. It brings a few nice advantages: * Instead of cloning the data between the two (in rustdoc source code), we now have the search-index one and aliases which reference to the first one. So we go from one big map containing a lot of duplicated data to just integers... * In the front-end (main.js), I improved the code around aliases to allow them to go through the same transformation as other items when we show the search results. * Improve the search tester in order to perform multiple requests into one file (I think it's better in this case than having a file for each case considering how many there are...) * I also had to add the new function inside the tester (`handleAliases`) Once this PR is merged, I intend to finally stabilize this feature. r? @ollie27 cc @rust-lang/rustdoc
This commit is contained in:
commit
154db50d86
9 changed files with 562 additions and 144 deletions
|
@ -293,7 +293,12 @@ impl Serialize for IndexItem {
|
|||
where
|
||||
S: Serializer,
|
||||
{
|
||||
assert_eq!(self.parent.is_some(), self.parent_idx.is_some());
|
||||
assert_eq!(
|
||||
self.parent.is_some(),
|
||||
self.parent_idx.is_some(),
|
||||
"`{}` is missing idx",
|
||||
self.name
|
||||
);
|
||||
|
||||
(self.ty, &self.name, &self.path, &self.desc, self.parent_idx, &self.search_type)
|
||||
.serialize(serializer)
|
||||
|
@ -819,42 +824,6 @@ themePicker.onblur = handleThemeButtonsBlur;
|
|||
Ok((ret, krates))
|
||||
}
|
||||
|
||||
fn show_item(item: &IndexItem, krate: &str) -> String {
|
||||
format!(
|
||||
"{{'crate':'{}','ty':{},'name':'{}','desc':'{}','p':'{}'{}}}",
|
||||
krate,
|
||||
item.ty as usize,
|
||||
item.name,
|
||||
item.desc.replace("'", "\\'"),
|
||||
item.path,
|
||||
if let Some(p) = item.parent_idx { format!(",'parent':{}", p) } else { String::new() }
|
||||
)
|
||||
}
|
||||
|
||||
let dst = cx.dst.join(&format!("aliases{}.js", cx.shared.resource_suffix));
|
||||
{
|
||||
let (mut all_aliases, _) = try_err!(collect(&dst, &krate.name, "ALIASES"), &dst);
|
||||
let mut output = String::with_capacity(100);
|
||||
for (alias, items) in &cx.cache.aliases {
|
||||
if items.is_empty() {
|
||||
continue;
|
||||
}
|
||||
output.push_str(&format!(
|
||||
"\"{}\":[{}],",
|
||||
alias,
|
||||
items.iter().map(|v| show_item(v, &krate.name)).collect::<Vec<_>>().join(",")
|
||||
));
|
||||
}
|
||||
all_aliases.push(format!("ALIASES[\"{}\"] = {{{}}};", krate.name, output));
|
||||
all_aliases.sort();
|
||||
let mut v = Buffer::html();
|
||||
writeln!(&mut v, "var ALIASES = {{}};");
|
||||
for aliases in &all_aliases {
|
||||
writeln!(&mut v, "{}", aliases);
|
||||
}
|
||||
cx.shared.fs.write(&dst, v.into_inner().into_bytes())?;
|
||||
}
|
||||
|
||||
use std::ffi::OsString;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue