Prechádzať zdrojové kódy

fix: git branch filewatcher, add flag to completely disable watcher

Aiden Cline 2 mesiacov pred
rodič
commit
7e3ad770ac

+ 20 - 8
packages/opencode/src/file/watcher.ts

@@ -5,11 +5,13 @@ import { Instance } from "../project/instance"
 import { Log } from "../util/log"
 import { FileIgnore } from "./ignore"
 import { Config } from "../config/config"
+import path from "path"
 // @ts-ignore
 import { createWrapper } from "@parcel/watcher/wrapper"
 import { lazy } from "@/util/lazy"
 import type ParcelWatcher from "@parcel/watcher"
 import { $ } from "bun"
+import { Flag } from "@/flag/flag"
 
 declare const OPENCODE_LIBC: string | undefined
 
@@ -57,17 +59,24 @@ export namespace FileWatcher {
         }
       }
 
-      const subs = []
+      const subs: ParcelWatcher.AsyncSubscription[] = []
       const cfgIgnores = cfg.watcher?.ignore ?? []
 
-      subs.push(
-        await watcher().subscribe(Instance.directory, subscribe, {
-          ignore: [...FileIgnore.PATTERNS, ...cfgIgnores],
-          backend,
-        }),
-      )
+      if (Flag.OPENCODE_EXPERIMENTAL_FILEWATCHER) {
+        subs.push(
+          await watcher().subscribe(Instance.directory, subscribe, {
+            ignore: [...FileIgnore.PATTERNS, ...cfgIgnores],
+            backend,
+          }),
+        )
+      }
 
-      const vcsDir = await $`git rev-parse --git-dir`.quiet().nothrow().cwd(Instance.worktree).text()
+      const vcsDir = await $`git rev-parse --git-dir`
+        .quiet()
+        .nothrow()
+        .cwd(Instance.worktree)
+        .text()
+        .then((x) => path.resolve(Instance.worktree, x.trim()))
       if (vcsDir && !cfgIgnores.includes(".git") && !cfgIgnores.includes(vcsDir)) {
         subs.push(
           await watcher().subscribe(vcsDir, subscribe, {
@@ -86,6 +95,9 @@ export namespace FileWatcher {
   )
 
   export function init() {
+    if (Flag.OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER) {
+      return
+    }
     state()
   }
 }

+ 2 - 0
packages/opencode/src/flag/flag.ts

@@ -17,6 +17,8 @@ export namespace Flag {
 
   // Experimental
   export const OPENCODE_EXPERIMENTAL = truthy("OPENCODE_EXPERIMENTAL")
+  export const OPENCODE_EXPERIMENTAL_FILEWATCHER = truthy("OPENCODE_EXPERIMENTAL_FILEWATCHER")
+  export const OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER = truthy("OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER")
   export const OPENCODE_EXPERIMENTAL_ICON_DISCOVERY =
     OPENCODE_EXPERIMENTAL || truthy("OPENCODE_EXPERIMENTAL_ICON_DISCOVERY")
   export const OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT = truthy("OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT")

+ 1 - 0
packages/web/src/content/docs/cli.mdx

@@ -325,3 +325,4 @@ These environment variables enable experimental features that may change or be r
 | `OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT`  | boolean | Disable copy on select in TUI           |
 | `OPENCODE_EXPERIMENTAL_BASH_MAX_OUTPUT_LENGTH`  | number  | Max output length for bash commands     |
 | `OPENCODE_EXPERIMENTAL_BASH_DEFAULT_TIMEOUT_MS` | number  | Default timeout for bash commands in ms |
+| `OPENCODE_EXPERIMENTAL_FILEWATCHER`             | boolean | Enable file watcher for entire dir      |