Improve search.js code readability and add missing test case

This commit is contained in:
Guillaume Gomez
2026-05-13 00:33:54 +02:00
parent 794301af24
commit 376e0c0ba4
3 changed files with 25 additions and 1 deletions
+5 -1
View File
@@ -120,6 +120,8 @@ const itemTypes = Object.freeze({
traitalias: 25,
generic: 26,
attribute: 27,
decl_macro_attribute: 28,
decl_macro_derive: 29,
});
const itemTypesName = Array.from(Object.keys(itemTypes));
@@ -1660,7 +1662,7 @@ class DocSearch {
associatedItemDisambiguatorOrExternCrateUrl: raw.length === 8 ? null : raw[8],
forceMacroHref: false,
};
if (item.ty === 28 || item.ty === 29) {
if (item.ty === itemTypes.decl_macro_attribute || item.ty === itemTypes.decl_macro_derive) {
// "proc attribute" is 23, "proc derive" is 24 whereas "decl macro attribute" is 28 and
// "decl macro derive" is 29, so 5 of difference to go from the latter to the former.
item.ty -= 5;
@@ -4823,6 +4825,8 @@ const longItemTypes = [
"trait alias",
"",
"attribute",
"", // decl macro attribute, never used as is
"", // decl macro derive, never used as is
];
// @ts-expect-error
let currentResults;
+14
View File
@@ -28,6 +28,18 @@ const EXPECTED = [
'href': '../macro_kinds/attr.macro2.html',
'ty': 23,
},
{
'path': 'macro_kinds',
'name': 'macro5',
'href': '../macro_kinds/macro.macro5.html',
'ty': 23,
},
{
'path': 'macro_kinds',
'name': 'macro5',
'href': '../macro_kinds/macro.macro5.html',
'ty': 24,
},
{
'path': 'macro_kinds',
'name': 'macro4',
@@ -47,12 +59,14 @@ const EXPECTED = [
'others': [
{ 'path': 'macro_kinds', 'name': 'macro1', 'href': '../macro_kinds/macro.macro1.html' },
{ 'path': 'macro_kinds', 'name': 'macro2', 'href': '../macro_kinds/attr.macro2.html' },
{ 'path': 'macro_kinds', 'name': 'macro5', 'href': '../macro_kinds/macro.macro5.html' },
],
},
{
'query': 'derive:macro',
'others': [
{ 'path': 'macro_kinds', 'name': 'macro1', 'href': '../macro_kinds/macro.macro1.html' },
{ 'path': 'macro_kinds', 'name': 'macro5', 'href': '../macro_kinds/macro.macro5.html' },
{
'path': 'macro_kinds', 'name': 'macro4', 'href': '../macro_kinds/derive.macro4.html'
},
+6
View File
@@ -26,3 +26,9 @@ macro_rules! macro3 {
macro_rules! macro4 {
derive() () => {};
}
#[macro_export]
macro_rules! macro5 {
attr() () => {};
derive() () => {};
}