From fbf2e4bc452c3432f814eba4b03f0e92e7cce7b8 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Tue, 17 Jun 2025 10:55:51 +0200 Subject: [PATCH] Rename system.invokeCommand syscall to editor.invokeCommand --- Library/Std/Config.md | 6 +++--- Library/Std/Widgets.md | 2 +- plug-api/syscalls/editor.ts | 10 ++++++++++ web/syscalls/editor.ts | 3 +++ web/syscalls/system.ts | 4 +--- website/API/editor.md | 8 ++++++++ website/API/system.md | 8 -------- website/CONFIG.md | 6 +++--- 8 files changed, 29 insertions(+), 18 deletions(-) diff --git a/Library/Std/Config.md b/Library/Std/Config.md index 0fb42775..1f60eb44 100644 --- a/Library/Std/Config.md +++ b/Library/Std/Config.md @@ -263,21 +263,21 @@ config.set { icon = "home", description = "Go to the index page", run = function() - system.invokeCommand("Navigate: Home") + editor.invokeCommand("Navigate: Home") end }, { icon = "book", description = "Open page", run = function() - system.invokeCommand("Navigate: Page Picker") + editor.invokeCommand("Navigate: Page Picker") end }, { icon = "terminal", description = "Run command", run = function() - system.invokeCommand "Open Command Palette" + editor.invokeCommand "Open Command Palette" end, } }, diff --git a/Library/Std/Widgets.md b/Library/Std/Widgets.md index e4af7853..f3cfdffa 100644 --- a/Library/Std/Widgets.md +++ b/Library/Std/Widgets.md @@ -26,7 +26,7 @@ function widgets.commandButton(text, commandName, args) end return widget.html(dom.button { onclick = function() - system.invokeCommand(commandName, args) + editor.invokeCommand(commandName, args) end, text }) diff --git a/plug-api/syscalls/editor.ts b/plug-api/syscalls/editor.ts index 11f5338a..e307ded2 100644 --- a/plug-api/syscalls/editor.ts +++ b/plug-api/syscalls/editor.ts @@ -93,6 +93,16 @@ export function setSelection(from: number, to: number): Promise { return syscall("editor.setSelection", from, to); } +/** + * Invoke a client command by name + * Note: only available on the client + * @param name name of the command + * @param args arguments to pass to the command + */ +export function invokeCommand(name: string, args?: string[]): Promise { + return syscall("editor.invokeCommand", name, args); +} + /** * Forces a save of the current page */ diff --git a/web/syscalls/editor.ts b/web/syscalls/editor.ts index 1f09021f..b4c46cb9 100644 --- a/web/syscalls/editor.ts +++ b/web/syscalls/editor.ts @@ -117,6 +117,9 @@ export function editorSyscalls(client: Client): SysCallMapping { [], ); }, + "editor.invokeCommand": (_ctx, name: string, args?: string[]) => { + return client.runCommandByName(name, args); + }, "editor.openUrl": (_ctx, url: string, existingWindow = false) => { client.openUrl(url, existingWindow); }, diff --git a/web/syscalls/system.ts b/web/syscalls/system.ts index c3654537..d427a3dd 100644 --- a/web/syscalls/system.ts +++ b/web/syscalls/system.ts @@ -45,9 +45,7 @@ export function systemSyscalls( return client.clientSystem.localSyscall(name, args); }, "system.invokeCommand": (_ctx, name: string, args?: string[]) => { - if (!client) { - throw new Error("Not supported"); - } + console.warn("Deprecated, use editor.invokeCommand instead"); return client.runCommandByName(name, args); }, "system.listCommands": (): { [key: string]: CommandDef } => { diff --git a/website/API/editor.md b/website/API/editor.md index 6d68c937..13552dd2 100644 --- a/website/API/editor.md +++ b/website/API/editor.md @@ -116,6 +116,14 @@ Example: editor.moveCursorToLine(1, 1, true) -- Move to start of first line ``` +### editor.invokeCommand(name, args?) +Invokes a client command by name. + +Example: +```lua +editor.invokeCommand("Stats: Show") +``` + ### editor.save() Force saves the current page. diff --git a/website/API/system.md b/website/API/system.md index 114a71f4..3b6b6c8e 100644 --- a/website/API/system.md +++ b/website/API/system.md @@ -13,14 +13,6 @@ Example: system.invokeFunction("myplug.processData", "input", 123) ``` -### system.invokeCommand(name, args) -Invokes a client command by name. - -Example: -```lua -system.invokeCommand("editor.save", {}) -``` - ## System Information ### system.listCommands() diff --git a/website/CONFIG.md b/website/CONFIG.md index 922d71ae..c6d82c2b 100644 --- a/website/CONFIG.md +++ b/website/CONFIG.md @@ -10,7 +10,7 @@ config.set { icon = "home", description = "Go to the index page", run = function() - system.invokeCommand("Navigate: Home") + editor.invokeCommand("Navigate: Home") end }, { @@ -33,14 +33,14 @@ config.set { icon = "book", description = "Open page", run = function() - system.invokeCommand("Navigate: Page Picker") + editor.invokeCommand("Navigate: Page Picker") end }, { icon = "terminal", description = "Run command", run = function() - system.invokeCommand "Open Command Palette" + editor.invokeCommand "Open Command Palette" end, } },