rustdoc-search: fix description on aliases in results

This needs to start downloading the descriptions after aliases
have been added to the result set.
This commit is contained in:
Michael Howell 2024-04-18 22:20:08 -07:00
parent fa0068b541
commit 2e7d9e9acb
2 changed files with 16 additions and 11 deletions

View File

@ -1464,16 +1464,7 @@ function initSearch(rawSearchIndex) {
return 0; return 0;
}); });
const transformed = transformResults(result_list); return transformResults(result_list);
const descs = await Promise.all(transformed.map(result => {
return searchIndexEmptyDesc.get(result.crate).contains(result.bitIndex) ?
"" :
searchState.loadDesc(result);
}));
for (const [i, result] of transformed.entries()) {
result.desc = descs[i];
}
return transformed;
} }
/** /**
@ -2517,6 +2508,16 @@ function initSearch(rawSearchIndex) {
sorted_others, sorted_others,
parsedQuery); parsedQuery);
handleAliases(ret, parsedQuery.original.replace(/"/g, ""), filterCrates, currentCrate); handleAliases(ret, parsedQuery.original.replace(/"/g, ""), filterCrates, currentCrate);
await Promise.all([ret.others, ret.returned, ret.in_args].map(async list => {
const descs = await Promise.all(list.map(result => {
return searchIndexEmptyDesc.get(result.crate).contains(result.bitIndex) ?
"" :
searchState.loadDesc(result);
}));
for (const [i, result] of list.entries()) {
result.desc = descs[i];
}
}));
if (parsedQuery.error !== null && ret.others.length !== 0) { if (parsedQuery.error !== null && ret.others.length !== 0) {
// It means some doc aliases were found so let's "remove" the error! // It means some doc aliases were found so let's "remove" the error!
ret.query.error = null; ret.query.error = null;

View File

@ -1,6 +1,10 @@
const EXPECTED = { const EXPECTED = {
'query': '&', 'query': '&',
'others': [ 'others': [
{ 'path': 'std', 'name': 'reference' }, {
'path': 'std',
'name': 'reference',
'desc': "References, <code>&amp;T</code> and <code>&amp;mut T</code>.",
},
], ],
}; };