From ca3cf185cfe47794c4bd3baa7d950908a002c8da Mon Sep 17 00:00:00 2001 From: canvrno <46584286+canvrno@users.noreply.github.com> Date: Tue, 6 May 2025 19:21:37 -0700 Subject: [PATCH] [PROTOBUS] Move showTaskWithID to protobus (#3283) * showTaskWithID protobus migration * replaced ShowTaskWithIdRequest with generic stringRequest * prettier --- proto/task.proto | 3 +++ src/core/controller/index.ts | 3 --- src/core/controller/task/methods.ts | 2 ++ src/core/controller/task/showTaskWithId.ts | 17 +++++++++++++++++ src/shared/WebviewMessage.ts | 1 - src/shared/proto/task.ts | 9 +++++++++ .../src/components/history/HistoryPreview.tsx | 3 ++- .../src/components/history/HistoryView.tsx | 2 +- 8 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 src/core/controller/task/showTaskWithId.ts diff --git a/proto/task.proto b/proto/task.proto index 20bc8942da..4fd9769ad1 100644 --- a/proto/task.proto +++ b/proto/task.proto @@ -15,6 +15,8 @@ service TaskService { rpc deleteTasksWithIds(StringArrayRequest) returns (Empty); // Creates a new task with the given text and optional images rpc newTask(NewTaskRequest) returns (Empty); + // Shows a task with the specified ID + rpc showTaskWithId(StringRequest) returns (Empty); // Exports a task with the given ID to markdown rpc exportTaskWithId(StringRequest) returns (Empty); } @@ -25,3 +27,4 @@ message NewTaskRequest { string text = 2; repeated string images = 3; } + diff --git a/src/core/controller/index.ts b/src/core/controller/index.ts index 02a7854db6..66e87eb10d 100644 --- a/src/core/controller/index.ts +++ b/src/core/controller/index.ts @@ -329,9 +329,6 @@ export class Controller { images, }) break - case "showTaskWithId": - this.showTaskWithId(message.text!) - break case "resetState": await this.resetState() break diff --git a/src/core/controller/task/methods.ts b/src/core/controller/task/methods.ts index 409a0fc91c..b5f6b5c243 100644 --- a/src/core/controller/task/methods.ts +++ b/src/core/controller/task/methods.ts @@ -8,6 +8,7 @@ import { clearTask } from "./clearTask" import { deleteTasksWithIds } from "./deleteTasksWithIds" import { exportTaskWithId } from "./exportTaskWithId" import { newTask } from "./newTask" +import { showTaskWithId } from "./showTaskWithId" // Register all task service methods export function registerAllMethods(): void { @@ -17,4 +18,5 @@ export function registerAllMethods(): void { registerMethod("deleteTasksWithIds", deleteTasksWithIds) registerMethod("exportTaskWithId", exportTaskWithId) registerMethod("newTask", newTask) + registerMethod("showTaskWithId", showTaskWithId) } diff --git a/src/core/controller/task/showTaskWithId.ts b/src/core/controller/task/showTaskWithId.ts new file mode 100644 index 0000000000..45b322627d --- /dev/null +++ b/src/core/controller/task/showTaskWithId.ts @@ -0,0 +1,17 @@ +import { Controller } from ".." +import { Empty, StringRequest } from "../../../shared/proto/common" + +/** + * Shows a task with the specified ID + * @param controller The controller instance + * @param request The request containing the task ID + * @returns Empty response + */ +export async function showTaskWithId(controller: Controller, request: StringRequest): Promise { + try { + await controller.showTaskWithId(request.value) + return Empty.create() + } catch (error) { + throw error + } +} diff --git a/src/shared/WebviewMessage.ts b/src/shared/WebviewMessage.ts index 9b977994ab..aaf158e803 100644 --- a/src/shared/WebviewMessage.ts +++ b/src/shared/WebviewMessage.ts @@ -16,7 +16,6 @@ export interface WebviewMessage { | "askResponse" | "didShowAnnouncement" | "selectImages" - | "showTaskWithId" | "resetState" | "openInBrowser" | "openMention" diff --git a/src/shared/proto/task.ts b/src/shared/proto/task.ts index ebb1bbd545..ea3568c142 100644 --- a/src/shared/proto/task.ts +++ b/src/shared/proto/task.ts @@ -151,6 +151,15 @@ export const TaskServiceDefinition = { responseStream: false, options: {}, }, + /** Shows a task with the specified ID */ + showTaskWithId: { + name: "showTaskWithId", + requestType: StringRequest, + requestStream: false, + responseType: Empty, + responseStream: false, + options: {}, + }, /** Exports a task with the given ID to markdown */ exportTaskWithId: { name: "exportTaskWithId", diff --git a/webview-ui/src/components/history/HistoryPreview.tsx b/webview-ui/src/components/history/HistoryPreview.tsx index c2d8860207..e5e8626bbc 100644 --- a/webview-ui/src/components/history/HistoryPreview.tsx +++ b/webview-ui/src/components/history/HistoryPreview.tsx @@ -2,6 +2,7 @@ import { VSCodeButton } from "@vscode/webview-ui-toolkit/react" import { useExtensionState } from "@/context/ExtensionStateContext" import { vscode } from "@/utils/vscode" import { memo } from "react" +import { TaskServiceClient } from "@/services/grpc-client" import { formatLargeNumber } from "@/utils/format" type HistoryPreviewProps = { @@ -11,7 +12,7 @@ type HistoryPreviewProps = { const HistoryPreview = ({ showHistoryView }: HistoryPreviewProps) => { const { taskHistory } = useExtensionState() const handleHistorySelect = (id: string) => { - vscode.postMessage({ type: "showTaskWithId", text: id }) + TaskServiceClient.showTaskWithId({ value: id }).catch((error) => console.error("Error showing task:", error)) } const formatDate = (timestamp: number) => { diff --git a/webview-ui/src/components/history/HistoryView.tsx b/webview-ui/src/components/history/HistoryView.tsx index 5bf722c8f4..ee37268fed 100644 --- a/webview-ui/src/components/history/HistoryView.tsx +++ b/webview-ui/src/components/history/HistoryView.tsx @@ -48,7 +48,7 @@ const HistoryView = ({ onDone }: HistoryViewProps) => { }, [searchQuery, sortOption, lastNonRelevantSort]) const handleShowTaskWithId = useCallback((id: string) => { - vscode.postMessage({ type: "showTaskWithId", text: id }) + TaskServiceClient.showTaskWithId({ value: id }).catch((error) => console.error("Error showing task:", error)) }, []) const handleHistorySelect = useCallback((itemId: string, checked: boolean) => {