Make current crate aliases go first

This commit is contained in:
Guillaume Gomez 2020-05-07 21:42:41 +02:00
parent 883c177abb
commit c4d9318be6
5 changed files with 67 additions and 34 deletions

View File

@ -978,7 +978,10 @@ function getSearchElement() {
}
function handleAliases(ret, query, filterCrates) {
// We separate aliases and crate aliases because we want to have current crate
// aliases to be before the others in the displayed results.
var aliases = [];
var crateAliases = [];
var i;
if (filterCrates !== undefined &&
ALIASES[filterCrates] &&
@ -990,25 +993,28 @@ function getSearchElement() {
} else {
Object.keys(ALIASES).forEach(function(crate) {
if (ALIASES[crate][query.search]) {
var pushTo = crate === window.currentCrate ? crateAliases : aliases;
for (i = 0; i < ALIASES[crate][query.search].length; ++i) {
aliases.push(
pushTo.push(
createAliasFromItem(
searchIndex[ALIASES[crate][query.search][i]]));
}
}
});
}
aliases.sort(function(aaa, bbb) {
var sortFunc = function(aaa, bbb) {
if (aaa.path < bbb.path) {
return 1;
} else if (aaa.path === bbb.path) {
return 0;
}
return -1;
});
for (i = 0; i < aliases.length; ++i) {
var alias = aliases[i];
};
crateAliases.sort(sortFunc);
aliases.sort(sortFunc);
var pushFunc = function(alias) {
alias.alias = query.raw;
var res = buildHrefAndPath(alias);
alias.displayPath = pathSplitter(res[0]);
@ -1019,7 +1025,9 @@ function getSearchElement() {
if (ret.others.length > MAX_RESULTS) {
ret.others.pop();
}
}
};
onEach(aliases, pushFunc);
onEach(crateAliases, pushFunc);
}
// quoted values mean literal search

View File

@ -1,12 +1,10 @@
// ignore-order
const QUERY = '+';
const EXPECTED = {
'others': [
{ 'path': 'core::ops', 'name': 'AddAssign' },
{ 'path': 'core::ops', 'name': 'Add' },
{ 'path': 'std::ops', 'name': 'AddAssign' },
{ 'path': 'std::ops', 'name': 'Add' },
{ 'path': 'core::ops', 'name': 'AddAssign' },
{ 'path': 'core::ops', 'name': 'Add' },
],
};

View File

@ -32,7 +32,8 @@ const EXPECTED = [
'path': 'doc_alias',
'name': 'Struct',
'alias': 'StructItem',
'href': '../doc_alias/struct.Struct.html'
'href': '../doc_alias/struct.Struct.html',
'is_alias': true
},
],
},
@ -42,7 +43,8 @@ const EXPECTED = [
'path': 'doc_alias::Struct',
'name': 'field',
'alias': 'StructFieldItem',
'href': '../doc_alias/struct.Struct.html#structfield.field'
'href': '../doc_alias/struct.Struct.html#structfield.field',
'is_alias': true
},
],
},
@ -52,7 +54,8 @@ const EXPECTED = [
'path': 'doc_alias::Struct',
'name': 'method',
'alias': 'StructMethodItem',
'href': '../doc_alias/struct.Struct.html#method.method'
'href': '../doc_alias/struct.Struct.html#method.method',
'is_alias': true
},
],
},
@ -65,8 +68,15 @@ const EXPECTED = [
'others': [],
},
{
// ImplTraitFunction
'others': [],
'others': [
{
'path': 'doc_alias::Struct',
'name': 'function',
'alias': 'ImplTraitFunction',
'href': '../doc_alias/struct.Struct.html#method.function',
'is_alias': true
},
],
},
{
'others': [
@ -74,7 +84,8 @@ const EXPECTED = [
'path': 'doc_alias',
'name': 'Enum',
'alias': 'EnumItem',
'href': '../doc_alias/enum.Enum.html'
'href': '../doc_alias/enum.Enum.html',
'is_alias': true
},
],
},
@ -84,7 +95,8 @@ const EXPECTED = [
'path': 'doc_alias::Enum',
'name': 'Variant',
'alias': 'VariantItem',
'href': '../doc_alias/enum.Enum.html#variant.Variant'
'href': '../doc_alias/enum.Enum.html#variant.Variant',
'is_alias': true
},
],
},
@ -94,7 +106,8 @@ const EXPECTED = [
'path': 'doc_alias::Enum',
'name': 'method',
'alias': 'EnumMethodItem',
'href': '../doc_alias/enum.Enum.html#method.method'
'href': '../doc_alias/enum.Enum.html#method.method',
'is_alias': true
},
],
},
@ -104,7 +117,8 @@ const EXPECTED = [
'path': 'doc_alias',
'name': 'Typedef',
'alias': 'TypedefItem',
'href': '../doc_alias/type.Typedef.html'
'href': '../doc_alias/type.Typedef.html',
'is_alias': true
},
],
},
@ -114,7 +128,8 @@ const EXPECTED = [
'path': 'doc_alias',
'name': 'Trait',
'alias': 'TraitItem',
'href': '../doc_alias/trait.Trait.html'
'href': '../doc_alias/trait.Trait.html',
'is_alias': true
},
],
},
@ -124,7 +139,8 @@ const EXPECTED = [
'path': 'doc_alias::Trait',
'name': 'Target',
'alias': 'TraitTypeItem',
'href': '../doc_alias/trait.Trait.html#associatedtype.Target'
'href': '../doc_alias/trait.Trait.html#associatedtype.Target',
'is_alias': true
},
],
},
@ -134,7 +150,8 @@ const EXPECTED = [
'path': 'doc_alias::Trait',
'name': 'AssociatedConst',
'alias': 'AssociatedConstItem',
'href': '../doc_alias/trait.Trait.html#associatedconstant.AssociatedConst'
'href': '../doc_alias/trait.Trait.html#associatedconstant.AssociatedConst',
'is_alias': true
},
],
},
@ -144,7 +161,8 @@ const EXPECTED = [
'path': 'doc_alias::Trait',
'name': 'function',
'alias': 'TraitFunctionItem',
'href': '../doc_alias/trait.Trait.html#tymethod.function'
'href': '../doc_alias/trait.Trait.html#tymethod.function',
'is_alias': true
},
],
},
@ -154,7 +172,8 @@ const EXPECTED = [
'path': 'doc_alias',
'name': 'function',
'alias': 'FunctionItem',
'href': '../doc_alias/fn.function.html'
'href': '../doc_alias/fn.function.html',
'is_alias': true
},
],
},
@ -164,7 +183,8 @@ const EXPECTED = [
'path': 'doc_alias',
'name': 'Module',
'alias': 'ModuleItem',
'href': '../doc_alias/Module/index.html'
'href': '../doc_alias/Module/index.html',
'is_alias': true
},
],
},
@ -174,7 +194,8 @@ const EXPECTED = [
'path': 'doc_alias',
'name': 'Const',
'alias': 'ConstItem',
'href': '../doc_alias/constant.Const.html'
'href': '../doc_alias/constant.Const.html',
'is_alias': true
},
],
},
@ -184,7 +205,8 @@ const EXPECTED = [
'path': 'doc_alias',
'name': 'Static',
'alias': 'StaticItem',
'href': '../doc_alias/static.Static.html'
'href': '../doc_alias/static.Static.html',
'is_alias': true
},
],
},
@ -194,7 +216,8 @@ const EXPECTED = [
'path': 'doc_alias',
'name': 'Union',
'alias': 'UnionItem',
'href': '../doc_alias/union.Union.html'
'href': '../doc_alias/union.Union.html',
'is_alias': true
},
// Not an alias!
{
@ -210,7 +233,8 @@ const EXPECTED = [
'path': 'doc_alias::Union',
'name': 'union_item',
'alias': 'UnionFieldItem',
'href': '../doc_alias/union.Union.html#structfield.union_item'
'href': '../doc_alias/union.Union.html#structfield.union_item',
'is_alias': true
},
],
},
@ -220,7 +244,8 @@ const EXPECTED = [
'path': 'doc_alias::Union',
'name': 'method',
'alias': 'UnionMethodItem',
'href': '../doc_alias/union.Union.html#method.method'
'href': '../doc_alias/union.Union.html#method.method',
'is_alias': true
},
],
},
@ -230,7 +255,8 @@ const EXPECTED = [
'path': 'doc_alias',
'name': 'Macro',
'alias': 'MacroItem',
'href': '../doc_alias/macro.Macro.html'
'href': '../doc_alias/macro.Macro.html',
'is_alias': true
},
],
},

