Skip to content

Commit 741d210

Browse files
Add search result item types after their name
1 parent fabf929 commit 741d210

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

src/librustdoc/html/static/css/rustdoc.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ a.anchor,
213213
h1 a,
214214
.search-results a,
215215
.stab,
216-
.result-name .primitive > i, .result-name .keyword > i {
216+
.result-name i {
217217
color: var(--main-color);
218218
}
219219

@@ -887,7 +887,7 @@ so that we can apply CSS-filters to change the arrow color in themes */
887887
.search-results .result-name span.alias {
888888
color: var(--search-results-alias-color);
889889
}
890-
.search-results .result-name span.grey {
890+
.search-results .result-name .grey {
891891
color: var(--search-results-grey-color);
892892
}
893893

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

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,35 @@ const itemTypes = [
3535
"traitalias",
3636
];
3737

38+
const longItemTypes = [
39+
"module",
40+
"extern crate",
41+
"re-export",
42+
"struct",
43+
"enum",
44+
"function",
45+
"type alias",
46+
"static",
47+
"trait",
48+
"",
49+
"trait method",
50+
"method",
51+
"struct field",
52+
"enum variant",
53+
"macro",
54+
"primitive type",
55+
"associated type",
56+
"constant",
57+
"associated constant",
58+
"union",
59+
"foreign type",
60+
"keyword",
61+
"existential type",
62+
"attribute macro",
63+
"derive macro",
64+
"trait alias",
65+
];
66+
3867
// used for special search precedence
3968
const TY_PRIMITIVE = itemTypes.indexOf("primitive");
4069
const TY_KEYWORD = itemTypes.indexOf("keyword");
@@ -1836,16 +1865,11 @@ function initSearch(rawSearchIndex) {
18361865
array.forEach(item => {
18371866
const name = item.name;
18381867
const type = itemTypes[item.ty];
1868+
const longType = longItemTypes[item.ty];
1869+
let extra = longType.length !== 0 ? ` <i>(${longType})</i>` : "";
18391870

18401871
length += 1;
18411872

1842-
let extra = "";
1843-
if (type === "primitive") {
1844-
extra = " <i>(primitive type)</i>";
1845-
} else if (type === "keyword") {
1846-
extra = " <i>(keyword)</i>";
1847-
}
1848-
18491873
const link = document.createElement("a");
18501874
link.className = "result-" + type;
18511875
link.href = item.href;
@@ -1854,6 +1878,7 @@ function initSearch(rawSearchIndex) {
18541878
resultName.className = "result-name";
18551879

18561880
if (item.is_alias) {
1881+
extra = "";
18571882
const alias = document.createElement("span");
18581883
alias.className = "alias";
18591884

@@ -1863,13 +1888,13 @@ function initSearch(rawSearchIndex) {
18631888

18641889
alias.insertAdjacentHTML(
18651890
"beforeend",
1866-
"<span class=\"grey\"><i>&nbsp;- see&nbsp;</i></span>");
1891+
"<i class=\"grey\">&nbsp;- see&nbsp;</i>");
18671892

18681893
resultName.appendChild(alias);
18691894
}
18701895
resultName.insertAdjacentHTML(
18711896
"beforeend",
1872-
item.displayPath + "<span class=\"" + type + "\">" + name + extra + "</span>");
1897+
item.displayPath + "<span class=\"" + type + "\">" + name + "</span>" + extra);
18731898
link.appendChild(resultName);
18741899

18751900
const description = document.createElement("div");

0 commit comments

Comments
 (0)