更新探测版插件:尝试 keymap.layer 注册命令
This commit is contained in:
@@ -25,72 +25,82 @@ function log(msg) {
|
|||||||
export default Plugin.define({
|
export default Plugin.define({
|
||||||
id: "oc-session-all",
|
id: "oc-session-all",
|
||||||
setup(context) {
|
setup(context) {
|
||||||
log("[oc-session-all] v2 Plugin loaded! Attempting command registration...")
|
log("[oc-session-all] v2 Plugin loaded! Attempting keymap.layer registration...")
|
||||||
|
|
||||||
// ── 探测 context 结构 ──────────────────────────────────────
|
// ── 探测 context.keymap 结构 ──────────────────────────────────────
|
||||||
const report = []
|
const report = []
|
||||||
report.push("context keys: " + Object.keys(context).join(", "))
|
report.push("context keys: " + Object.keys(context).join(", "))
|
||||||
|
|
||||||
// 探测 context.command
|
|
||||||
if (context.command) {
|
|
||||||
const cmdKeys = Object.getOwnPropertyNames(context.command)
|
|
||||||
report.push("command props: " + cmdKeys.join(", "))
|
|
||||||
const cmdMethods = cmdKeys.filter(k => typeof context.command[k] === "function")
|
|
||||||
report.push("command methods: " + cmdMethods.join(", "))
|
|
||||||
|
|
||||||
// 尝试 command.register
|
|
||||||
if (typeof context.command.register === "function") {
|
|
||||||
try {
|
|
||||||
const unregister = context.command.register(() => [
|
|
||||||
{
|
|
||||||
title: "Show All Sessions",
|
|
||||||
value: "sessions-all",
|
|
||||||
slash: { name: "sessions-all", aliases: ["sa"] },
|
|
||||||
description: "Display all session records in a dialog",
|
|
||||||
onSelect: async () => {
|
|
||||||
log("[oc-session-all] /sessions-all triggered")
|
|
||||||
context.ui.toast.show({
|
|
||||||
message: "Sessions-all command executed!",
|
|
||||||
variant: "success",
|
|
||||||
duration: 3000,
|
|
||||||
})
|
|
||||||
},
|
|
||||||
},
|
|
||||||
])
|
|
||||||
report.push("command.register: SUCCESS, unregister type: " + typeof unregister)
|
|
||||||
log("[oc-session-all] command.register succeeded")
|
|
||||||
} catch (e) {
|
|
||||||
report.push("command.register ERROR: " + e.message)
|
|
||||||
log("[oc-session-all] command.register ERROR: " + e.message)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
report.push("command.register: NOT A FUNCTION")
|
|
||||||
log("[oc-session-all] command.register is not a function")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
report.push("context.command: undefined")
|
|
||||||
log("[oc-session-all] context.command is undefined")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 探测 context.keymap
|
// 探测 context.keymap
|
||||||
if (context.keymap) {
|
if (context.keymap) {
|
||||||
const kmKeys = Object.getOwnPropertyNames(context.keymap)
|
const kmKeys = Object.getOwnPropertyNames(context.keymap)
|
||||||
report.push("keymap props: " + kmKeys.join(", "))
|
report.push("keymap props: " + kmKeys.join(", "))
|
||||||
const kmMethods = kmKeys.filter(k => typeof context.keymap[k] === "function")
|
|
||||||
report.push("keymap methods: " + kmMethods.join(", "))
|
// 尝试 keymap.layer
|
||||||
}
|
if (typeof context.keymap.layer === "function") {
|
||||||
|
report.push("keymap.layer is a function")
|
||||||
|
try {
|
||||||
|
// 尝试不同的调用方式
|
||||||
|
const layerResult = context.keymap.layer({
|
||||||
|
commands: [
|
||||||
|
{
|
||||||
|
title: "Show All Sessions",
|
||||||
|
value: "sessions-all",
|
||||||
|
slash: { name: "sessions-all", aliases: ["sa"] },
|
||||||
|
description: "Display all session records in a dialog",
|
||||||
|
onSelect: async () => {
|
||||||
|
log("[oc-session-all] /sessions-all triggered via keymap.layer")
|
||||||
|
context.ui.toast.show({
|
||||||
|
message: "Sessions-all command executed!",
|
||||||
|
variant: "success",
|
||||||
|
duration: 3000,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
report.push("keymap.layer result type: " + typeof layerResult)
|
||||||
|
log("[oc-session-all] keymap.layer called successfully, result type: " + typeof layerResult)
|
||||||
|
} catch (e) {
|
||||||
|
report.push("keymap.layer ERROR: " + e.message)
|
||||||
|
log("[oc-session-all] keymap.layer ERROR: " + e.message)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
report.push("keymap.layer is NOT a function")
|
||||||
|
log("[oc-session-all] keymap.layer is NOT a function")
|
||||||
|
}
|
||||||
|
|
||||||
// 探测 context.ui
|
// 尝试 keymap.commands
|
||||||
if (context.ui) {
|
if (typeof context.keymap.commands === "function") {
|
||||||
const uiKeys = Object.keys(context.ui)
|
report.push("keymap.commands is a function")
|
||||||
report.push("ui keys: " + uiKeys.join(", "))
|
try {
|
||||||
|
const commandsResult = context.keymap.commands()
|
||||||
|
report.push("keymap.commands() result type: " + typeof commandsResult)
|
||||||
|
log("[oc-session-all] keymap.commands() called, result type: " + typeof commandsResult)
|
||||||
|
} catch (e) {
|
||||||
|
report.push("keymap.commands ERROR: " + e.message)
|
||||||
|
log("[oc-session-all] keymap.commands ERROR: " + e.message)
|
||||||
|
}
|
||||||
|
} else if (context.keymap.commands) {
|
||||||
|
report.push("keymap.commands is an object: " + Object.keys(context.keymap.commands).join(", "))
|
||||||
|
log("[oc-session-all] keymap.commands is an object: " + Object.keys(context.keymap.commands).join(", "))
|
||||||
|
} else {
|
||||||
|
report.push("keymap.commands is undefined")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 尝试 keymap.dispatch
|
||||||
|
if (typeof context.keymap.dispatch === "function") {
|
||||||
|
report.push("keymap.dispatch is a function")
|
||||||
|
} else {
|
||||||
|
report.push("keymap.dispatch is NOT a function")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const msg = report.join(" | ")
|
const msg = report.join(" | ")
|
||||||
log("[oc-session-all] FULL PROBE: " + msg)
|
log("[oc-session-all] KEYMAP PROBE: " + msg)
|
||||||
try {
|
try {
|
||||||
context.ui.toast.show({
|
context.ui.toast.show({
|
||||||
message: "Full probe: " + msg,
|
message: "Keymap probe: " + msg,
|
||||||
variant: "info",
|
variant: "info",
|
||||||
duration: 20000,
|
duration: 20000,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,9 +1,31 @@
|
|||||||
import { Plugin } from "@opencode/plugin/tui"
|
import { Plugin } from "@opencode/plugin/tui"
|
||||||
|
import { appendFileSync, mkdirSync, existsSync } from "fs"
|
||||||
|
import { join } from "path"
|
||||||
|
|
||||||
|
// 日志文件路径
|
||||||
|
const LOG_DIR = "C:\\Users\\ypshidifu\\.config\\opencode"
|
||||||
|
const LOG_FILE = join(LOG_DIR, "oc-session-all.log")
|
||||||
|
|
||||||
|
// 确保日志目录存在
|
||||||
|
if (!existsSync(LOG_DIR)) {
|
||||||
|
mkdirSync(LOG_DIR, { recursive: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
function log(msg) {
|
||||||
|
const timestamp = new Date().toISOString()
|
||||||
|
const line = `[${timestamp}] ${msg}\n`
|
||||||
|
try {
|
||||||
|
appendFileSync(LOG_FILE, line)
|
||||||
|
} catch (e) {
|
||||||
|
// 忽略写入错误
|
||||||
|
}
|
||||||
|
console.log(msg)
|
||||||
|
}
|
||||||
|
|
||||||
export default Plugin.define({
|
export default Plugin.define({
|
||||||
id: "oc-session-all",
|
id: "oc-session-all",
|
||||||
setup(context) {
|
setup(context) {
|
||||||
console.log("[oc-session-all] v2 Plugin loaded! Attempting command registration...")
|
log("[oc-session-all] v2 Plugin loaded! Attempting command registration...")
|
||||||
|
|
||||||
// ── 探测 context 结构 ──────────────────────────────────────
|
// ── 探测 context 结构 ──────────────────────────────────────
|
||||||
const report = []
|
const report = []
|
||||||
@@ -26,7 +48,7 @@ export default Plugin.define({
|
|||||||
slash: { name: "sessions-all", aliases: ["sa"] },
|
slash: { name: "sessions-all", aliases: ["sa"] },
|
||||||
description: "Display all session records in a dialog",
|
description: "Display all session records in a dialog",
|
||||||
onSelect: async () => {
|
onSelect: async () => {
|
||||||
console.log("[oc-session-all] /sessions-all triggered")
|
log("[oc-session-all] /sessions-all triggered")
|
||||||
context.ui.toast.show({
|
context.ui.toast.show({
|
||||||
message: "Sessions-all command executed!",
|
message: "Sessions-all command executed!",
|
||||||
variant: "success",
|
variant: "success",
|
||||||
@@ -36,16 +58,18 @@ export default Plugin.define({
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
report.push("command.register: SUCCESS, unregister type: " + typeof unregister)
|
report.push("command.register: SUCCESS, unregister type: " + typeof unregister)
|
||||||
console.log("[oc-session-all] command.register succeeded")
|
log("[oc-session-all] command.register succeeded")
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
report.push("command.register ERROR: " + e.message)
|
report.push("command.register ERROR: " + e.message)
|
||||||
console.error("[oc-session-all] command.register failed:", e)
|
log("[oc-session-all] command.register ERROR: " + e.message)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
report.push("command.register: NOT A FUNCTION")
|
report.push("command.register: NOT A FUNCTION")
|
||||||
|
log("[oc-session-all] command.register is not a function")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
report.push("context.command: undefined")
|
report.push("context.command: undefined")
|
||||||
|
log("[oc-session-all] context.command is undefined")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 探测 context.keymap
|
// 探测 context.keymap
|
||||||
@@ -63,11 +87,15 @@ export default Plugin.define({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const msg = report.join(" | ")
|
const msg = report.join(" | ")
|
||||||
console.log("[oc-session-all] FULL PROBE: " + msg)
|
log("[oc-session-all] FULL PROBE: " + msg)
|
||||||
context.ui.toast.show({
|
try {
|
||||||
message: "Full probe: " + msg,
|
context.ui.toast.show({
|
||||||
variant: "info",
|
message: "Full probe: " + msg,
|
||||||
duration: 20000,
|
variant: "info",
|
||||||
})
|
duration: 20000,
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
log("[oc-session-all] toast.show ERROR: " + e.message)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user