@@ -1462,6 +1462,32 @@ function initSearch(rawSearchIndex) {
1462
1462
if ( ! typePassesFilter ( queryElem . typeFilter , fnType . ty ) ) {
1463
1463
continue ;
1464
1464
}
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
+ }
1465
1491
if ( queryElem . generics . length === 0 || checkGenerics ( fnType , queryElem ) ) {
1466
1492
currentFnTypeList . splice ( i , 1 ) ;
1467
1493
const result = doHandleQueryElemList ( currentFnTypeList , queryElemList ) ;
@@ -1862,14 +1888,14 @@ function initSearch(rawSearchIndex) {
1862
1888
* @param {QueryElement } elem
1863
1889
*/
1864
1890
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 ) ;
1867
1893
} else if ( ! parsedQuery . literalSearch ) {
1868
1894
let match = - 1 ;
1869
1895
let matchDist = maxEditDistance + 1 ;
1870
1896
let matchName = "" ;
1871
1897
for ( const [ name , id ] of typeNameIdMap ) {
1872
- const dist = editDistance ( name , elem . name , maxEditDistance ) ;
1898
+ const dist = editDistance ( name , elem . pathLast , maxEditDistance ) ;
1873
1899
if ( dist <= matchDist && dist <= maxEditDistance ) {
1874
1900
if ( dist === matchDist && matchName > name ) {
1875
1901
continue ;
@@ -2385,10 +2411,19 @@ ${item.displayPath}<span class="${type}">${name}</span>\
2385
2411
) ;
2386
2412
}
2387
2413
// `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 ] ;
2389
2423
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 ,
2392
2427
generics : generics ,
2393
2428
} ;
2394
2429
} ) ;
@@ -2417,15 +2452,25 @@ ${item.displayPath}<span class="${type}">${name}</span>\
2417
2452
if ( functionSearchType === 0 ) {
2418
2453
return null ;
2419
2454
}
2420
- let inputs , output , item ;
2455
+ let inputs , output ;
2421
2456
if ( typeof functionSearchType [ INPUTS_DATA ] === "number" ) {
2422
2457
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
+ }
2429
2474
} else {
2430
2475
inputs = buildItemSearchTypeAll (
2431
2476
functionSearchType [ INPUTS_DATA ] ,
@@ -2435,12 +2480,22 @@ ${item.displayPath}<span class="${type}">${name}</span>\
2435
2480
if ( functionSearchType . length > 1 ) {
2436
2481
if ( typeof functionSearchType [ OUTPUT_DATA ] === "number" ) {
2437
2482
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
+ }
2444
2499
} else {
2445
2500
output = buildItemSearchTypeAll (
2446
2501
functionSearchType [ OUTPUT_DATA ] ,
@@ -2573,9 +2628,19 @@ ${item.displayPath}<span class="${type}">${name}</span>\
2573
2628
// convert `rawPaths` entries into object form
2574
2629
// generate normalizedPaths for function search mode
2575
2630
let len = paths . length ;
2631
+ let lastPath = itemPaths . get ( 0 ) ;
2576
2632
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 } ;
2579
2644
}
2580
2645
2581
2646
// convert `item*` into an object form, and construct word indices.
@@ -2585,8 +2650,8 @@ ${item.displayPath}<span class="${type}">${name}</span>\
2585
2650
// operation that is cached for the life of the page state so that
2586
2651
// all other search operations have access to this cached data for
2587
2652
// faster analysis operations
2653
+ lastPath = "" ;
2588
2654
len = itemTypes . length ;
2589
- let lastPath = "" ;
2590
2655
for ( let i = 0 ; i < len ; ++ i ) {
2591
2656
let word = "" ;
2592
2657
// This object should have exactly the same set of fields as the "crateRow"
@@ -2595,11 +2660,12 @@ ${item.displayPath}<span class="${type}">${name}</span>\
2595
2660
word = itemNames [ i ] . toLowerCase ( ) ;
2596
2661
}
2597
2662
searchWords . push ( word ) ;
2663
+ const path = itemPaths . has ( i ) ? itemPaths . get ( i ) : lastPath ;
2598
2664
const row = {
2599
2665
crate : crate ,
2600
2666
ty : itemTypes . charCodeAt ( i ) - charA ,
2601
2667
name : itemNames [ i ] ,
2602
- path : itemPaths . has ( i ) ? itemPaths . get ( i ) : lastPath ,
2668
+ path : path ,
2603
2669
desc : itemDescs [ i ] ,
2604
2670
parent : itemParentIdxs [ i ] > 0 ? paths [ itemParentIdxs [ i ] - 1 ] : undefined ,
2605
2671
type : buildFunctionSearchType (
0 commit comments