Add search result item types after their name
This commit is contained in:
parent
fabf929863
commit
741d210c44
2 changed files with 36 additions and 11 deletions
|
@ -35,6 +35,35 @@ const itemTypes = [
|
|||
"traitalias",
|
||||
];
|
||||
|
||||
const longItemTypes = [
|
||||
"module",
|
||||
"extern crate",
|
||||
"re-export",
|
||||
"struct",
|
||||
"enum",
|
||||
"function",
|
||||
"type alias",
|
||||
"static",
|
||||
"trait",
|
||||
"",
|
||||
"trait method",
|
||||
"method",
|
||||
"struct field",
|
||||
"enum variant",
|
||||
"macro",
|
||||
"primitive type",
|
||||
"associated type",
|
||||
"constant",
|
||||
"associated constant",
|
||||
"union",
|
||||
"foreign type",
|
||||
"keyword",
|
||||
"existential type",
|
||||
"attribute macro",
|
||||
"derive macro",
|
||||
"trait alias",
|
||||
];
|
||||
|
||||
// used for special search precedence
|
||||
const TY_PRIMITIVE = itemTypes.indexOf("primitive");
|
||||
const TY_KEYWORD = itemTypes.indexOf("keyword");
|
||||
|
@ -1836,16 +1865,11 @@ function initSearch(rawSearchIndex) {
|
|||
array.forEach(item => {
|
||||
const name = item.name;
|
||||
const type = itemTypes[item.ty];
|
||||
const longType = longItemTypes[item.ty];
|
||||
let extra = longType.length !== 0 ? ` <i>(${longType})</i>` : "";
|
||||
|
||||
length += 1;
|
||||
|
||||
let extra = "";
|
||||
if (type === "primitive") {
|
||||
extra = " <i>(primitive type)</i>";
|
||||
} else if (type === "keyword") {
|
||||
extra = " <i>(keyword)</i>";
|
||||
}
|
||||
|
||||
const link = document.createElement("a");
|
||||
link.className = "result-" + type;
|
||||
link.href = item.href;
|
||||
|
@ -1854,6 +1878,7 @@ function initSearch(rawSearchIndex) {
|
|||
resultName.className = "result-name";
|
||||
|
||||
if (item.is_alias) {
|
||||
extra = "";
|
||||
const alias = document.createElement("span");
|
||||
alias.className = "alias";
|
||||
|
||||
|
@ -1863,13 +1888,13 @@ function initSearch(rawSearchIndex) {
|
|||
|
||||
alias.insertAdjacentHTML(
|
||||
"beforeend",
|
||||
"<span class=\"grey\"><i> - see </i></span>");
|
||||
"<i class=\"grey\"> - see </i>");
|
||||
|
||||
resultName.appendChild(alias);
|
||||
}
|
||||
resultName.insertAdjacentHTML(
|
||||
"beforeend",
|
||||
item.displayPath + "<span class=\"" + type + "\">" + name + extra + "</span>");
|
||||
item.displayPath + "<span class=\"" + type + "\">" + name + "</span>" + extra);
|
||||
link.appendChild(resultName);
|
||||
|
||||
const description = document.createElement("div");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue