tabby/clients/vscode/src/Commands.ts

59 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-03-28 07:53:57 +00:00
import { ConfigurationTarget, workspace, window, commands } from "vscode";
import { TabbyClient } from "./TabbyClient";
2023-03-28 07:53:57 +00:00
const target = ConfigurationTarget.Global;
type Command = {
command: string;
callback: (...args: any[]) => any;
thisArg?: any;
};
const toogleEnabled: Command = {
command: "tabby.toggleEnabled",
callback: () => {
const configuration = workspace.getConfiguration("tabby");
const enabled = configuration.get("enabled", true);
console.debug(`Toggle Enabled: ${enabled} -> ${!enabled}.`);
configuration.update("enabled", !enabled, target, false);
},
};
const setServerUrl: Command = {
command: "tabby.setServerUrl",
callback: () => {
const configuration = workspace.getConfiguration("tabby");
window
.showInputBox({
prompt: "Enter the URL of your Tabby Server",
value: configuration.get("serverUrl", ""),
})
.then((url) => {
if (url) {
console.debug("Set Tabby Server URL: ", url);
configuration.update("serverUrl", url, target, false);
}
});
},
};
const openSettings: Command = {
command: "tabby.openSettings",
callback: () => {
commands.executeCommand("workbench.action.openSettings", "tabby");
},
};
const tabbyClient = TabbyClient.getInstance();
2023-03-28 07:53:57 +00:00
const emitEvent: Command = {
command: "tabby.emitEvent",
callback: (event) => {
console.debug("Emit Event: ", event);
tabbyClient.postEvent(event);
2023-03-28 07:53:57 +00:00
},
};
export const tabbyCommands = [toogleEnabled, setServerUrl, openSettings, emitEvent].map((command) =>
2023-03-28 07:53:57 +00:00
commands.registerCommand(command.command, command.callback, command.thisArg)
);