File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { Global } from "../global"
44import fs from "fs/promises"
55import { z } from "zod"
66import { NamedError } from "../util/error"
7+ import { lazy } from "../util/lazy"
78
89export namespace Ripgrep {
910 const PLATFORM = {
@@ -35,8 +36,10 @@ export namespace Ripgrep {
3536 } ) ,
3637 )
3738
38- const state = App . state ( "ripgrep" , async ( ) => {
39- const filepath = path . join (
39+ const state = lazy ( async ( ) => {
40+ let filepath = Bun . which ( "rg" )
41+ if ( filepath ) return { filepath }
42+ filepath = path . join (
4043 Global . Path . bin ,
4144 "rg" + ( process . platform === "win32" ? ".exe" : "" ) ,
4245 )
Original file line number Diff line number Diff line change 11export namespace File {
22 const glob = new Bun . Glob ( "**/*" )
3- export async function search ( path : string ) {
3+ export async function search ( path : string , query : string ) {
44 for await ( const entry of glob . scan ( {
55 cwd : path ,
66 onlyFiles : true ,
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ const cli = yargs(hideBin(process.argv))
2626 describe : "Print logs to stderr" ,
2727 type : "boolean" ,
2828 } )
29- . middleware ( async ( args ) => {
29+ . middleware ( async ( ) => {
3030 await Log . init ( { print : process . argv . includes ( "--print-logs" ) } )
3131 Log . Default . info ( "opencode" , {
3232 version : VERSION ,
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import { App } from "../app/app"
1212import { Global } from "../global"
1313import { mapValues } from "remeda"
1414import { NamedError } from "../util/error"
15+ import { Fzf } from "../external/fzf"
1516
1617const ERRORS = {
1718 400 : {
@@ -427,6 +428,34 @@ export namespace Server {
427428 } )
428429 } ,
429430 )
431+ . post (
432+ "/file_search" ,
433+ describeRoute ( {
434+ description : "Search for files" ,
435+ responses : {
436+ 200 : {
437+ description : "Search for files" ,
438+ content : {
439+ "application/json" : {
440+ schema : resolver ( z . string ( ) . array ( ) ) ,
441+ } ,
442+ } ,
443+ } ,
444+ } ,
445+ } ) ,
446+ zValidator (
447+ "json" ,
448+ z . object ( {
449+ query : z . string ( ) ,
450+ } ) ,
451+ ) ,
452+ async ( c ) => {
453+ const body = c . req . valid ( "json" )
454+ const app = App . info ( )
455+ const result = await Fzf . search ( app . path . cwd , body . query )
456+ return c . json ( result )
457+ } ,
458+ )
430459
431460 return result
432461 }
Original file line number Diff line number Diff line change 11import { z } from "zod"
22import { Tool } from "./tool"
33import { App } from "../app/app"
4- import { Ripgrep } from "../ripgrep"
4+ import { Ripgrep } from "../external/ ripgrep"
55
66import DESCRIPTION from "./grep.txt"
77
Original file line number Diff line number Diff line change 1+ export function lazy < T > ( fn : ( ) => T ) {
2+ let value : T | undefined
3+ let loaded = false
4+
5+ return ( ) : T => {
6+ if ( loaded ) return value as T
7+ value = fn ( )
8+ return value as T
9+ }
10+ }
11+
You can’t perform that action at this time.
0 commit comments