From 2e7d9e9acbdb48620e347529796bf1e35fd97c19 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Thu, 18 Apr 2024 22:20:08 -0700 Subject: [PATCH] rustdoc-search: fix description on aliases in results This needs to start downloading the descriptions after aliases have been added to the result set. --- src/librustdoc/html/static/js/search.js | 21 +++++++++++---------- tests/rustdoc-js-std/alias-1.js | 6 +++++- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 0a43e9765e2b9..41a9897de6dfb 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -1464,16 +1464,7 @@ function initSearch(rawSearchIndex) { return 0; }); - const transformed = 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; + return transformResults(result_list); } /** @@ -2517,6 +2508,16 @@ function initSearch(rawSearchIndex) { sorted_others, parsedQuery); 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) { // It means some doc aliases were found so let's "remove" the error! ret.query.error = null; diff --git a/tests/rustdoc-js-std/alias-1.js b/tests/rustdoc-js-std/alias-1.js index b27b3da217966..c31d1a3b1ad7d 100644 --- a/tests/rustdoc-js-std/alias-1.js +++ b/tests/rustdoc-js-std/alias-1.js @@ -1,6 +1,10 @@ const EXPECTED = { 'query': '&', 'others': [ - { 'path': 'std', 'name': 'reference' }, + { + 'path': 'std', + 'name': 'reference', + 'desc': "References, &T and &mut T.", + }, ], };