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