chore: generate
This commit is contained in:
parent
106f8e94d6
commit
21a644fef5
@ -3,12 +3,7 @@ import { mkdir, symlink } from "node:fs/promises"
|
||||
import os from "node:os"
|
||||
import path from "node:path"
|
||||
import { afterEach, expect, spyOn, test } from "bun:test"
|
||||
import {
|
||||
isZedTerminal,
|
||||
offsetToPosition,
|
||||
resolveZedDbPath,
|
||||
resolveZedSelection,
|
||||
} from "@opencode-ai/tui/editor-zed"
|
||||
import { isZedTerminal, offsetToPosition, resolveZedDbPath, resolveZedSelection } from "@opencode-ai/tui/editor-zed"
|
||||
import { tmpdir } from "../../fixture/fixture"
|
||||
|
||||
const originalZedTerm = process.env.ZED_TERM
|
||||
|
||||
@ -35,13 +35,10 @@ function mountEditorContext(WebSocketImpl?: typeof WebSocket) {
|
||||
|
||||
const value = process.env.CLAUDE_CODE_SSE_PORT || process.env.OPENCODE_EDITOR_SSE_PORT
|
||||
return (
|
||||
<TestTuiContexts
|
||||
cwd={process.cwd()}
|
||||
paths={{ home: os.homedir() }}
|
||||
>
|
||||
<EditorContextProvider integration={editorService} WebSocketImpl={WebSocketImpl}>
|
||||
<Consumer />
|
||||
</EditorContextProvider>
|
||||
<TestTuiContexts cwd={process.cwd()} paths={{ home: os.homedir() }}>
|
||||
<EditorContextProvider integration={editorService} WebSocketImpl={WebSocketImpl}>
|
||||
<Consumer />
|
||||
</EditorContextProvider>
|
||||
</TestTuiContexts>
|
||||
)
|
||||
})
|
||||
|
||||
@ -73,7 +73,11 @@ export async function read() {
|
||||
if (text) return { data: text, mime: "text/plain" }
|
||||
}
|
||||
|
||||
export function copyCommand(os: NodeJS.Platform, wayland: boolean, has: (name: string) => boolean): string[] | undefined {
|
||||
export function copyCommand(
|
||||
os: NodeJS.Platform,
|
||||
wayland: boolean,
|
||||
has: (name: string) => boolean,
|
||||
): string[] | undefined {
|
||||
if (os === "darwin" && has("osascript")) return ["osascript"]
|
||||
if (os === "linux" && wayland && has("wl-copy")) return ["wl-copy"]
|
||||
if (os === "linux" && has("xclip")) return ["xclip", "-selection", "clipboard"]
|
||||
|
||||
@ -6,11 +6,7 @@ import { useClipboard } from "../context/clipboard"
|
||||
import { InstallationVersion } from "@opencode-ai/core/installation/version"
|
||||
import { destroyRenderer } from "../util/renderer"
|
||||
|
||||
export function ErrorComponent(props: {
|
||||
error: Error
|
||||
reset: () => void
|
||||
mode?: "dark" | "light"
|
||||
}) {
|
||||
export function ErrorComponent(props: { error: Error; reset: () => void; mode?: "dark" | "light" }) {
|
||||
const term = useTerminalDimensions()
|
||||
const renderer = useRenderer()
|
||||
const clipboard = useClipboard()
|
||||
|
||||
@ -116,7 +116,8 @@ export const { use: useEditorContext, provider: EditorContextProvider } = create
|
||||
const editor = props.integration ?? editorIntegration
|
||||
const value = process.env.CLAUDE_CODE_SSE_PORT || process.env.OPENCODE_EDITOR_SSE_PORT
|
||||
const parsedPort = value ? Number.parseInt(value, 10) : undefined
|
||||
const port = parsedPort && Number.isInteger(parsedPort) && parsedPort > 0 && parsedPort <= 65535 ? parsedPort : undefined
|
||||
const port =
|
||||
parsedPort && Number.isInteger(parsedPort) && parsedPort > 0 && parsedPort <= 65535 ? parsedPort : undefined
|
||||
const zedTerminal = process.env.ZED_TERM === "true" || process.env.TERM_PROGRAM?.toLowerCase() === "zed"
|
||||
const mentionListeners = new Set<(mention: EditorMention) => void>()
|
||||
const WebSocketImpl = props.WebSocketImpl ?? WebSocket
|
||||
@ -319,9 +320,7 @@ export const { use: useEditorContext, provider: EditorContextProvider } = create
|
||||
|
||||
return {
|
||||
enabled() {
|
||||
return Boolean(
|
||||
resolveEditorConnection(directory, port, editor.connection) || (zedTerminal && editor.selection),
|
||||
)
|
||||
return Boolean(resolveEditorConnection(directory, port, editor.connection) || (zedTerminal && editor.selection))
|
||||
},
|
||||
connected() {
|
||||
return store.status === "connected"
|
||||
|
||||
@ -19,7 +19,7 @@ export const { use: useKV, provider: KVProvider } = createSimpleContext({
|
||||
// Queue same-process writes so rapid updates persist in order.
|
||||
let write = Promise.resolve()
|
||||
|
||||
;Flock.withLock(lock, () => readJson<Record<string, unknown>>(file))
|
||||
Flock.withLock(lock, () => readJson<Record<string, unknown>>(file))
|
||||
.then((x) => {
|
||||
setStore(x)
|
||||
})
|
||||
@ -55,9 +55,7 @@ export const { use: useKV, provider: KVProvider } = createSimpleContext({
|
||||
setStore(key, value)
|
||||
const snapshot = structuredClone(unwrap(store))
|
||||
write = write
|
||||
.then(() =>
|
||||
Flock.withLock(lock, () => writeJsonAtomic(file, snapshot)),
|
||||
)
|
||||
.then(() => Flock.withLock(lock, () => writeJsonAtomic(file, snapshot)))
|
||||
.catch((error) => {
|
||||
console.error("Failed to write KV state", { error })
|
||||
})
|
||||
|
||||
@ -52,7 +52,11 @@ function search<T>(items: T[], target: string, key: (item: T) => string) {
|
||||
return { found: false, index: left }
|
||||
}
|
||||
|
||||
export const { context: SyncContext, use: useSync, provider: SyncProvider } = createSimpleContext({
|
||||
export const {
|
||||
context: SyncContext,
|
||||
use: useSync,
|
||||
provider: SyncProvider,
|
||||
} = createSimpleContext({
|
||||
name: "Sync",
|
||||
init: () => {
|
||||
const startup = useTuiStartup()
|
||||
|
||||
@ -52,10 +52,10 @@ const themeSource: ThemeSource = {
|
||||
export async function discoverThemes(directories: string[]) {
|
||||
const result: Record<string, unknown> = {}
|
||||
for (const directory of directories) {
|
||||
const files = await Glob.scan("themes/*.json", { cwd: directory, absolute: true, dot: true, symlink: true })
|
||||
for (const file of files) {
|
||||
result[path.basename(file, ".json")] = JSON.parse(await readFile(file, "utf8")) as unknown
|
||||
}
|
||||
const files = await Glob.scan("themes/*.json", { cwd: directory, absolute: true, dot: true, symlink: true })
|
||||
for (const file of files) {
|
||||
result[path.basename(file, ".json")] = JSON.parse(await readFile(file, "utf8")) as unknown
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@ -16,9 +16,7 @@ function Directory(props: { api: TuiPluginApi }) {
|
||||
if (!selected || selected.type === "new") return
|
||||
const out = abbreviateHome(selected.directory, paths.home)
|
||||
const branch =
|
||||
selected.directory === (props.api.state.path.directory || paths.cwd)
|
||||
? props.api.state.vcs?.branch
|
||||
: undefined
|
||||
selected.directory === (props.api.state.path.directory || paths.cwd) ? props.api.state.vcs?.branch : undefined
|
||||
if (branch) return out + ":" + branch
|
||||
return out
|
||||
})
|
||||
|
||||
@ -467,7 +467,8 @@ export function Session() {
|
||||
},
|
||||
run: async () => {
|
||||
const copy = (url: string) =>
|
||||
clipboard.write?.(url)
|
||||
clipboard
|
||||
.write?.(url)
|
||||
.then(() => toast.show({ message: "Share URL copied to clipboard!", variant: "success" }))
|
||||
.catch(() => toast.show({ message: "Failed to copy URL to clipboard", variant: "error" }))
|
||||
const url = session()?.share?.url
|
||||
@ -902,7 +903,8 @@ export function Session() {
|
||||
return
|
||||
}
|
||||
|
||||
clipboard.write?.(text)
|
||||
clipboard
|
||||
.write?.(text)
|
||||
.then(() => toast.show({ message: "Message copied to clipboard!", variant: "success" }))
|
||||
.catch(() => toast.show({ message: "Failed to copy to clipboard", variant: "error" }))
|
||||
dialog.clear()
|
||||
|
||||
@ -45,15 +45,15 @@ export async function mount(override?: FetchHandler, state?: string) {
|
||||
const app = await testRender(() => (
|
||||
<TestTuiContexts paths={state ? { state } : undefined}>
|
||||
<ArgsProvider>
|
||||
<KVProvider>
|
||||
<SDKProvider url="http://test" directory={directory} fetch={calls.fetch} events={events.source}>
|
||||
<ProjectProvider>
|
||||
<SyncProvider>
|
||||
<Probe />
|
||||
</SyncProvider>
|
||||
</ProjectProvider>
|
||||
</SDKProvider>
|
||||
</KVProvider>
|
||||
<KVProvider>
|
||||
<SDKProvider url="http://test" directory={directory} fetch={calls.fetch} events={events.source}>
|
||||
<ProjectProvider>
|
||||
<SyncProvider>
|
||||
<Probe />
|
||||
</SyncProvider>
|
||||
</ProjectProvider>
|
||||
</SDKProvider>
|
||||
</KVProvider>
|
||||
</ArgsProvider>
|
||||
</TestTuiContexts>
|
||||
))
|
||||
|
||||
@ -1,10 +1,7 @@
|
||||
import { expect, test } from "bun:test"
|
||||
import { testRender } from "@opentui/solid"
|
||||
import { abbreviateHome } from "../src/runtime"
|
||||
import {
|
||||
TuiPathsProvider,
|
||||
useTuiPaths,
|
||||
} from "../src/context/runtime"
|
||||
import { TuiPathsProvider, useTuiPaths } from "../src/context/runtime"
|
||||
|
||||
test("abbreviates paths within home boundaries", () => {
|
||||
expect(abbreviateHome("/home/test", "/home/test")).toBe("~")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user