@@ -18,8 +18,6 @@ import { Glob } from "../util/glob"
1818import { Log } from "../util/log"
1919
2020export namespace Fff {
21- const log = Log . create ( { service : "file.fff" } )
22-
2321 export const Match = z . object ( {
2422 path : z . object ( {
2523 text : z . string ( ) ,
@@ -52,7 +50,7 @@ export namespace Fff {
5250
5351 const root = path . join ( Global . Path . cache , "fff" )
5452
55- async function db ( ) {
53+ async function dbs ( ) {
5654 await fs . mkdir ( root , { recursive : true } )
5755 // fff databases are global across the file system
5856 return {
@@ -71,18 +69,26 @@ export namespace Fff {
7169 if ( wait ) return wait
7270
7371 const next = ( async ( ) => {
74- const files = await db ( )
75- const made = FileFinder . create ( {
72+ const files = await dbs ( )
73+ const base = Log . file ( )
74+ const logfile = path . join ( Global . Path . log , base ? "fff-" + path . basename ( base ) : "fff.log" )
75+ const result = FileFinder . create ( {
76+ aiMode : true ,
7677 basePath : dir ,
7778 frecencyDbPath : files . frecency ,
7879 historyDbPath : files . history ,
79- aiMode : true ,
80+ logFilePath : logfile ,
81+ logLevel : Log . currentLevel ( ) . toLowerCase ( ) as "debug" | "info" | "warn" | "error" ,
82+ // if there is second project opened within the same sesion - disable
83+ // content mapping, the memory mapping address space is finite, so we
84+ // don't want to blow user's computer (the limit depends on repo size)
85+ cacheBudgetMaxFiles : memo . map . size > 0 ? 0 : undefined ,
8086 } )
81- if ( ! made . ok ) throw new Error ( made . error )
87+ if ( ! result . ok ) throw new Error ( result . error )
8288 // we do not syncrhnously wait for the results here to not block anything
8389 // fff will do the indexing in the background and will automatically
8490 // become available
85- const pick = made . value
91+ const pick = result . value
8692 memo . map . set ( dir , pick )
8793 return pick
8894 } ) ( )
@@ -96,8 +102,8 @@ export namespace Fff {
96102 }
97103
98104 export async function files ( input : { cwd : string ; query : string ; page ?: number ; size ?: number ; current ?: string } ) {
99- const pick = await picker ( input . cwd )
100- const out = pick . fileSearch ( input . query , {
105+ const fff = await picker ( input . cwd )
106+ const out = fff . fileSearch ( input . query , {
101107 pageIndex : input . page ?? 0 ,
102108 pageSize : input . size ?? 100 ,
103109 currentFile : input . current ,
@@ -107,8 +113,8 @@ export namespace Fff {
107113 }
108114
109115 export async function mixed ( input : { cwd : string ; query : string ; page ?: number ; size ?: number ; current ?: string } ) {
110- const pick = await picker ( input . cwd )
111- const out = pick . mixedSearch ( input . query , {
116+ const fff = await picker ( input . cwd )
117+ const out = fff . mixedSearch ( input . query , {
112118 pageIndex : input . page ?? 0 ,
113119 pageSize : input . size ?? 100 ,
114120 currentFile : input . current ,
0 commit comments