Refactor commands

This commit is contained in:
Saoud Rizwan
2024-10-06 05:39:11 -04:00
parent c04dfc76cb
commit 5190d30ae3
9 changed files with 39 additions and 39 deletions

View File

@@ -62,27 +62,27 @@
}, },
"commands": [ "commands": [
{ {
"command": "claude-dev.plusButtonTapped", "command": "cline.plusButtonClicked",
"title": "New Task", "title": "New Task",
"icon": "$(add)" "icon": "$(add)"
}, },
{ {
"command": "claude-dev.historyButtonTapped", "command": "cline.historyButtonClicked",
"title": "History", "title": "History",
"icon": "$(history)" "icon": "$(history)"
}, },
{ {
"command": "claude-dev.popoutButtonTapped", "command": "cline.popoutButtonClicked",
"title": "Open in Editor", "title": "Open in Editor",
"icon": "$(link-external)" "icon": "$(link-external)"
}, },
{ {
"command": "claude-dev.settingsButtonTapped", "command": "cline.settingsButtonClicked",
"title": "Settings", "title": "Settings",
"icon": "$(settings-gear)" "icon": "$(settings-gear)"
}, },
{ {
"command": "claude-dev.openInNewTab", "command": "cline.openInNewTab",
"title": "Open In New Tab", "title": "Open In New Tab",
"category": "Cline" "category": "Cline"
} }
@@ -90,22 +90,22 @@
"menus": { "menus": {
"view/title": [ "view/title": [
{ {
"command": "claude-dev.plusButtonTapped", "command": "cline.plusButtonClicked",
"group": "navigation@1", "group": "navigation@1",
"when": "view == claude-dev.SidebarProvider" "when": "view == claude-dev.SidebarProvider"
}, },
{ {
"command": "claude-dev.historyButtonTapped", "command": "cline.historyButtonClicked",
"group": "navigation@2", "group": "navigation@2",
"when": "view == claude-dev.SidebarProvider" "when": "view == claude-dev.SidebarProvider"
}, },
{ {
"command": "claude-dev.popoutButtonTapped", "command": "cline.popoutButtonClicked",
"group": "navigation@3", "group": "navigation@3",
"when": "view == claude-dev.SidebarProvider" "when": "view == claude-dev.SidebarProvider"
}, },
{ {
"command": "claude-dev.settingsButtonTapped", "command": "cline.settingsButtonClicked",
"group": "navigation@4", "group": "navigation@4",
"when": "view == claude-dev.SidebarProvider" "when": "view == claude-dev.SidebarProvider"
} }

View File

@@ -631,7 +631,7 @@ export class Cline {
const sendCommandOutput = async (line: string): Promise<void> => { const sendCommandOutput = async (line: string): Promise<void> => {
try { try {
const { response, text, images } = await this.ask("command_output", line) const { response, text, images } = await this.ask("command_output", line)
if (response === "yesButtonTapped") { if (response === "yesButtonClicked") {
// proceed while running // proceed while running
} else { } else {
userFeedback = { text, images } userFeedback = { text, images }
@@ -737,8 +737,8 @@ export class Cline {
"api_req_failed", "api_req_failed",
error.message ?? JSON.stringify(serializeError(error), null, 2) error.message ?? JSON.stringify(serializeError(error), null, 2)
) )
if (response !== "yesButtonTapped") { if (response !== "yesButtonClicked") {
// this will never happen since if noButtonTapped, we will clear current task, aborting this instance // this will never happen since if noButtonClicked, we will clear current task, aborting this instance
throw new Error("API request failed") throw new Error("API request failed")
} }
await this.say("api_req_retried") await this.say("api_req_retried")
@@ -877,7 +877,7 @@ export class Cline {
const askApproval = async (type: ClineAsk, partialMessage?: string) => { const askApproval = async (type: ClineAsk, partialMessage?: string) => {
const { response, text, images } = await this.ask(type, partialMessage, false) const { response, text, images } = await this.ask(type, partialMessage, false)
if (response !== "yesButtonTapped") { if (response !== "yesButtonClicked") {
if (response === "messageResponse") { if (response === "messageResponse") {
await this.say("user_feedback", text, images) await this.say("user_feedback", text, images)
pushToolResult( pushToolResult(
@@ -1404,8 +1404,8 @@ export class Cline {
resultToSend = "" 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) 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") { if (response === "yesButtonClicked") {
return [false, ""] // signals to recursive loop to stop (for now this never happens since yesButtonTapped will trigger a new task) 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) await this.say("user_feedback", text ?? "", images)
return [ return [
@@ -1488,8 +1488,8 @@ export class Cline {
// we already sent completion_result says, an empty string asks relinquishes control over button and field // 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) const { response, text, images } = await this.ask("completion_result", "", false)
if (response === "yesButtonTapped") { if (response === "yesButtonClicked") {
pushToolResult("") // signals to recursive loop to stop (for now this never happens since yesButtonTapped will trigger a new task) pushToolResult("") // signals to recursive loop to stop (for now this never happens since yesButtonClicked will trigger a new task)
break break
} }
await this.say("user_feedback", text ?? "", images) await this.say("user_feedback", text ?? "", images)
@@ -1809,7 +1809,7 @@ export class Cline {
return didEndLoop // will always be false for now return didEndLoop // will always be false for now
} catch (error) { } 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 return true
} }
} }

View File

@@ -509,7 +509,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
if (this.cline) { if (this.cline) {
this.cline.api = buildApiHandler({ apiProvider: openrouter, openRouterApiKey: apiKey }) 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<string> { private async ensureCacheDirectoryExists(): Promise<string> {
@@ -659,7 +659,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
const { historyItem } = await this.getTaskWithId(id) const { historyItem } = await this.getTaskWithId(id)
await this.initClineWithHistoryItem(historyItem) // clears existing task 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) { async exportTaskWithId(id: string) {
@@ -955,6 +955,6 @@ export class ClineProvider implements vscode.WebviewViewProvider {
} }
vscode.window.showInformationMessage("State reset") vscode.window.showInformationMessage("State reset")
await this.postStateToWebview() await this.postStateToWebview()
await this.postMessageToWebview({ type: "action", action: "chatButtonTapped" }) await this.postMessageToWebview({ type: "action", action: "chatButtonClicked" })
} }
} }

View File

@@ -17,7 +17,7 @@ export function createClineAPI(outputChannel: vscode.OutputChannel, sidebarProvi
outputChannel.appendLine("Starting new task") outputChannel.appendLine("Starting new task")
await sidebarProvider.clearTask() await sidebarProvider.clearTask()
await sidebarProvider.postStateToWebview() await sidebarProvider.postStateToWebview()
await sidebarProvider.postMessageToWebview({ type: "action", action: "chatButtonTapped" }) await sidebarProvider.postMessageToWebview({ type: "action", action: "chatButtonClicked" })
await sidebarProvider.postMessageToWebview({ await sidebarProvider.postMessageToWebview({
type: "invoke", type: "invoke",
invoke: "sendMessage", invoke: "sendMessage",

View File

@@ -34,11 +34,11 @@ export function activate(context: vscode.ExtensionContext) {
) )
context.subscriptions.push( context.subscriptions.push(
vscode.commands.registerCommand("claude-dev.plusButtonTapped", async () => { vscode.commands.registerCommand("cline.plusButtonClicked", async () => {
outputChannel.appendLine("Plus button tapped") outputChannel.appendLine("Plus button Clicked")
await sidebarProvider.clearTask() await sidebarProvider.clearTask()
await sidebarProvider.postStateToWebview() 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") await vscode.commands.executeCommand("workbench.action.lockEditorGroup")
} }
context.subscriptions.push(vscode.commands.registerCommand("claude-dev.popoutButtonTapped", openClineInNewTab)) context.subscriptions.push(vscode.commands.registerCommand("cline.popoutButtonClicked", openClineInNewTab))
context.subscriptions.push(vscode.commands.registerCommand("claude-dev.openInNewTab", openClineInNewTab)) context.subscriptions.push(vscode.commands.registerCommand("cline.openInNewTab", openClineInNewTab))
context.subscriptions.push( context.subscriptions.push(
vscode.commands.registerCommand("claude-dev.settingsButtonTapped", () => { vscode.commands.registerCommand("cline.settingsButtonClicked", () => {
//vscode.window.showInformationMessage(message) //vscode.window.showInformationMessage(message)
sidebarProvider.postMessageToWebview({ type: "action", action: "settingsButtonTapped" }) sidebarProvider.postMessageToWebview({ type: "action", action: "settingsButtonClicked" })
}) })
) )
context.subscriptions.push( context.subscriptions.push(
vscode.commands.registerCommand("claude-dev.historyButtonTapped", () => { vscode.commands.registerCommand("cline.historyButtonClicked", () => {
sidebarProvider.postMessageToWebview({ type: "action", action: "historyButtonTapped" }) sidebarProvider.postMessageToWebview({ type: "action", action: "historyButtonClicked" })
}) })
) )

View File

@@ -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 { ApiConfiguration, ModelInfo } from "./api"
import { HistoryItem } from "./HistoryItem" import { HistoryItem } from "./HistoryItem"
@@ -16,7 +16,7 @@ export interface ExtensionMessage {
| "partialMessage" | "partialMessage"
| "openRouterModels" | "openRouterModels"
text?: string text?: string
action?: "chatButtonTapped" | "settingsButtonTapped" | "historyButtonTapped" | "didBecomeVisible" action?: "chatButtonClicked" | "settingsButtonClicked" | "historyButtonClicked" | "didBecomeVisible"
invoke?: "sendMessage" | "primaryButtonClick" | "secondaryButtonClick" invoke?: "sendMessage" | "primaryButtonClick" | "secondaryButtonClick"
state?: ExtensionState state?: ExtensionState
images?: string[] images?: string[]

View File

@@ -29,4 +29,4 @@ export interface WebviewMessage {
bool?: boolean bool?: boolean
} }
export type ClineAskResponse = "yesButtonTapped" | "noButtonTapped" | "messageResponse" export type ClineAskResponse = "yesButtonClicked" | "noButtonClicked" | "messageResponse"

View File

@@ -19,15 +19,15 @@ const AppContent = () => {
switch (message.type) { switch (message.type) {
case "action": case "action":
switch (message.action!) { switch (message.action!) {
case "settingsButtonTapped": case "settingsButtonClicked":
setShowSettings(true) setShowSettings(true)
setShowHistory(false) setShowHistory(false)
break break
case "historyButtonTapped": case "historyButtonClicked":
setShowSettings(false) setShowSettings(false)
setShowHistory(true) setShowHistory(true)
break break
case "chatButtonTapped": case "chatButtonClicked":
setShowSettings(false) setShowSettings(false)
setShowHistory(false) setShowHistory(false)
break break

View File

@@ -269,7 +269,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
case "tool": case "tool":
case "resume_task": case "resume_task":
case "mistake_limit_reached": case "mistake_limit_reached":
vscode.postMessage({ type: "askResponse", askResponse: "yesButtonTapped" }) vscode.postMessage({ type: "askResponse", askResponse: "yesButtonClicked" })
break break
case "completion_result": case "completion_result":
case "resume_completed_task": case "resume_completed_task":
@@ -299,7 +299,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
case "command": case "command":
case "tool": case "tool":
// responds to the API with a "This operation failed" and lets it try again // 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 break
} }
setTextAreaDisabled(true) setTextAreaDisabled(true)