Skip to content

Commit 714be45

Browse files
committed
search.js: refactor transformResults
1 parent 8af647c commit 714be45

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

src/librustdoc/html/static/js/rustdoc.d.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,20 @@ declare namespace rustdoc {
257257
ty: number,
258258
type?: FunctionSearchType,
259259
paramNames?: string[],
260-
displayType: Promise<Array<Array<string>>>|null,
261-
displayTypeMappedNames: Promise<Array<[string, Array<string>]>>|null,
260+
displayTypeSignature: Promise<rustdoc.DisplayTypeSignature> | null,
262261
item: Row,
263262
dontValidate?: boolean,
264263
}
265264

265+
/**
266+
* output of `formatDisplayTypeSignature`
267+
*/
268+
interface DisplayTypeSignature {
269+
type: Array<string>,
270+
mappedNames: Map<string, string>,
271+
whereClause: Map<string, Array<string>>,
272+
}
273+
266274
/**
267275
* A pair of [inputs, outputs], or 0 for null. This is stored in the search index.
268276
* The JavaScript deserializes this into FunctionSearchType.

src/librustdoc/html/static/js/search.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2777,15 +2777,28 @@ class DocSearch {
27772777
for (const result of results) {
27782778
if (result.id !== -1) {
27792779
const res = buildHrefAndPath(this.searchIndex[result.id]);
2780+
// many of these properties don't strictly need to be
2781+
// copied over, but copying them over satisfies tsc,
2782+
// and hopefully plays nice with the shape optimization
2783+
// of the browser engine.
2784+
/** @type {rustdoc.ResultObject} */
27802785
const obj = Object.assign({
2786+
parent: result.parent,
2787+
type: result.type,
27812788
dist: result.dist,
2789+
path_dist: result.path_dist,
2790+
index: result.index,
2791+
desc: result.desc,
2792+
item: result.item,
27822793
displayPath: pathSplitter(res[0]),
2794+
fullPath: "",
2795+
href: "",
2796+
displayTypeSignature: null,
27832797
}, this.searchIndex[result.id]);
27842798

27852799
// To be sure than it some items aren't considered as duplicate.
2786-
// @ts-expect-error
2787-
obj.fullPath = res[2] + "|" + obj.ty;
2788-
// @ts-expect-error
2800+
obj.fullPath = res[2] + "|" + obj.ty
2801+
27892802
if (duplicates.has(obj.fullPath)) {
27902803
continue;
27912804
}
@@ -2798,26 +2811,22 @@ class DocSearch {
27982811
if (duplicates.has(res[2] + "|" + TY_IMPORT)) {
27992812
continue;
28002813
}
2801-
// @ts-expect-error
28022814
duplicates.add(obj.fullPath);
28032815
duplicates.add(res[2]);
28042816

28052817
if (typeInfo !== null) {
2806-
// @ts-expect-error
28072818
obj.displayTypeSignature =
28082819
// @ts-expect-error
28092820
this.formatDisplayTypeSignature(obj, typeInfo);
28102821
}
28112822

2812-
// @ts-expect-error
28132823
obj.href = res[1];
28142824
out.push(obj);
28152825
if (out.length >= MAX_RESULTS) {
28162826
break;
28172827
}
28182828
}
28192829
}
2820-
// @ts-expect-error
28212830
return out;
28222831
};
28232832

@@ -2830,11 +2839,7 @@ class DocSearch {
28302839
*
28312840
* @param {rustdoc.ResultObject} obj
28322841
* @param {"sig"|"elems"|"returned"|null} typeInfo
2833-
* @returns {Promise<{
2834-
* "type": Array<string>,
2835-
* "mappedNames": Map<string, string>,
2836-
* "whereClause": Map<string, Array<string>>,
2837-
* }>}
2842+
* @returns {Promise<rustdoc.DisplayTypeSignature>}
28382843
*/
28392844
this.formatDisplayTypeSignature = async(obj, typeInfo) => {
28402845
const objType = obj.type;

0 commit comments

Comments
 (0)