Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/opencode/src/cli/cmd/tui/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { DialogProvider, useDialog } from "@tui/ui/dialog"
import { DialogProvider as DialogProviderList } from "@tui/component/dialog-provider"
import { ErrorComponent } from "@tui/component/error-component"
import { PluginRouteMissing } from "@tui/component/plugin-route-missing"
import { ProjectProvider } from "@tui/context/project"
import { ProjectProvider, useProject } from "@tui/context/project"
import { EditorContextProvider } from "@tui/context/editor"
import { useEvent } from "@tui/context/event"
import { SDKProvider, useSDK } from "@tui/context/sdk"
Expand Down Expand Up @@ -279,6 +279,7 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
const themeState = useTheme()
const { theme, mode, setMode, locked, lock, unlock } = themeState
const sync = useSync()
const project = useProject()
const exit = useExit()
const promptRef = usePromptRef()
const routes: RouteMap = new Map()
Expand All @@ -304,6 +305,7 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
toast,
renderer,
attention,
project,
})
const [ready, setReady] = createSignal(false)
TuiPluginRuntime.init({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @jsxImportSource @opentui/solid */
import type { TuiPlugin, TuiPluginApi } from "@opencode-ai/plugin/tui"
import type { TuiPlugin, TuiPluginApi, TuiRouteCurrent } from "@opencode-ai/plugin/tui"
import type { SnapshotFileDiff, VcsFileDiff } from "@opencode-ai/sdk/v2"
import type { BoxRenderable, ScrollBoxRenderable } from "@opentui/core"
import { LANGUAGE_EXTENSIONS } from "@/lsp/language"
Expand Down Expand Up @@ -61,7 +61,7 @@ function DiffViewer(props: { api: TuiPluginApi }) {
const theme = () => props.api.theme.current
const params = () =>
("params" in props.api.route.current ? props.api.route.current.params : undefined) as
| { mode?: DiffMode; sessionID?: string; messageID?: string }
| { mode?: DiffMode; sessionID?: string; messageID?: string; returnTo?: TuiRouteCurrent }
| undefined
const mode = () => params()?.mode ?? "git"
const diffInput = createMemo(() => ({
Expand All @@ -80,7 +80,10 @@ function DiffViewer(props: { api: TuiPluginApi }) {
return normalizeDiffs(result.data ?? [])
}

const result = await props.api.client.vcs.diff({ mode: "git" }, { throwOnError: true })
const result = await props.api.client.vcs.diff(
{ mode: "git", workspace: props.api.workspace.current() },
{ throwOnError: true },
)
return normalizeDiffs(result.data ?? [])
})
const files = createMemo(() => diff() ?? [])
Expand Down Expand Up @@ -250,7 +253,8 @@ function DiffViewer(props: { api: TuiPluginApi }) {
title: "Close diff viewer",
category: "VCS",
run() {
props.api.route.navigate("home")
const target = params()?.returnTo ?? ({ name: "home" } satisfies TuiRouteCurrent)
props.api.route.navigate(target.name, "params" in target ? target.params : undefined)
},
},
{
Expand Down Expand Up @@ -446,6 +450,7 @@ function DiffViewer(props: { api: TuiPluginApi }) {
mode: option.value,
sessionID: params()?.sessionID,
messageID: params()?.messageID,
returnTo: params()?.returnTo,
})
},
}))}
Expand Down Expand Up @@ -672,6 +677,12 @@ const tui: TuiPlugin = async (api) => {
api.route.navigate(ROUTE, {
mode: "git",
sessionID: "params" in api.route.current ? api.route.current.params?.sessionID : undefined,
returnTo: {
name: api.route.current.name,
...("params" in api.route.current && api.route.current.params
? { params: api.route.current.params }
: {}),
},
})
api.ui.dialog.clear()
},
Expand Down
7 changes: 7 additions & 0 deletions packages/opencode/src/cli/cmd/tui/plugin/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Dialog as DialogUI, type useDialog } from "@tui/ui/dialog"
import type { TuiConfig } from "@/cli/cmd/tui/config/tui"
import type { useOpencodeKeymap } from "../keymap"
import type { useKV } from "../context/kv"
import type { useProject } from "../context/project"
import { DialogAlert } from "../ui/dialog-alert"
import { DialogConfirm } from "../ui/dialog-confirm"
import { DialogPrompt } from "../ui/dialog-prompt"
Expand Down Expand Up @@ -41,6 +42,7 @@ type Input = {
toast: ReturnType<typeof useToast>
renderer: TuiPluginApi["renderer"]
attention: TuiPluginApi["attention"]
project: ReturnType<typeof useProject>
}

function routeRegister(routes: RouteMap, list: TuiRouteDefinition[], bump: () => void) {
Expand Down Expand Up @@ -227,6 +229,11 @@ export function createTuiApi(input: Input): TuiPluginApi {
return Keymap.getOpencodeModeStack(input.keymap).push(mode)
},
},
workspace: {
current() {
return input.project.workspace.current()
},
},
route: {
register(list) {
return routeRegister(input.routes, list, input.bump)
Expand Down
1 change: 1 addition & 0 deletions packages/opencode/src/cli/cmd/tui/plugin/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ function pluginApi(runtime: RuntimeState, plugin: PluginEntry, scope: PluginScop
keys: api.keys,
keymap,
mode: createScopedMode(api.mode, scope),
workspace: api.workspace,
route,
ui: api.ui,
tuiConfig: api.tuiConfig,
Expand Down
3 changes: 3 additions & 0 deletions packages/opencode/test/fixture/tui-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ export function createTuiPluginApi(opts: Opts = {}): HostPluginApi {
current: () => "base",
push: () => () => {},
},
workspace: {
current: () => undefined,
},
route: {
register: () => {
if (count) count.route_add += 1
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/src/tui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,6 @@ export type TuiPluginInstallResult =

export type TuiWorkspace = {
current: () => string | undefined
set: (workspaceID?: string) => void
}

export type TuiPluginApi = {
Expand All @@ -595,6 +594,7 @@ export type TuiPluginApi = {
keys: TuiKeys
keymap: TuiKeymap
mode: TuiModeApi
workspace: TuiWorkspace
route: {
register: (routes: TuiRouteDefinition[]) => () => void
navigate: (name: string, params?: Record<string, unknown>) => void
Expand Down
Loading