Compare commits

...

1 Commits

Author SHA1 Message Date
celestial-vault eb842982ff migrate withProgress 2025-07-21 23:15:11 -07:00
4 changed files with 93 additions and 10 deletions
+25 -1
View File
@@ -12,6 +12,8 @@ service WindowService {
rpc showTextDocument(ShowTextDocumentRequest) returns (TextEditorInfo);
rpc showOpenDialogue(ShowOpenDialogueRequest) returns (SelectedResources);
rpc showMessage(ShowMessageRequest) returns (SelectedResponse);
rpc startProgress(StartProgressRequest) returns (StartProgressResponse);
rpc endProgress(EndProgressRequest) returns (cline.Empty);
}
message ShowTextDocumentRequest {
@@ -70,4 +72,26 @@ message ShowMessageRequestOptions {
message SelectedResponse {
optional string selected_option = 1;
}
}
enum ProgressLocation {
NOTIFICATION = 0;
SOURCE_CONTROL = 1;
WINDOW = 2;
}
message StartProgressRequest {
cline.Metadata metadata = 1;
ProgressLocation location = 2;
string title = 3;
bool cancellable = 4;
}
message StartProgressResponse {
string progress_id = 1;
}
message EndProgressRequest {
cline.Metadata metadata = 1;
string progress_id = 2;
}
@@ -0,0 +1,12 @@
import { EndProgressRequest } from "@/shared/proto/index.host"
import { progressMap } from "./startProgress"
export async function endProgress(request: EndProgressRequest): Promise<void> {
const { progressId } = request
const resolve = progressMap.get(progressId)
if (resolve) {
resolve() // This completes the withProgress callback
progressMap.delete(progressId)
}
}
@@ -0,0 +1,44 @@
import { window, ProgressLocation as VscodeProgressLocation } from "vscode"
import { StartProgressRequest, StartProgressResponse, ProgressLocation } from "@/shared/proto/index.host"
import { v4 as uuidv4 } from "uuid"
// Map to track active progress instances
const progressMap = new Map<string, () => void>()
function mapProgressLocation(location: ProgressLocation): VscodeProgressLocation {
switch (location) {
case ProgressLocation.NOTIFICATION:
return VscodeProgressLocation.Notification
case ProgressLocation.SOURCE_CONTROL:
return VscodeProgressLocation.SourceControl
case ProgressLocation.WINDOW:
return VscodeProgressLocation.Window
default:
return VscodeProgressLocation.Notification
}
}
export async function startProgress(request: StartProgressRequest): Promise<StartProgressResponse> {
const { location, title, cancellable } = request
const progressId = uuidv4()
// Start the VS Code progress but keep it alive until endProgress is called
window.withProgress(
{
location: mapProgressLocation(location),
title,
cancellable,
},
async () => {
// Keep the progress alive until endProgress is called
return new Promise<void>((resolve) => {
progressMap.set(progressId, resolve)
})
},
)
return StartProgressResponse.create({ progressId })
}
// Export the progress map for use by endProgress
export { progressMap }
@@ -1,7 +1,7 @@
import * as vscode from "vscode"
import { writeTextToClipboard } from "@utils/env"
import { HostProvider } from "@/hosts/host-provider"
import { ShowMessageType, ShowTextDocumentRequest } from "@/shared/proto/host/window"
import { ShowMessageType, ShowTextDocumentRequest, ProgressLocation } from "@/shared/proto/host/window"
import { buildApiHandler } from "@/api"
import { getAllExtensionState } from "@/core/storage/state"
import { getWorkingState } from "@/utils/git"
@@ -42,14 +42,17 @@ async function generate(context: vscode.ExtensionContext, scm?: vscode.SourceCon
return
}
await vscode.window.withProgress(
{
location: vscode.ProgressLocation.SourceControl,
title: "Generating commit message...",
cancellable: true,
},
() => performCommitGeneration(context, gitDiff, inputBox),
)
const { progressId } = await HostProvider.window.startProgress({
location: ProgressLocation.SOURCE_CONTROL,
title: "Generating commit message...",
cancellable: true,
})
try {
await performCommitGeneration(context, gitDiff, inputBox)
} finally {
await HostProvider.window.endProgress({ progressId })
}
}
async function performCommitGeneration(context: vscode.ExtensionContext, gitDiff: string, inputBox: any) {