View File

@ -19,7 +19,6 @@ impl Trait for Struct {
#[doc(alias = "ImplAssociatedConstItem")]
const AssociatedConst: i32 = 12;
// Shouldn't be listed in aliases!
#[doc(alias = "ImplTraitFunction")]
fn function() -> Self::Target { 0 }
}

View File

@ -218,7 +218,7 @@ function lookForEntry(entry, data) {
return null;
}
function loadMainJsAndIndex(mainJs, searchIndex, crate) {
function loadMainJsAndIndex(mainJs, searchIndex, storageJs, crate) {
if (searchIndex[searchIndex.length - 1].length === 0) {
searchIndex.pop();
}
@ -241,6 +241,7 @@ function loadMainJsAndIndex(mainJs, searchIndex, crate) {
ALIASES = {};
finalJS += 'window = { "currentCrate": "' + crate + '" };\n';
finalJS += 'var rootPath = "../";\n';
finalJS += loadThings(["onEach"], 'function', extractFunction, storageJs);
finalJS += loadThings(arraysToLoad, 'array', extractArrayVariable, mainJs);
finalJS += loadThings(variablesToLoad, 'variable', extractVariable, mainJs);
finalJS += loadThings(functionsToLoad, 'function', extractFunction, mainJs);
@ -338,10 +339,11 @@ function runChecks(testFile, loaded, index) {
function load_files(doc_folder, resource_suffix, crate) {
var mainJs = readFile(path.join(doc_folder, "main" + resource_suffix + ".js"));
var storageJs = readFile(path.join(doc_folder, "storage" + resource_suffix + ".js"));
var searchIndex = readFile(
path.join(doc_folder, "search-index" + resource_suffix + ".js")).split("\n");
return loadMainJsAndIndex(mainJs, searchIndex, crate);
return loadMainJsAndIndex(mainJs, searchIndex, storageJs, crate);
}
function showHelp() {