rustdoc: emit JS paths for struct-like variants
On the backend, rustdoc now emits `paths` entries to a crate's search index for struct-like enum variants, and index items of type structfield which belong to such variants point to their variant parents in the `paths` table, rather than their enum grandparents. The path entry for a variant is the fully qualified module path plus the enum name. On the frontend, the search code recognizes structfields belonging to structlike variants in the `paths` table and re-constructs the URL to the field's anchor on the enum documentation page. closes #16017
This commit is contained in:
parent
b60f08bd6d
commit
05c6f329e7
1 changed files with 22 additions and 8 deletions
|
@ -1364,14 +1364,15 @@ function getSearchElement() {
|
||||||
var href;
|
var href;
|
||||||
var type = itemTypes[item.ty];
|
var type = itemTypes[item.ty];
|
||||||
var name = item.name;
|
var name = item.name;
|
||||||
|
var path = item.path;
|
||||||
|
|
||||||
if (type === "mod") {
|
if (type === "mod") {
|
||||||
displayPath = item.path + "::";
|
displayPath = path + "::";
|
||||||
href = rootPath + item.path.replace(/::/g, "/") + "/" +
|
href = rootPath + path.replace(/::/g, "/") + "/" +
|
||||||
name + "/index.html";
|
name + "/index.html";
|
||||||
} else if (type === "primitive" || type === "keyword") {
|
} else if (type === "primitive" || type === "keyword") {
|
||||||
displayPath = "";
|
displayPath = "";
|
||||||
href = rootPath + item.path.replace(/::/g, "/") +
|
href = rootPath + path.replace(/::/g, "/") +
|
||||||
"/" + type + "." + name + ".html";
|
"/" + type + "." + name + ".html";
|
||||||
} else if (type === "externcrate") {
|
} else if (type === "externcrate") {
|
||||||
displayPath = "";
|
displayPath = "";
|
||||||
|
@ -1380,14 +1381,27 @@ function getSearchElement() {
|
||||||
var myparent = item.parent;
|
var myparent = item.parent;
|
||||||
var anchor = "#" + type + "." + name;
|
var anchor = "#" + type + "." + name;
|
||||||
var parentType = itemTypes[myparent.ty];
|
var parentType = itemTypes[myparent.ty];
|
||||||
|
var pageType = parentType;
|
||||||
|
var pageName = myparent.name;
|
||||||
|
|
||||||
if (parentType === "primitive") {
|
if (parentType === "primitive") {
|
||||||
displayPath = myparent.name + "::";
|
displayPath = myparent.name + "::";
|
||||||
|
} else if (type === "structfield" && parentType === "variant") {
|
||||||
|
// Structfields belonging to variants are special: the
|
||||||
|
// final path element is the enum name.
|
||||||
|
var splitPath = item.path.split("::");
|
||||||
|
var enumName = splitPath.pop();
|
||||||
|
path = splitPath.join("::");
|
||||||
|
displayPath = path + "::" + enumName + "::" + myparent.name + "::";
|
||||||
|
anchor = "#variant." + myparent.name + ".field." + name;
|
||||||
|
pageType = "enum";
|
||||||
|
pageName = enumName;
|
||||||
} else {
|
} else {
|
||||||
displayPath = item.path + "::" + myparent.name + "::";
|
displayPath = path + "::" + myparent.name + "::";
|
||||||
}
|
}
|
||||||
href = rootPath + item.path.replace(/::/g, "/") +
|
href = rootPath + path.replace(/::/g, "/") +
|
||||||
"/" + parentType +
|
"/" + pageType +
|
||||||
"." + myparent.name +
|
"." + pageName +
|
||||||
".html" + anchor;
|
".html" + anchor;
|
||||||
} else {
|
} else {
|
||||||
displayPath = item.path + "::";
|
displayPath = item.path + "::";
|
||||||
|
@ -1668,7 +1682,7 @@ function getSearchElement() {
|
||||||
// (String) name]
|
// (String) name]
|
||||||
var paths = rawSearchIndex[crate].p;
|
var paths = rawSearchIndex[crate].p;
|
||||||
|
|
||||||
// convert `paths` into an object form
|
// convert `rawPaths` entries into object form
|
||||||
var len = paths.length;
|
var len = paths.length;
|
||||||
for (i = 0; i < len; ++i) {
|
for (i = 0; i < len; ++i) {
|
||||||
paths[i] = {ty: paths[i][0], name: paths[i][1]};
|
paths[i] = {ty: paths[i][0], name: paths[i][1]};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue