@@ -1500,10 +1500,10 @@ function initSearch(rawSearchIndex) {
1500
1500
* This function checks if a list of search query `queryElems` can all be found in the
1501
1501
* search index (`fnTypes`).
1502
1502
*
1503
- * This function returns `true` on a match, or `false` if none . If `solutionCb` is
1503
+ * This function returns highlighted results on a match, or `null` . If `solutionCb` is
1504
1504
* supplied, it will call that function with mgens, and that callback can accept or
1505
- * reject the result bu returning `true` or `false`. If the callback returns false,
1506
- * then this function will try with a different solution, or bail with false if it
1505
+ * reject the result by returning `true` or `false`. If the callback returns false,
1506
+ * then this function will try with a different solution, or bail with null if it
1507
1507
* runs out of candidates.
1508
1508
*
1509
1509
* @param {Array<FunctionType> } fnTypesIn - The objects to check.
@@ -1516,7 +1516,7 @@ function initSearch(rawSearchIndex) {
1516
1516
* - Limit checks that Ty matches Vec<Ty>,
1517
1517
* but not Vec<ParamEnvAnd<WithInfcx<ConstTy<Interner<Ty=Ty>>>>>
1518
1518
*
1519
- * @return {boolean } - Returns true if a match, false otherwise.
1519
+ * @return {[FunctionType]|null } - Returns highlighed results if a match, null otherwise.
1520
1520
*/
1521
1521
function unifyFunctionTypes (
1522
1522
fnTypesIn ,
@@ -1527,17 +1527,17 @@ function initSearch(rawSearchIndex) {
1527
1527
unboxingDepth ,
1528
1528
) {
1529
1529
if ( unboxingDepth >= UNBOXING_LIMIT ) {
1530
- return false ;
1530
+ return null ;
1531
1531
}
1532
1532
/**
1533
1533
* @type Map<integer, integer>|null
1534
1534
*/
1535
1535
const mgens = mgensIn === null ? null : new Map ( mgensIn ) ;
1536
1536
if ( queryElems . length === 0 ) {
1537
- return ! solutionCb || solutionCb ( mgens ) ;
1537
+ return ( ! solutionCb || solutionCb ( mgens ) ) ? fnTypesIn : null ;
1538
1538
}
1539
1539
if ( ! fnTypesIn || fnTypesIn . length === 0 ) {
1540
- return false ;
1540
+ return null ;
1541
1541
}
1542
1542
const ql = queryElems . length ;
1543
1543
const fl = fnTypesIn . length ;
@@ -1546,7 +1546,7 @@ function initSearch(rawSearchIndex) {
1546
1546
if ( ql === 1 && queryElems [ 0 ] . generics . length === 0
1547
1547
&& queryElems [ 0 ] . bindings . size === 0 ) {
1548
1548
const queryElem = queryElems [ 0 ] ;
1549
- for ( const fnType of fnTypesIn ) {
1549
+ for ( const [ i , fnType ] of fnTypesIn . entries ( ) ) {
1550
1550
if ( ! unifyFunctionTypeIsMatchCandidate ( fnType , queryElem , mgens ) ) {
1551
1551
continue ;
1552
1552
}
@@ -1558,14 +1558,18 @@ function initSearch(rawSearchIndex) {
1558
1558
const mgensScratch = new Map ( mgens ) ;
1559
1559
mgensScratch . set ( fnType . id , queryElem . id ) ;
1560
1560
if ( ! solutionCb || solutionCb ( mgensScratch ) ) {
1561
- return true ;
1561
+ const highlighted = [ ...fnTypesIn ] ;
1562
+ highlighted [ i ] = Object . assign ( { highlighted : true } , fnType ) ;
1563
+ return highlighted ;
1562
1564
}
1563
1565
} else if ( ! solutionCb || solutionCb ( mgens ? new Map ( mgens ) : null ) ) {
1564
1566
// unifyFunctionTypeIsMatchCandidate already checks that ids match
1565
- return true ;
1567
+ const highlighted = [ ...fnTypesIn ] ;
1568
+ highlighted [ i ] = Object . assign ( { highlighted : true } , fnType ) ;
1569
+ return highlighted ;
1566
1570
}
1567
1571
}
1568
- for ( const fnType of fnTypesIn ) {
1572
+ for ( const [ i , fnType ] of fnTypesIn . entries ( ) ) {
1569
1573
if ( ! unifyFunctionTypeIsUnboxCandidate (
1570
1574
fnType ,
1571
1575
queryElem ,
@@ -1590,17 +1594,28 @@ function initSearch(rawSearchIndex) {
1590
1594
solutionCb ,
1591
1595
unboxingDepth + 1 ,
1592
1596
) ) {
1593
- return true ;
1597
+ const highlighted = [ ...fnTypesIn ] ;
1598
+ highlighted [ i ] = Object . assign ( { highlighted : true } , fnType ) ;
1599
+ return highlighted ;
1600
+ }
1601
+ } else {
1602
+ const highlightedGenerics = unifyFunctionTypes (
1603
+ [ ...fnType . generics , ...Array . from ( fnType . bindings . values ( ) ) . flat ( ) ] ,
1604
+ queryElems ,
1605
+ whereClause ,
1606
+ mgens ? new Map ( mgens ) : null ,
1607
+ solutionCb ,
1608
+ unboxingDepth + 1 ,
1609
+ ) ;
1610
+ if ( highlightedGenerics ) {
1611
+ const highlighted = [ ...fnTypesIn ] ;
1612
+ highlighted [ i ] = Object . assign ( {
1613
+ generics : highlightedGenerics ,
1614
+ bindings : new Map ( ) ,
1615
+ highlighted : false ,
1616
+ } , fnType ) ;
1617
+ return highlighted ;
1594
1618
}
1595
- } else if ( unifyFunctionTypes (
1596
- [ ...fnType . generics , ...Array . from ( fnType . bindings . values ( ) ) . flat ( ) ] ,
1597
- queryElems ,
1598
- whereClause ,
1599
- mgens ? new Map ( mgens ) : null ,
1600
- solutionCb ,
1601
- unboxingDepth + 1 ,
1602
- ) ) {
1603
- return true ;
1604
1619
}
1605
1620
}
1606
1621
return false ;
@@ -1696,7 +1711,11 @@ function initSearch(rawSearchIndex) {
1696
1711
unboxingDepth ,
1697
1712
) ;
1698
1713
if ( passesUnification ) {
1699
- return true ;
1714
+ return fnTypesIn . map ( innerFnType => {
1715
+ const highlighted = fnType === innerFnType ||
1716
+ passesUnification . indexOf ( innerFnType ) !== - 1 ;
1717
+ return Object . assign ( { highlighted } , innerFnType ) ;
1718
+ } ) ;
1700
1719
}
1701
1720
// backtrack
1702
1721
fnTypes [ flast ] = fnTypes [ i ] ;
@@ -1739,10 +1758,27 @@ function initSearch(rawSearchIndex) {
1739
1758
unboxingDepth + 1 ,
1740
1759
) ;
1741
1760
if ( passesUnification ) {
1742
- return true ;
1761
+ return fnTypesIn . map ( innerFnType => {
1762
+ if ( fnType === innerFnType ) {
1763
+ return Object . assign ( {
1764
+ generics : unifyFunctionTypes (
1765
+ [ ...generics , ...bindings ] ,
1766
+ [ queryElem ] ,
1767
+ whereClause ,
1768
+ mgensScratch ,
1769
+ solutionCb ,
1770
+ unboxingDepth + 1 ,
1771
+ ) || [ ] ,
1772
+ bindings : new Map ( ) ,
1773
+ highlighted : false ,
1774
+ } , innerFnType ) ;
1775
+ }
1776
+ const highlighted = passesUnification . indexOf ( innerFnType ) !== - 1 ;
1777
+ return Object . assign ( { highlighted } , innerFnType ) ;
1778
+ } ) ;
1743
1779
}
1744
1780
}
1745
- return false ;
1781
+ return null ;
1746
1782
}
1747
1783
/**
1748
1784
* Check if this function is a match candidate.
0 commit comments