@@ -72,11 +72,10 @@ async function tryLoadMiniSearch(): Promise<
7272/** Opaque handle returned by {@link buildFileIndex}. */
7373export interface DocsetIndex {
7474 /** MiniSearch instance (null when MiniSearch could not be loaded) */
75- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7675 _ms : {
7776 search (
78- query : string ,
79- opts ?: Record < string , unknown > ,
77+ _query : string ,
78+ _opts ?: Record < string , unknown > ,
8079 ) : Array < { id : unknown ; score : number } > ;
8180 } | null ;
8281 /** Absolute path to the docset root used to build this index */
@@ -98,8 +97,13 @@ export async function buildFileIndex(rootPath: string): Promise<DocsetIndex> {
9897 return { _ms : null , rootPath, _idToPath : new Map ( ) } ;
9998 }
10099
101- // eslint-disable-next-line @typescript-eslint/no-explicit-any
102- const ms = new ( MiniSearch as any ) ( {
100+ type MiniSearchInstance = DocsetIndex [ "_ms" ] & {
101+ addAllAsync ( _docs : Array < { id : number ; content : string } > ) : Promise < void > ;
102+ } ;
103+ type MiniSearchCtor = new (
104+ _opts : Record < string , unknown > ,
105+ ) => MiniSearchInstance ;
106+ const ms = new ( MiniSearch as unknown as MiniSearchCtor ) ( {
103107 fields : [ "content" ] ,
104108 storeFields : [ ] ,
105109 } ) ;
@@ -416,13 +420,16 @@ function escapeRegex(s: string): string {
416420 * Only used for the `include` file-filter option; not a full glob engine.
417421 */
418422function matchGlob ( filePath : string , pattern : string ) : boolean {
419- // Convert simple glob to regex
423+ // Convert simple glob to regex.
424+ // Use a rare Unicode placeholder (U+FFFE) to temporarily represent **
425+ // so that the single-* replacement doesn't clobber it.
426+ const DOUBLE_STAR = "\uFFFE" ;
420427 const regexStr = pattern
421428 . replace ( / [ . + ^ $ { } ( ) | [ \] \\ ] / g, "\\$&" ) // escape regex chars (not * and ?)
422- . replace ( / \* \* / g, "\x00" ) // placeholder for **
429+ . replace ( / \* \* / g, DOUBLE_STAR ) // placeholder for **
423430 . replace ( / \* / g, "[^/]*" ) // * → any chars except /
424431 . replace ( / \? / g, "[^/]" ) // ? → single char except /
425- . replace ( / \x00 / g , ".*" ) ; // ** → any chars including /
432+ . replace ( new RegExp ( DOUBLE_STAR , "g" ) , ".*" ) ; // ** → any chars including /
426433
427434 return new RegExp ( regexStr + "$" , "i" ) . test ( filePath ) ;
428435}
0 commit comments