summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/context/command.tsx
diff options
context:
space:
mode:
authorBrendan Allan <[email protected]>2026-03-18 14:46:53 +0800
committerBrendan Allan <[email protected]>2026-03-18 14:46:53 +0800
commita43783a6d47a069ca2fd187c378b8e9899093b37 (patch)
tree974ec59f81702c5f1fce235886e887f5b15a1e91 /packages/app/src/context/command.tsx
parent37c52951116e7529a8325f051e18a6dbe3defb60 (diff)
downloadopencode-a43783a6d47a069ca2fd187c378b8e9899093b37.tar.gz
opencode-a43783a6d47a069ca2fd187c378b8e9899093b37.zip
app: initialize command catalog more efficiently
cuts down load times by like 30-50%
Diffstat (limited to 'packages/app/src/context/command.tsx')
-rw-r--r--packages/app/src/context/command.tsx34
1 files changed, 19 insertions, 15 deletions
diff --git a/packages/app/src/context/command.tsx b/packages/app/src/context/command.tsx
index 2c6799d12..65805f40c 100644
--- a/packages/app/src/context/command.tsx
+++ b/packages/app/src/context/command.tsx
@@ -1,10 +1,10 @@
-import { createEffect, createMemo, onCleanup, onMount, type Accessor } from "solid-js"
-import { createStore } from "solid-js/store"
import { createSimpleContext } from "@opencode-ai/ui/context"
import { useDialog } from "@opencode-ai/ui/context/dialog"
-import { dict as en } from "@/i18n/en"
+import { type Accessor, createEffect, createMemo, onCleanup, onMount } from "solid-js"
+import { createStore } from "solid-js/store"
import { useLanguage } from "@/context/language"
import { useSettings } from "@/context/settings"
+import { dict as en } from "@/i18n/en"
import { Persist, persisted } from "@/utils/persist"
const IS_MAC = typeof navigator === "object" && /(Mac|iPod|iPhone|iPad)/.test(navigator.platform)
@@ -238,9 +238,10 @@ export const { use: useCommand, provider: CommandProvider } = createSimpleContex
})
const warnedDuplicates = new Set<string>()
+ type CommandCatalog = Record<string, CommandCatalogItem>
const [catalog, setCatalog, _, catalogReady] = persisted(
Persist.global("command.catalog.v1"),
- createStore<Record<string, CommandCatalogItem>>({}),
+ createStore<CommandCatalog>({}),
)
const bind = (id: string, def: KeybindConfig | undefined) => {
@@ -259,7 +260,7 @@ export const { use: useCommand, provider: CommandProvider } = createSimpleContex
if (seen.has(opt.id)) {
if (import.meta.env.DEV && !warnedDuplicates.has(opt.id)) {
warnedDuplicates.add(opt.id)
- console.warn(`[command] duplicate command id \"${opt.id}\" registered; keeping first entry`)
+ console.warn(`[command] duplicate command id "${opt.id}" registered; keeping first entry`)
}
continue
}
@@ -274,16 +275,19 @@ export const { use: useCommand, provider: CommandProvider } = createSimpleContex
createEffect(() => {
if (!catalogReady()) return
- for (const opt of registered()) {
- const id = actionId(opt.id)
- setCatalog(id, {
- title: opt.title,
- description: opt.description,
- category: opt.category,
- keybind: opt.keybind,
- slash: opt.slash,
- })
- }
+ setCatalog(
+ registered().reduce((acc, opt) => {
+ const id = actionId(opt.id)
+ acc[id] = {
+ title: opt.title,
+ description: opt.description,
+ category: opt.category,
+ keybind: opt.keybind,
+ slash: opt.slash,
+ }
+ return acc
+ }, {} as CommandCatalog),
+ )
})
const catalogOptions = createMemo(() => Object.entries(catalog).map(([id, meta]) => ({ id, ...meta })))