/
Alex_Ural
/
opencode
Обзор
Документация
Войти
/
Alex_Ural
/
opencode
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
packages/app/src/context/file/watcher.ts
53 строки
1 KB
Adam
fix(app): update tab file contents on change
09 фев 2026, 16:38
Не верифицирован
09 фев 2026, 16:38
30f0d3b
Код
Авторство
О чём код?
import type { FileNode } from "@opencode-ai/sdk/v2" type WatcherEvent = { type: string properties: unknown } type WatcherOps = { normalize: (input: string) => string hasFile: (path: string) => boolean isOpen?: (path: string) => boolean loadFile: (path: string) => void node: (path: string) => FileNode | undefined isDirLoaded: (path: string) => boolean refreshDir: (path: string) => void } export function invalidateFromWatcher(event: WatcherEvent, ops: WatcherOps) { if (event.type !== "file.watcher.updated") return const props = typeof event.properties === "object" && event.properties ? (event.properties as Record<string, unknown>) : undefined const rawPath = typeof props?.file === "string" ? props.file : undefined const kind = typeof props?.event === "string" ? props.event : undefined if (!rawPath) return if (!kind) return const path = ops.normalize(rawPath) if (!path) return if (path.startsWith(".git/")) return if (ops.hasFile(path) || ops.isOpen?.(path)) { ops.loadFile(path) } if (kind === "change") { const dir = (() => { if (path === "") return "" const node = ops.node(path) if (node?.type !== "directory") return return path })() if (dir === undefined) return if (!ops.isDirLoaded(dir)) return ops.refreshDir(dir) return } if (kind !== "add" && kind !== "unlink") return const parent = path.split("/").slice(0, -1).join("/") if (!ops.isDirLoaded(parent)) return ops.refreshDir(parent) }