@@ -1462,6 +1462,32 @@ function initSearch(rawSearchIndex) {
14621462 if ( ! typePassesFilter ( queryElem . typeFilter , fnType . ty ) ) {
14631463 continue ;
14641464 }
1465+ const queryElemPathLength = queryElem . pathWithoutLast . length ;
1466+ // If the query element is a path (it contains `::`), we need to check if this
1467+ // path is compatible with the target type.
1468+ if ( queryElemPathLength > 0 ) {
1469+ const fnTypePath = fnType . path !== undefined && fnType . path !== null ?
1470+ fnType . path . split ( "::" ) : [ ] ;
1471+ // If the path provided in the query element is longer than this type,
1472+ // no need to check it since it won't match in any case.
1473+ if ( queryElemPathLength > fnTypePath . length ) {
1474+ continue ;
1475+ }
1476+ let i = 0 ;
1477+ for ( const path of fnTypePath ) {
1478+ if ( path === queryElem . pathWithoutLast [ i ] ) {
1479+ i += 1 ;
1480+ if ( i >= queryElemPathLength ) {
1481+ break ;
1482+ }
1483+ }
1484+ }
1485+ if ( i < queryElemPathLength ) {
1486+ // If we didn't find all parts of the path of the query element inside
1487+ // the fn type, then it's not the right one.
1488+ continue ;
1489+ }
1490+ }
14651491 if ( queryElem . generics . length === 0 || checkGenerics ( fnType , queryElem ) ) {
14661492 currentFnTypeList . splice ( i , 1 ) ;
14671493 const result = doHandleQueryElemList ( currentFnTypeList , queryElemList ) ;
@@ -1862,14 +1888,14 @@ function initSearch(rawSearchIndex) {
18621888 * @param {QueryElement } elem
18631889 */
18641890 function convertNameToId ( elem ) {
1865- if ( typeNameIdMap . has ( elem . name ) ) {
1866- elem . id = typeNameIdMap . get ( elem . name ) ;
1891+ if ( typeNameIdMap . has ( elem . pathLast ) ) {
1892+ elem . id = typeNameIdMap . get ( elem . pathLast ) ;
18671893 } else if ( ! parsedQuery . literalSearch ) {
18681894 let match = - 1 ;
18691895 let matchDist = maxEditDistance + 1 ;
18701896 let matchName = "" ;
18711897 for ( const [ name , id ] of typeNameIdMap ) {
1872- const dist = editDistance ( name , elem . name , maxEditDistance ) ;
1898+ const dist = editDistance ( name , elem . pathLast , maxEditDistance ) ;
18731899 if ( dist <= matchDist && dist <= maxEditDistance ) {
18741900 if ( dist === matchDist && matchName > name ) {
18751901 continue ;
@@ -2385,10 +2411,19 @@ ${item.displayPath}<span class="${type}">${name}</span>\
23852411 ) ;
23862412 }
23872413 // `0` is used as a sentinel because it's fewer bytes than `null`
2388- const item = pathIndex === 0 ? null : lowercasePaths [ pathIndex - 1 ] ;
2414+ if ( pathIndex === 0 ) {
2415+ return {
2416+ id : - 1 ,
2417+ ty : null ,
2418+ path : null ,
2419+ generics : generics ,
2420+ } ;
2421+ }
2422+ const item = lowercasePaths [ pathIndex - 1 ] ;
23892423 return {
2390- id : item === null ? - 1 : buildTypeMapIndex ( item . name ) ,
2391- ty : item === null ? null : item . ty ,
2424+ id : buildTypeMapIndex ( item . name ) ,
2425+ ty : item . ty ,
2426+ path : item . path ,
23922427 generics : generics ,
23932428 } ;
23942429 } ) ;
@@ -2417,15 +2452,25 @@ ${item.displayPath}<span class="${type}">${name}</span>\
24172452 if ( functionSearchType === 0 ) {
24182453 return null ;
24192454 }
2420- let inputs , output , item ;
2455+ let inputs , output ;
24212456 if ( typeof functionSearchType [ INPUTS_DATA ] === "number" ) {
24222457 const pathIndex = functionSearchType [ INPUTS_DATA ] ;
2423- item = pathIndex === 0 ? null : lowercasePaths [ pathIndex - 1 ] ;
2424- inputs = [ {
2425- id : item === null ? - 1 : buildTypeMapIndex ( item . name ) ,
2426- ty : item === null ? null : item . ty ,
2427- generics : [ ] ,
2428- } ] ;
2458+ if ( pathIndex === 0 ) {
2459+ inputs = [ {
2460+ id : - 1 ,
2461+ ty : null ,
2462+ path : null ,
2463+ generics : [ ] ,
2464+ } ] ;
2465+ } else {
2466+ const item = lowercasePaths [ pathIndex - 1 ] ;
2467+ inputs = [ {
2468+ id : buildTypeMapIndex ( item . name ) ,
2469+ ty : item . ty ,
2470+ path : item . path ,
2471+ generics : [ ] ,
2472+ } ] ;
2473+ }
24292474 } else {
24302475 inputs = buildItemSearchTypeAll (
24312476 functionSearchType [ INPUTS_DATA ] ,
@@ -2435,12 +2480,22 @@ ${item.displayPath}<span class="${type}">${name}</span>\
24352480 if ( functionSearchType . length > 1 ) {
24362481 if ( typeof functionSearchType [ OUTPUT_DATA ] === "number" ) {
24372482 const pathIndex = functionSearchType [ OUTPUT_DATA ] ;
2438- item = pathIndex === 0 ? null : lowercasePaths [ pathIndex - 1 ] ;
2439- output = [ {
2440- id : item === null ? - 1 : buildTypeMapIndex ( item . name ) ,
2441- ty : item === null ? null : item . ty ,
2442- generics : [ ] ,
2443- } ] ;
2483+ if ( pathIndex === 0 ) {
2484+ output = [ {
2485+ id : - 1 ,
2486+ ty : null ,
2487+ path : null ,
2488+ generics : [ ] ,
2489+ } ] ;
2490+ } else {
2491+ const item = lowercasePaths [ pathIndex - 1 ] ;
2492+ output = [ {
2493+ id : buildTypeMapIndex ( item . name ) ,
2494+ ty : item . ty ,
2495+ path : item . path ,
2496+ generics : [ ] ,
2497+ } ] ;
2498+ }
24442499 } else {
24452500 output = buildItemSearchTypeAll (
24462501 functionSearchType [ OUTPUT_DATA ] ,
@@ -2573,9 +2628,19 @@ ${item.displayPath}<span class="${type}">${name}</span>\
25732628 // convert `rawPaths` entries into object form
25742629 // generate normalizedPaths for function search mode
25752630 let len = paths . length ;
2631+ let lastPath = itemPaths . get ( 0 ) ;
25762632 for ( let i = 0 ; i < len ; ++ i ) {
2577- lowercasePaths . push ( { ty : paths [ i ] [ 0 ] , name : paths [ i ] [ 1 ] . toLowerCase ( ) } ) ;
2578- paths [ i ] = { ty : paths [ i ] [ 0 ] , name : paths [ i ] [ 1 ] } ;
2633+ const elem = paths [ i ] ;
2634+ const ty = elem [ 0 ] ;
2635+ const name = elem [ 1 ] ;
2636+ let path = null ;
2637+ if ( elem . length > 2 ) {
2638+ path = itemPaths . has ( elem [ 2 ] ) ? itemPaths . get ( elem [ 2 ] ) : lastPath ;
2639+ lastPath = path ;
2640+ }
2641+
2642+ lowercasePaths . push ( { ty : ty , name : name . toLowerCase ( ) , path : path } ) ;
2643+ paths [ i ] = { ty : ty , name : name , path : path } ;
25792644 }
25802645
25812646 // convert `item*` into an object form, and construct word indices.
@@ -2585,8 +2650,8 @@ ${item.displayPath}<span class="${type}">${name}</span>\
25852650 // operation that is cached for the life of the page state so that
25862651 // all other search operations have access to this cached data for
25872652 // faster analysis operations
2653+ lastPath = "" ;
25882654 len = itemTypes . length ;
2589- let lastPath = "" ;
25902655 for ( let i = 0 ; i < len ; ++ i ) {
25912656 let word = "" ;
25922657 // This object should have exactly the same set of fields as the "crateRow"
@@ -2595,11 +2660,12 @@ ${item.displayPath}<span class="${type}">${name}</span>\
25952660 word = itemNames [ i ] . toLowerCase ( ) ;
25962661 }
25972662 searchWords . push ( word ) ;
2663+ const path = itemPaths . has ( i ) ? itemPaths . get ( i ) : lastPath ;
25982664 const row = {
25992665 crate : crate ,
26002666 ty : itemTypes . charCodeAt ( i ) - charA ,
26012667 name : itemNames [ i ] ,
2602- path : itemPaths . has ( i ) ? itemPaths . get ( i ) : lastPath ,
2668+ path : path ,
26032669 desc : itemDescs [ i ] ,
26042670 parent : itemParentIdxs [ i ] > 0 ? paths [ itemParentIdxs [ i ] - 1 ] : undefined ,
26052671 type : buildFunctionSearchType (
0 commit comments