mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-28 07:15:10 +00:00
internal which-key plugin, inactive by default (#26337)
This commit is contained in:
@@ -156,3 +156,45 @@ test("kv plugin_enabled overrides tui config on startup", async () => {
|
||||
delete process.env.OPENCODE_PLUGIN_META_FILE
|
||||
}
|
||||
})
|
||||
|
||||
test("loads disabled-by-default internal plugin inactive and activates on demand", async () => {
|
||||
await using tmp = await tmpdir()
|
||||
const config = createTuiResolvedConfig()
|
||||
const wait = spyOn(TuiConfig, "waitForDependencies").mockResolvedValue()
|
||||
const cwd = spyOn(process, "cwd").mockImplementation(() => tmp.path)
|
||||
const api = createTuiPluginApi()
|
||||
|
||||
try {
|
||||
await TuiPluginRuntime.init({ api, config })
|
||||
|
||||
expect(TuiPluginRuntime.list().find((item) => item.id === "internal:plugin-manager")).toMatchObject({
|
||||
enabled: true,
|
||||
active: true,
|
||||
})
|
||||
expect(TuiPluginRuntime.list().find((item) => item.id === "tui-which-key")).toEqual({
|
||||
id: "tui-which-key",
|
||||
source: "internal",
|
||||
spec: "tui-which-key",
|
||||
target: "tui-which-key",
|
||||
enabled: false,
|
||||
active: false,
|
||||
})
|
||||
|
||||
await expect(TuiPluginRuntime.activatePlugin("tui-which-key")).resolves.toBe(true)
|
||||
expect(TuiPluginRuntime.list().find((item) => item.id === "tui-which-key")).toEqual({
|
||||
id: "tui-which-key",
|
||||
source: "internal",
|
||||
spec: "tui-which-key",
|
||||
target: "tui-which-key",
|
||||
enabled: true,
|
||||
active: true,
|
||||
})
|
||||
expect(api.kv.get("plugin_enabled", {})).toEqual({
|
||||
"tui-which-key": true,
|
||||
})
|
||||
} finally {
|
||||
await TuiPluginRuntime.dispose()
|
||||
cwd.mockRestore()
|
||||
wait.mockRestore()
|
||||
}
|
||||
})
|
||||
|
||||
@@ -412,6 +412,7 @@ test("resolves semantic keymap sections", async () => {
|
||||
keymap: {
|
||||
sections: {
|
||||
global: { "command.palette.show": "alt+p" },
|
||||
which_key: { "tui-which-key.toggle": "alt+k" },
|
||||
prompt: { "prompt.editor": "ctrl+e" },
|
||||
autocomplete: { "prompt.autocomplete.next": "ctrl+j" },
|
||||
dialog_actions: { "dialog.action.toggle": "ctrl+t" },
|
||||
@@ -427,6 +428,23 @@ test("resolves semantic keymap sections", async () => {
|
||||
const config = await getTuiConfig(tmp.path)
|
||||
expect(config.keymap.sections.global.find((binding) => binding.cmd === "command.palette.show")?.key).toBe("alt+p")
|
||||
expect(config.keymap.sections.global.find((binding) => binding.cmd === "session.new")?.key).toBe("<leader>n")
|
||||
expect(config.keymap.sections.which_key.find((binding) => binding.cmd === "tui-which-key.toggle")?.key).toBe(
|
||||
"alt+k",
|
||||
)
|
||||
expect(config.keymap.sections.which_key.find((binding) => binding.cmd === "tui-which-key.layout.toggle")?.key).toBe(
|
||||
"ctrl+alt+shift+k",
|
||||
)
|
||||
expect(config.keymap.sections.which_key.find((binding) => binding.cmd === "tui-which-key.pending.toggle")?.key).toBe(
|
||||
"ctrl+alt+shift+p",
|
||||
)
|
||||
expect(config.keymap.sections.which_key.find((binding) => binding.cmd === "tui-which-key.group.next")?.key).toBe(
|
||||
"ctrl+alt+right,ctrl+alt+]",
|
||||
)
|
||||
expect(
|
||||
(config.keymap.sections.which_key.find((binding) => binding.cmd === "tui-which-key.toggle") as
|
||||
| { group?: unknown }
|
||||
| undefined)?.group,
|
||||
).toBe("System")
|
||||
expect(config.keymap.sections.prompt.find((binding) => binding.cmd === "prompt.editor")?.key).toBe("ctrl+e")
|
||||
expect(config.keymap.sections.autocomplete.find((binding) => binding.cmd === "prompt.autocomplete.next")?.key).toBe(
|
||||
"ctrl+j",
|
||||
@@ -467,6 +485,7 @@ test("legacy keybinds transform into semantic keymap sections", async () => {
|
||||
const config = await getTuiConfig(tmp.path)
|
||||
expect(Object.keys(config.keymap.sections)).toEqual([
|
||||
"global",
|
||||
"which_key",
|
||||
"session",
|
||||
"prompt",
|
||||
"autocomplete",
|
||||
@@ -480,6 +499,9 @@ test("legacy keybinds transform into semantic keymap sections", async () => {
|
||||
"home_tips",
|
||||
])
|
||||
expect(config.keymap.sections.global.find((binding) => binding.cmd === "command.palette.show")?.key).toBe("alt+p")
|
||||
expect(config.keymap.sections.which_key.find((binding) => binding.cmd === "tui-which-key.toggle")?.key).toBe(
|
||||
"ctrl+alt+k",
|
||||
)
|
||||
expect(config.keymap.sections.prompt.find((binding) => binding.cmd === "prompt.editor")?.key).toBe("ctrl+e")
|
||||
expect(config.keymap.sections.autocomplete.find((binding) => binding.cmd === "prompt.autocomplete.next")?.key).toBe(
|
||||
"ctrl+j",
|
||||
|
||||
Reference in New Issue
Block a user