From 5190d30ae303d26b568049f94cfaa137de157840 Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Sun, 6 Oct 2024 05:39:11 -0400 Subject: [PATCH] Refactor commands --- package.json | 18 +++++++++--------- src/core/Cline.ts | 18 +++++++++--------- src/core/webview/ClineProvider.ts | 6 +++--- src/exports/index.ts | 2 +- src/extension.ts | 18 +++++++++--------- src/shared/ExtensionMessage.ts | 4 ++-- src/shared/WebviewMessage.ts | 2 +- webview-ui/src/App.tsx | 6 +++--- webview-ui/src/components/chat/ChatView.tsx | 4 ++-- 9 files changed, 39 insertions(+), 39 deletions(-) diff --git a/package.json b/package.json index f4229c8..c2052b0 100644 --- a/package.json +++ b/package.json @@ -62,27 +62,27 @@ }, "commands": [ { - "command": "claude-dev.plusButtonTapped", + "command": "cline.plusButtonClicked", "title": "New Task", "icon": "$(add)" }, { - "command": "claude-dev.historyButtonTapped", + "command": "cline.historyButtonClicked", "title": "History", "icon": "$(history)" }, { - "command": "claude-dev.popoutButtonTapped", + "command": "cline.popoutButtonClicked", "title": "Open in Editor", "icon": "$(link-external)" }, { - "command": "claude-dev.settingsButtonTapped", + "command": "cline.settingsButtonClicked", "title": "Settings", "icon": "$(settings-gear)" }, { - "command": "claude-dev.openInNewTab", + "command": "cline.openInNewTab", "title": "Open In New Tab", "category": "Cline" } @@ -90,22 +90,22 @@ "menus": { "view/title": [ { - "command": "claude-dev.plusButtonTapped", + "command": "cline.plusButtonClicked", "group": "navigation@1", "when": "view == claude-dev.SidebarProvider" }, { - "command": "claude-dev.historyButtonTapped", + "command": "cline.historyButtonClicked", "group": "navigation@2", "when": "view == claude-dev.SidebarProvider" }, { - "command": "claude-dev.popoutButtonTapped", + "command": "cline.popoutButtonClicked", "group": "navigation@3", "when": "view == claude-dev.SidebarProvider" }, { - "command": "claude-dev.settingsButtonTapped", + "command": "cline.settingsButtonClicked", "group": "navigation@4", "when": "view == claude-dev.SidebarProvider" } diff --git a/src/core/Cline.ts b/src/core/Cline.ts index 1098f22..add5ea8 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -631,7 +631,7 @@ export class Cline { const sendCommandOutput = async (line: string): Promise => { try { const { response, text, images } = await this.ask("command_output", line) - if (response === "yesButtonTapped") { + if (response === "yesButtonClicked") { // proceed while running } else { userFeedback = { text, images } @@ -737,8 +737,8 @@ export class Cline { "api_req_failed", error.message ?? JSON.stringify(serializeError(error), null, 2) ) - if (response !== "yesButtonTapped") { - // this will never happen since if noButtonTapped, we will clear current task, aborting this instance + if (response !== "yesButtonClicked") { + // this will never happen since if noButtonClicked, we will clear current task, aborting this instance throw new Error("API request failed") } await this.say("api_req_retried") @@ -877,7 +877,7 @@ export class Cline { const askApproval = async (type: ClineAsk, partialMessage?: string) => { const { response, text, images } = await this.ask(type, partialMessage, false) - if (response !== "yesButtonTapped") { + if (response !== "yesButtonClicked") { if (response === "messageResponse") { await this.say("user_feedback", text, images) pushToolResult( @@ -1404,8 +1404,8 @@ export class Cline { resultToSend = "" } const { response, text, images } = await this.ask("completion_result", resultToSend) // this prompts webview to show 'new task' button, and enable text input (which would be the 'text' here) - if (response === "yesButtonTapped") { - return [false, ""] // signals to recursive loop to stop (for now this never happens since yesButtonTapped will trigger a new task) + if (response === "yesButtonClicked") { + return [false, ""] // signals to recursive loop to stop (for now this never happens since yesButtonClicked will trigger a new task) } await this.say("user_feedback", text ?? "", images) return [ @@ -1488,8 +1488,8 @@ export class Cline { // we already sent completion_result says, an empty string asks relinquishes control over button and field const { response, text, images } = await this.ask("completion_result", "", false) - if (response === "yesButtonTapped") { - pushToolResult("") // signals to recursive loop to stop (for now this never happens since yesButtonTapped will trigger a new task) + if (response === "yesButtonClicked") { + pushToolResult("") // signals to recursive loop to stop (for now this never happens since yesButtonClicked will trigger a new task) break } await this.say("user_feedback", text ?? "", images) @@ -1809,7 +1809,7 @@ export class Cline { return didEndLoop // will always be false for now } catch (error) { - // this should never happen since the only thing that can throw an error is the attemptApiRequest, which is wrapped in a try catch that sends an ask where if noButtonTapped, will clear current task and destroy this instance. However to avoid unhandled promise rejection, we will end this loop which will end execution of this instance (see startTask) + // this should never happen since the only thing that can throw an error is the attemptApiRequest, which is wrapped in a try catch that sends an ask where if noButtonClicked, will clear current task and destroy this instance. However to avoid unhandled promise rejection, we will end this loop which will end execution of this instance (see startTask) return true } } diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 2d52289..d1e3ab1 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -509,7 +509,7 @@ export class ClineProvider implements vscode.WebviewViewProvider { if (this.cline) { this.cline.api = buildApiHandler({ apiProvider: openrouter, openRouterApiKey: apiKey }) } - // await this.postMessageToWebview({ type: "action", action: "settingsButtonTapped" }) // bad ux if user is on welcome + // await this.postMessageToWebview({ type: "action", action: "settingsButtonClicked" }) // bad ux if user is on welcome } private async ensureCacheDirectoryExists(): Promise { @@ -659,7 +659,7 @@ export class ClineProvider implements vscode.WebviewViewProvider { const { historyItem } = await this.getTaskWithId(id) await this.initClineWithHistoryItem(historyItem) // clears existing task } - await this.postMessageToWebview({ type: "action", action: "chatButtonTapped" }) + await this.postMessageToWebview({ type: "action", action: "chatButtonClicked" }) } async exportTaskWithId(id: string) { @@ -955,6 +955,6 @@ export class ClineProvider implements vscode.WebviewViewProvider { } vscode.window.showInformationMessage("State reset") await this.postStateToWebview() - await this.postMessageToWebview({ type: "action", action: "chatButtonTapped" }) + await this.postMessageToWebview({ type: "action", action: "chatButtonClicked" }) } } diff --git a/src/exports/index.ts b/src/exports/index.ts index 7633f8d..ebb42d0 100644 --- a/src/exports/index.ts +++ b/src/exports/index.ts @@ -17,7 +17,7 @@ export function createClineAPI(outputChannel: vscode.OutputChannel, sidebarProvi outputChannel.appendLine("Starting new task") await sidebarProvider.clearTask() await sidebarProvider.postStateToWebview() - await sidebarProvider.postMessageToWebview({ type: "action", action: "chatButtonTapped" }) + await sidebarProvider.postMessageToWebview({ type: "action", action: "chatButtonClicked" }) await sidebarProvider.postMessageToWebview({ type: "invoke", invoke: "sendMessage", diff --git a/src/extension.ts b/src/extension.ts index 5735dae..0cf4996 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -34,11 +34,11 @@ export function activate(context: vscode.ExtensionContext) { ) context.subscriptions.push( - vscode.commands.registerCommand("claude-dev.plusButtonTapped", async () => { - outputChannel.appendLine("Plus button tapped") + vscode.commands.registerCommand("cline.plusButtonClicked", async () => { + outputChannel.appendLine("Plus button Clicked") await sidebarProvider.clearTask() await sidebarProvider.postStateToWebview() - await sidebarProvider.postMessageToWebview({ type: "action", action: "chatButtonTapped" }) + await sidebarProvider.postMessageToWebview({ type: "action", action: "chatButtonClicked" }) }) ) @@ -75,19 +75,19 @@ export function activate(context: vscode.ExtensionContext) { await vscode.commands.executeCommand("workbench.action.lockEditorGroup") } - context.subscriptions.push(vscode.commands.registerCommand("claude-dev.popoutButtonTapped", openClineInNewTab)) - context.subscriptions.push(vscode.commands.registerCommand("claude-dev.openInNewTab", openClineInNewTab)) + context.subscriptions.push(vscode.commands.registerCommand("cline.popoutButtonClicked", openClineInNewTab)) + context.subscriptions.push(vscode.commands.registerCommand("cline.openInNewTab", openClineInNewTab)) context.subscriptions.push( - vscode.commands.registerCommand("claude-dev.settingsButtonTapped", () => { + vscode.commands.registerCommand("cline.settingsButtonClicked", () => { //vscode.window.showInformationMessage(message) - sidebarProvider.postMessageToWebview({ type: "action", action: "settingsButtonTapped" }) + sidebarProvider.postMessageToWebview({ type: "action", action: "settingsButtonClicked" }) }) ) context.subscriptions.push( - vscode.commands.registerCommand("claude-dev.historyButtonTapped", () => { - sidebarProvider.postMessageToWebview({ type: "action", action: "historyButtonTapped" }) + vscode.commands.registerCommand("cline.historyButtonClicked", () => { + sidebarProvider.postMessageToWebview({ type: "action", action: "historyButtonClicked" }) }) ) diff --git a/src/shared/ExtensionMessage.ts b/src/shared/ExtensionMessage.ts index 349475c..0ae1e13 100644 --- a/src/shared/ExtensionMessage.ts +++ b/src/shared/ExtensionMessage.ts @@ -1,4 +1,4 @@ -// type that represents json data that is sent from extension to webview, called ExtensionMessage and has 'type' enum which can be 'plusButtonTapped' or 'settingsButtonTapped' or 'hello' +// type that represents json data that is sent from extension to webview, called ExtensionMessage and has 'type' enum which can be 'plusButtonClicked' or 'settingsButtonClicked' or 'hello' import { ApiConfiguration, ModelInfo } from "./api" import { HistoryItem } from "./HistoryItem" @@ -16,7 +16,7 @@ export interface ExtensionMessage { | "partialMessage" | "openRouterModels" text?: string - action?: "chatButtonTapped" | "settingsButtonTapped" | "historyButtonTapped" | "didBecomeVisible" + action?: "chatButtonClicked" | "settingsButtonClicked" | "historyButtonClicked" | "didBecomeVisible" invoke?: "sendMessage" | "primaryButtonClick" | "secondaryButtonClick" state?: ExtensionState images?: string[] diff --git a/src/shared/WebviewMessage.ts b/src/shared/WebviewMessage.ts index f37c520..723efff 100644 --- a/src/shared/WebviewMessage.ts +++ b/src/shared/WebviewMessage.ts @@ -29,4 +29,4 @@ export interface WebviewMessage { bool?: boolean } -export type ClineAskResponse = "yesButtonTapped" | "noButtonTapped" | "messageResponse" +export type ClineAskResponse = "yesButtonClicked" | "noButtonClicked" | "messageResponse" diff --git a/webview-ui/src/App.tsx b/webview-ui/src/App.tsx index 29a0b5b..d625802 100644 --- a/webview-ui/src/App.tsx +++ b/webview-ui/src/App.tsx @@ -19,15 +19,15 @@ const AppContent = () => { switch (message.type) { case "action": switch (message.action!) { - case "settingsButtonTapped": + case "settingsButtonClicked": setShowSettings(true) setShowHistory(false) break - case "historyButtonTapped": + case "historyButtonClicked": setShowSettings(false) setShowHistory(true) break - case "chatButtonTapped": + case "chatButtonClicked": setShowSettings(false) setShowHistory(false) break diff --git a/webview-ui/src/components/chat/ChatView.tsx b/webview-ui/src/components/chat/ChatView.tsx index d296107..e1f132f 100644 --- a/webview-ui/src/components/chat/ChatView.tsx +++ b/webview-ui/src/components/chat/ChatView.tsx @@ -269,7 +269,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie case "tool": case "resume_task": case "mistake_limit_reached": - vscode.postMessage({ type: "askResponse", askResponse: "yesButtonTapped" }) + vscode.postMessage({ type: "askResponse", askResponse: "yesButtonClicked" }) break case "completion_result": case "resume_completed_task": @@ -299,7 +299,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie case "command": case "tool": // responds to the API with a "This operation failed" and lets it try again - vscode.postMessage({ type: "askResponse", askResponse: "noButtonTapped" }) + vscode.postMessage({ type: "askResponse", askResponse: "noButtonClicked" }) break } setTextAreaDisabled(true)