@@ -4,13 +4,11 @@ import type { PlatformError } from "effect/PlatformError" |
4 | 4 | import { FSUtil } from "../fs-util" |
5 | 5 | import { Glob } from "../util/glob" |
6 | 6 | import { Global } from "../global" |
7 | | -import * as Log from "../util/log" |
8 | 7 | import { serviceUse } from "../effect/service-use" |
9 | 8 | import { makeRuntime } from "../effect/runtime" |
10 | 9 | import { Fff } from "#fff" |
11 | 10 | import { Ripgrep } from "./ripgrep" |
12 | 11 |
|
13 | | -const log = Log.create({ service: "file.search" }) |
14 | 12 | const root = path.join(Global.Path.cache, "fff") |
15 | 13 |
|
16 | 14 | export type Item = Ripgrep.Item |
@@ -220,12 +218,14 @@ export const layer: Layer.Layer<Service, never, FSUtil.Service | Ripgrep.Service |
220 | 218 | if (!scanned.ok || !scanned.value) { |
221 | 219 | yield* fffSync("destroy picker", () => pick.destroy()).pipe(Effect.ignore) |
222 | 220 | state.pick.delete(dir) |
223 | | - log.warn("fff scan not ready", { dir }) |
| 221 | + yield* Effect.logWarning("fff scan not ready", { dir }) |
224 | 222 | return yield* Effect.fail(new Error(scanned.ok ? "fff scan timed out" : scanned.error)) |
225 | 223 | } |
226 | 224 |
|
227 | 225 | const git = yield* fffSync("refresh git status", () => pick.refreshGitStatus()) |
228 | | - if (!git.ok) log.warn("fff git refresh failed", { dir, error: git.error }) |
| 226 | + if (!git.ok) { |
| 227 | + yield* Effect.logWarning("fff git refresh failed", { dir, error: git.error }) |
| 228 | + } |
229 | 229 | }) |
230 | 230 |
|
231 | 231 | // Create (or return) the picker for a directory. Creation is synchronous |
@@ -244,10 +244,7 @@ export const layer: Layer.Layer<Service, never, FSUtil.Service | Ripgrep.Service |
244 | 244 | if (pending) return yield* Deferred.await(pending) |
245 | 245 |
|
246 | 246 | const available = yield* fffSync("check availability", () => Fff.available()).pipe( |
247 | | - Effect.catch((error) => { |
248 | | - log.warn("fff availability check failed", { error }) |
249 | | - return Effect.succeed(false) |
250 | | - }), |
| 247 | + Effect.catch((error) => Effect.logWarning("fff availability check failed", { error }).pipe(Effect.as(false))), |
251 | 248 | ) |
252 | 249 | if (!available) return undefined |
253 | 250 |
|
@@ -272,7 +269,7 @@ export const layer: Layer.Layer<Service, never, FSUtil.Service | Ripgrep.Service |
272 | 269 | }), |
273 | 270 | ) |
274 | 271 | if (!made.ok) { |
275 | | - log.warn("fff init failed", { dir, error: made.error }) |
| 272 | + yield* Effect.logWarning("fff init failed", { dir, error: made.error }) |
276 | 273 | const err = new Error(made.error) |
277 | 274 | yield* Deferred.fail(gate, err) |
278 | 275 | return yield* Effect.fail(err) |
@@ -355,14 +352,15 @@ export const layer: Layer.Layer<Service, never, FSUtil.Service | Ripgrep.Service |
355 | 352 | pageSize: limit, |
356 | 353 | }), |
357 | 354 | ).pipe( |
358 | | - Effect.catch((error) => { |
359 | | - log.warn(`fff ${kind} search failed`, { dir, query, error }) |
360 | | - return Effect.succeed<Fff.Result<string[]> | undefined>(undefined) |
361 | | - }), |
| 355 | + Effect.catch((error) => |
| 356 | + Effect.logWarning(`fff ${kind} search failed`, { dir, query, error }).pipe( |
| 357 | + Effect.as<Fff.Result<string[]> | undefined>(undefined), |
| 358 | + ), |
| 359 | + ), |
362 | 360 | ) |
363 | 361 | if (!fffResult) return undefined |
364 | 362 | if (!fffResult.ok) { |
365 | | - log.warn(`fff ${kind} search failed`, { dir, query, error: fffResult.error }) |
| 363 | + yield* Effect.logWarning(`fff ${kind} search failed`, { dir, query, error: fffResult.error }) |
366 | 364 | return undefined |
367 | 365 | } |
368 | 366 |
|
@@ -393,14 +391,15 @@ export const layer: Layer.Layer<Service, never, FSUtil.Service | Ripgrep.Service |
393 | 391 | timeBudgetMs: 1_500, |
394 | 392 | }), |
395 | 393 | ).pipe( |
396 | | - Effect.catch((error) => { |
397 | | - log.warn("fff grep failed", { dir, pattern: input.pattern, error }) |
398 | | - return Effect.succeed<Fff.Result<Fff.Grep> | undefined>(undefined) |
399 | | - }), |
| 394 | + Effect.catch((error) => |
| 395 | + Effect.logWarning("fff grep failed", { dir, pattern: input.pattern, error }).pipe( |
| 396 | + Effect.as<Fff.Result<Fff.Grep> | undefined>(undefined), |
| 397 | + ), |
| 398 | + ), |
400 | 399 | ) |
401 | 400 | if (!fffGrep) return yield* rip(input) |
402 | 401 | if (!fffGrep.ok) { |
403 | | - log.warn("fff grep failed", { dir, pattern: input.pattern, error: fffGrep.error }) |
| 402 | + yield* Effect.logWarning("fff grep failed", { dir, pattern: input.pattern, error: fffGrep.error }) |
404 | 403 | return yield* rip(input) |
405 | 404 | } |
406 | 405 |
|
@@ -432,10 +431,11 @@ export const layer: Layer.Layer<Service, never, FSUtil.Service | Ripgrep.Service |
432 | 431 | pageSize: limit, |
433 | 432 | }), |
434 | 433 | ).pipe( |
435 | | - Effect.catch((error) => { |
436 | | - log.warn("fff glob failed", { dir, pattern: input.pattern, error }) |
437 | | - return Effect.succeed<Fff.Result<Fff.Search> | undefined>(undefined) |
438 | | - }), |
| 434 | + Effect.catch((error) => |
| 435 | + Effect.logWarning("fff glob failed", { dir, pattern: input.pattern, error }).pipe( |
| 436 | + Effect.as<Fff.Result<Fff.Search> | undefined>(undefined), |
| 437 | + ), |
| 438 | + ), |
439 | 439 | ) |
440 | 440 |
|
441 | 441 | if (fffGlob?.ok) { |
@@ -453,7 +453,7 @@ export const layer: Layer.Layer<Service, never, FSUtil.Service | Ripgrep.Service |
453 | 453 | truncated: fffGlob.value.totalMatched > rows.length, |
454 | 454 | } |
455 | 455 | } else if (fffGlob) { |
456 | | - log.warn("fff glob failed", { dir, pattern: input.pattern, error: fffGlob.error }) |
| 456 | + yield* Effect.logWarning("fff glob failed", { dir, pattern: input.pattern, error: fffGlob.error }) |
457 | 457 | // fall through to the fallback |
458 | 458 | } |
459 | 459 | } |
@@ -500,13 +500,16 @@ export const layer: Layer.Layer<Service, never, FSUtil.Service | Ripgrep.Service |
500 | 500 | if (!entry) return |
501 | 501 |
|
502 | 502 | const out = yield* fffSync("track query", () => entry.pick.trackQuery(row.text, file)).pipe( |
503 | | - Effect.catch((error) => { |
504 | | - log.warn("fff track query failed", { dir: row.dir, query: row.text, file, error }) |
505 | | - return Effect.succeed<Fff.Result<boolean> | undefined>(undefined) |
506 | | - }), |
| 503 | + Effect.catch((error) => |
| 504 | + Effect.logWarning("fff track query failed", { dir: row.dir, query: row.text, file, error }).pipe( |
| 505 | + Effect.as<Fff.Result<boolean> | undefined>(undefined), |
| 506 | + ), |
| 507 | + ), |
507 | 508 | ) |
508 | 509 | if (!out) return |
509 | | - if (!out.ok) log.warn("fff track query failed", { dir: row.dir, query: row.text, file, error: out.error }) |
| 510 | + if (!out.ok) { |
| 511 | + yield* Effect.logWarning("fff track query failed", { dir: row.dir, query: row.text, file, error: out.error }) |
| 512 | + } |
510 | 513 | }) |
511 | 514 |
|
512 | 515 | return Service.of({ files, tree, search, file, glob, open, warm, release }) |
|