@@ -1500,10 +1500,10 @@ function initSearch(rawSearchIndex) {
15001500 * This function checks if a list of search query `queryElems` can all be found in the
15011501 * search index (`fnTypes`).
15021502 *
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
15041504 * 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
15071507 * runs out of candidates.
15081508 *
15091509 * @param {Array<FunctionType> } fnTypesIn - The objects to check.
@@ -1516,7 +1516,7 @@ function initSearch(rawSearchIndex) {
15161516 * - Limit checks that Ty matches Vec<Ty>,
15171517 * but not Vec<ParamEnvAnd<WithInfcx<ConstTy<Interner<Ty=Ty>>>>>
15181518 *
1519- * @return {boolean } - Returns true if a match, false otherwise.
1519+ * @return {[FunctionType]|null } - Returns highlighed results if a match, null otherwise.
15201520 */
15211521 function unifyFunctionTypes (
15221522 fnTypesIn ,
@@ -1527,17 +1527,17 @@ function initSearch(rawSearchIndex) {
15271527 unboxingDepth ,
15281528 ) {
15291529 if ( unboxingDepth >= UNBOXING_LIMIT ) {
1530- return false ;
1530+ return null ;
15311531 }
15321532 /**
15331533 * @type Map<integer, integer>|null
15341534 */
15351535 const mgens = mgensIn === null ? null : new Map ( mgensIn ) ;
15361536 if ( queryElems . length === 0 ) {
1537- return ! solutionCb || solutionCb ( mgens ) ;
1537+ return ( ! solutionCb || solutionCb ( mgens ) ) ? fnTypesIn : null ;
15381538 }
15391539 if ( ! fnTypesIn || fnTypesIn . length === 0 ) {
1540- return false ;
1540+ return null ;
15411541 }
15421542 const ql = queryElems . length ;
15431543 const fl = fnTypesIn . length ;
@@ -1546,7 +1546,7 @@ function initSearch(rawSearchIndex) {
15461546 if ( ql === 1 && queryElems [ 0 ] . generics . length === 0
15471547 && queryElems [ 0 ] . bindings . size === 0 ) {
15481548 const queryElem = queryElems [ 0 ] ;
1549- for ( const fnType of fnTypesIn ) {
1549+ for ( const [ i , fnType ] of fnTypesIn . entries ( ) ) {
15501550 if ( ! unifyFunctionTypeIsMatchCandidate ( fnType , queryElem , mgens ) ) {
15511551 continue ;
15521552 }
@@ -1558,14 +1558,18 @@ function initSearch(rawSearchIndex) {
15581558 const mgensScratch = new Map ( mgens ) ;
15591559 mgensScratch . set ( fnType . id , queryElem . id ) ;
15601560 if ( ! solutionCb || solutionCb ( mgensScratch ) ) {
1561- return true ;
1561+ const highlighted = [ ...fnTypesIn ] ;
1562+ highlighted [ i ] = Object . assign ( { highlighted : true } , fnType ) ;
1563+ return highlighted ;
15621564 }
15631565 } else if ( ! solutionCb || solutionCb ( mgens ? new Map ( mgens ) : null ) ) {
15641566 // unifyFunctionTypeIsMatchCandidate already checks that ids match
1565- return true ;
1567+ const highlighted = [ ...fnTypesIn ] ;
1568+ highlighted [ i ] = Object . assign ( { highlighted : true } , fnType ) ;
1569+ return highlighted ;
15661570 }
15671571 }
1568- for ( const fnType of fnTypesIn ) {
1572+ for ( const [ i , fnType ] of fnTypesIn . entries ( ) ) {
15691573 if ( ! unifyFunctionTypeIsUnboxCandidate (
15701574 fnType ,
15711575 queryElem ,
@@ -1590,17 +1594,28 @@ function initSearch(rawSearchIndex) {
15901594 solutionCb ,
15911595 unboxingDepth + 1 ,
15921596 ) ) {
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 ;
15941618 }
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 ;
16041619 }
16051620 }
16061621 return false ;
@@ -1696,7 +1711,11 @@ function initSearch(rawSearchIndex) {
16961711 unboxingDepth ,
16971712 ) ;
16981713 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+ } ) ;
17001719 }
17011720 // backtrack
17021721 fnTypes [ flast ] = fnTypes [ i ] ;
@@ -1739,10 +1758,27 @@ function initSearch(rawSearchIndex) {
17391758 unboxingDepth + 1 ,
17401759 ) ;
17411760 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+ } ) ;
17431779 }
17441780 }
1745- return false ;
1781+ return null ;
17461782 }
17471783 /**
17481784 * Check if this function is a match candidate.
0 commit comments