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) { 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 aliases = [];
var crateAliases = [];
var i; var i;
if (filterCrates !== undefined && if (filterCrates !== undefined &&
ALIASES[filterCrates] && ALIASES[filterCrates] &&
@ -990,25 +993,28 @@ function getSearchElement() {
} else { } else {
Object.keys(ALIASES).forEach(function(crate) { Object.keys(ALIASES).forEach(function(crate) {
if (ALIASES[crate][query.search]) { if (ALIASES[crate][query.search]) {
var pushTo = crate === window.currentCrate ? crateAliases : aliases;
for (i = 0; i < ALIASES[crate][query.search].length; ++i) { for (i = 0; i < ALIASES[crate][query.search].length; ++i) {
aliases.push( pushTo.push(
createAliasFromItem( createAliasFromItem(
searchIndex[ALIASES[crate][query.search][i]])); searchIndex[ALIASES[crate][query.search][i]]));
} }
} }
}); });
} }
aliases.sort(function(aaa, bbb) {
var sortFunc = function(aaa, bbb) {
if (aaa.path < bbb.path) { if (aaa.path < bbb.path) {
return 1; return 1;
} else if (aaa.path === bbb.path) { } else if (aaa.path === bbb.path) {
return 0; return 0;
} }
return -1; return -1;
}); };
for (i = 0; i < aliases.length; ++i) { crateAliases.sort(sortFunc);
var alias = aliases[i]; aliases.sort(sortFunc);
var pushFunc = function(alias) {
alias.alias = query.raw; alias.alias = query.raw;
var res = buildHrefAndPath(alias); var res = buildHrefAndPath(alias);
alias.displayPath = pathSplitter(res[0]); alias.displayPath = pathSplitter(res[0]);
@ -1019,7 +1025,9 @@ function getSearchElement() {
if (ret.others.length > MAX_RESULTS) { if (ret.others.length > MAX_RESULTS) {
ret.others.pop(); ret.others.pop();
} }
} };
onEach(aliases, pushFunc);
onEach(crateAliases, pushFunc);
} }
// quoted values mean literal search // quoted values mean literal search

View File

@ -1,12 +1,10 @@
// ignore-order
const QUERY = '+'; const QUERY = '+';
const EXPECTED = { const EXPECTED = {
'others': [ 'others': [
{ 'path': 'core::ops', 'name': 'AddAssign' },
{ 'path': 'core::ops', 'name': 'Add' },
{ 'path': 'std::ops', 'name': 'AddAssign' }, { 'path': 'std::ops', 'name': 'AddAssign' },
{ 'path': 'std::ops', 'name': 'Add' }, { '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', 'path': 'doc_alias',
'name': 'Struct', 'name': 'Struct',
'alias': 'StructItem', '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', 'path': 'doc_alias::Struct',
'name': 'field', 'name': 'field',
'alias': 'StructFieldItem', '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', 'path': 'doc_alias::Struct',
'name': 'method', 'name': 'method',
'alias': 'StructMethodItem', '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': [], 'others': [],
}, },
{ {
// ImplTraitFunction 'others': [
'others': [], {
'path': 'doc_alias::Struct',
'name': 'function',
'alias': 'ImplTraitFunction',
'href': '../doc_alias/struct.Struct.html#method.function',
'is_alias': true
},
],
}, },
{ {
'others': [ 'others': [
@ -74,7 +84,8 @@ const EXPECTED = [
'path': 'doc_alias', 'path': 'doc_alias',
'name': 'Enum', 'name': 'Enum',
'alias': 'EnumItem', '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', 'path': 'doc_alias::Enum',
'name': 'Variant', 'name': 'Variant',
'alias': 'VariantItem', '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', 'path': 'doc_alias::Enum',
'name': 'method', 'name': 'method',
'alias': 'EnumMethodItem', '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', 'path': 'doc_alias',
'name': 'Typedef', 'name': 'Typedef',
'alias': 'TypedefItem', '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', 'path': 'doc_alias',
'name': 'Trait', 'name': 'Trait',
'alias': 'TraitItem', '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', 'path': 'doc_alias::Trait',
'name': 'Target', 'name': 'Target',
'alias': 'TraitTypeItem', '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', 'path': 'doc_alias::Trait',
'name': 'AssociatedConst', 'name': 'AssociatedConst',
'alias': 'AssociatedConstItem', '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', 'path': 'doc_alias::Trait',
'name': 'function', 'name': 'function',
'alias': 'TraitFunctionItem', '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', 'path': 'doc_alias',
'name': 'function', 'name': 'function',
'alias': 'FunctionItem', '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', 'path': 'doc_alias',
'name': 'Module', 'name': 'Module',
'alias': 'ModuleItem', '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', 'path': 'doc_alias',
'name': 'Const', 'name': 'Const',
'alias': 'ConstItem', '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', 'path': 'doc_alias',
'name': 'Static', 'name': 'Static',
'alias': 'StaticItem', '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', 'path': 'doc_alias',
'name': 'Union', 'name': 'Union',
'alias': 'UnionItem', 'alias': 'UnionItem',
'href': '../doc_alias/union.Union.html' 'href': '../doc_alias/union.Union.html',
'is_alias': true
}, },
// Not an alias! // Not an alias!
{ {
@ -210,7 +233,8 @@ const EXPECTED = [
'path': 'doc_alias::Union', 'path': 'doc_alias::Union',
'name': 'union_item', 'name': 'union_item',
'alias': 'UnionFieldItem', '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', 'path': 'doc_alias::Union',
'name': 'method', 'name': 'method',
'alias': 'UnionMethodItem', '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', 'path': 'doc_alias',
'name': 'Macro', 'name': 'Macro',
'alias': 'MacroItem', '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")] #[doc(alias = "ImplAssociatedConstItem")]
const AssociatedConst: i32 = 12; const AssociatedConst: i32 = 12;
// Shouldn't be listed in aliases!
#[doc(alias = "ImplTraitFunction")] #[doc(alias = "ImplTraitFunction")]
fn function() -> Self::Target { 0 } fn function() -> Self::Target { 0 }
} }

View File

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