refactor(server): inject runtime options
This commit is contained in:
parent
ace77a5cf7
commit
0409e6884d
17 changed files with 146 additions and 74 deletions
|
|
@ -2,7 +2,7 @@ export * as FileSystemSearch from "./search"
|
|||
|
||||
import { makeLocationNode } from "../effect/app-node"
|
||||
import path from "path"
|
||||
import { Context, Effect, Layer, Scope } from "effect"
|
||||
import { Context, Effect, Layer, Schema, Scope } from "effect"
|
||||
import { Fff } from "#fff"
|
||||
import fuzzysort from "fuzzysort"
|
||||
import { FileSystem } from "../filesystem"
|
||||
|
|
@ -10,7 +10,6 @@ import { FSUtil } from "../fs-util"
|
|||
import { Location } from "../location"
|
||||
import { Ripgrep } from "../ripgrep"
|
||||
import { RelativePath } from "../schema"
|
||||
import { Flag } from "../flag/flag"
|
||||
|
||||
export interface Interface {
|
||||
readonly find: (input: FileSystem.FindInput) => Effect.Effect<FileSystem.Entry[]>
|
||||
|
|
@ -18,6 +17,11 @@ export interface Interface {
|
|||
readonly grep: (input: FileSystem.GrepInput) => Effect.Effect<readonly FileSystem.Match[]>
|
||||
}
|
||||
|
||||
export const Options = Schema.Struct({
|
||||
fff: Schema.optional(Schema.Boolean),
|
||||
})
|
||||
export type Options = typeof Options.Type
|
||||
|
||||
export class Service extends Context.Service<Service, Interface>()("@opencode/v2/FileSystem/Search") {}
|
||||
|
||||
export const ripgrepLayer = Layer.effect(
|
||||
|
|
@ -232,13 +236,18 @@ export const fffLayer = Layer.effect(
|
|||
}),
|
||||
)
|
||||
|
||||
const layer = Layer.unwrap(
|
||||
export const layer = (options?: Options) => Layer.unwrap(
|
||||
Effect.gen(function* () {
|
||||
if (Flag.OPENCODE_DISABLE_FFF || !Fff.available()) return ripgrepLayer
|
||||
if (options?.fff === false || (options?.fff === undefined && process.platform === "win32") || !Fff.available())
|
||||
return ripgrepLayer
|
||||
const location = yield* Location.Service
|
||||
// Non-VCS locations can contain many repositories, so avoid eagerly content-indexing the entire aggregate tree.
|
||||
return location.vcs ? fffLayer : ripgrepLayer
|
||||
}),
|
||||
)
|
||||
|
||||
export const node = makeLocationNode({ service: Service, layer, deps: [FSUtil.node, Location.node, Ripgrep.node] })
|
||||
export function nodeWith(options?: Options) {
|
||||
return makeLocationNode({ service: Service, layer: layer(options), deps: [FSUtil.node, Location.node, Ripgrep.node] })
|
||||
}
|
||||
|
||||
export const node = nodeWith()
|
||||
|
|
|
|||
|
|
@ -5,9 +5,8 @@ import { createWrapper } from "@parcel/watcher/wrapper"
|
|||
import type ParcelWatcher from "@parcel/watcher"
|
||||
import { FileSystem } from "@opencode-ai/schema/filesystem"
|
||||
import { makeGlobalNode } from "../effect/app-node"
|
||||
import { Cause, Context, Effect, Layer, PubSub, Scope, Stream } from "effect"
|
||||
import { Cause, Context, Effect, Layer, PubSub, Schema, Scope, Stream } from "effect"
|
||||
import { KeyedMutex } from "../effect/keyed-mutex"
|
||||
import { Flag } from "../flag/flag"
|
||||
import { lazy } from "../util/lazy"
|
||||
import { watch as watchFileSystem } from "node:fs"
|
||||
import path from "path"
|
||||
|
|
@ -50,14 +49,19 @@ export interface Interface {
|
|||
readonly subscribe: (input: WatchInput) => Stream.Stream<Update>
|
||||
}
|
||||
|
||||
export const Options = Schema.Struct({
|
||||
enabled: Schema.optional(Schema.Boolean),
|
||||
})
|
||||
export type Options = typeof Options.Type
|
||||
|
||||
export class Service extends Context.Service<Service, Interface>()("@opencode/Watcher") {}
|
||||
|
||||
const layer = Layer.effect(
|
||||
export const layer = (options?: Options) => Layer.effect(
|
||||
Service,
|
||||
Effect.gen(function* () {
|
||||
const backend = getBackend()
|
||||
const native = watcher()
|
||||
if (Flag.OPENCODE_DISABLE_FILEWATCHER) {
|
||||
if (options?.enabled === false) {
|
||||
return Service.of({ subscribe: () => Stream.empty })
|
||||
}
|
||||
|
||||
|
|
@ -140,7 +144,11 @@ const layer = Layer.effect(
|
|||
}),
|
||||
)
|
||||
|
||||
export const node = makeGlobalNode({ service: Service, layer, deps: [] })
|
||||
export function nodeWith(options?: Options) {
|
||||
return makeGlobalNode({ service: Service, layer: layer(options), deps: [] })
|
||||
}
|
||||
|
||||
export const node = nodeWith()
|
||||
|
||||
function subscribeDirectory(
|
||||
native: typeof import("@parcel/watcher") | undefined,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue