Replace vscode show message API calls with the host bridge (#5161)

This commit is contained in:
Sarah Fortune authored and GitHub committed 2025-07-25 11:48:16 -04:00
1 parent 66fb8835a4
commit 38babe12f7
3 files changed
+82 -25

No files matched your search

+13 -8
View File
@@ -29,20 +29,21 @@ const disallowedApis = {
"vscode.workspace.applyEdit": {
messageId: "useHostBridge",
},
// "vscode.env.openExternal": {
// messageId: "useUtils",
// },
"vscode.window.onDidChangeActiveTextEditor": {
messageId: "useHostBridge",
},
"vscode.env.openExternal": {
messageId: "useUtils",
},
// "vscode.window.showWarningMessage": {
// messageId: "useHostBridgeShowMessage",
// },
"vscode.window.showOpenDialog": {
messageId: "useHostBridgeShowMessage",
},
// There are too many warnings for these calls, uncomment the following
// when the migration is finished.
// "vscode.window.showErrorMessage": {
// messageId: "useHostBridgeShowMessage",
// },
"vscode.window.showErrorMessage": {
messageId: "useHostBridgeShowMessage",
},
// "vscode.window.showInformationMessage": {
// messageId: "useHostBridgeShowMessage",
// },
@@ -186,6 +187,10 @@ module.exports = createRule({
if (filename.includes("/standalone/runtime-files/")) {
return true
}
// Skip unit tests
if (filename.endsWith(".test.ts")) {
return true
}
}
return {
+61 -15
View File
@@ -86,6 +86,7 @@ import { MessageStateHandler } from "./message-state"
import { TaskState } from "./TaskState"
import { ToolExecutor } from "./ToolExecutor"
import { updateApiReqMsg } from "./utils"
import { ShowMessageType } from "@/shared/proto/index.host"
export const USE_EXPERIMENTAL_CLAUDE4_FEATURES = false
@@ -375,7 +376,10 @@ export class Task {
case "taskAndWorkspace":
case "workspace":
if (!this.enableCheckpoints) {
vscode.window.showErrorMessage("Checkpoints are disabled in settings.")
HostProvider.window.showMessage({
type: ShowMessageType.ERROR,
message: "Checkpoints are disabled in settings.",
})
didWorkspaceRestoreFail = true
break
}
@@ -393,7 +397,10 @@ export class Task {
console.error("Failed to initialize checkpoint tracker:", errorMessage)
this.taskState.checkpointTrackerErrorMessage = errorMessage
await this.postStateToWebview()
vscode.window.showErrorMessage(errorMessage)
HostProvider.window.showMessage({
type: ShowMessageType.ERROR,
message: errorMessage,
})
didWorkspaceRestoreFail = true
}
}
@@ -402,7 +409,10 @@ export class Task {
await this.checkpointTracker.resetHead(message.lastCheckpointHash)
} catch (error) {
const errorMessage = error instanceof Error ? error.message : "Unknown error"
vscode.window.showErrorMessage("Failed to restore checkpoint: " + errorMessage)
HostProvider.window.showMessage({
type: ShowMessageType.ERROR,
message: "Failed to restore checkpoint: " + errorMessage,
})
didWorkspaceRestoreFail = true
}
} else if (offset && lastMessageWithHash.lastCheckpointHash && this.checkpointTracker) {
@@ -410,7 +420,10 @@ export class Task {
await this.checkpointTracker.resetHead(lastMessageWithHash.lastCheckpointHash)
} catch (error) {
const errorMessage = error instanceof Error ? error.message : "Unknown error"
vscode.window.showErrorMessage("Failed to restore offsetcheckpoint: " + errorMessage)
HostProvider.window.showMessage({
type: ShowMessageType.ERROR,
message: "Failed to restore offsetcheckpoint: " + errorMessage,
})
didWorkspaceRestoreFail = true
}
} else if (!offset && lastMessageWithHash.lastCheckpointHash && this.checkpointTracker) {
@@ -420,11 +433,17 @@ export class Task {
await this.checkpointTracker.resetHead(lastMessageWithHash.lastCheckpointHash)
} catch (error) {
const errorMessage = error instanceof Error ? error.message : "Unknown error"
vscode.window.showErrorMessage("Failed to restore checkpoint: " + errorMessage)
HostProvider.window.showMessage({
type: ShowMessageType.ERROR,
message: "Failed to restore checkpoint: " + errorMessage,
})
didWorkspaceRestoreFail = true
}
} else {
vscode.window.showErrorMessage("Failed to restore checkpoint")
HostProvider.window.showMessage({
type: ShowMessageType.ERROR,
message: "Failed to restore checkpoint",
})
}
break
}
@@ -481,13 +500,22 @@ export class Task {
switch (restoreType) {
case "task":
vscode.window.showInformationMessage("Task messages have been restored to the checkpoint")
HostProvider.window.showMessage({
type: ShowMessageType.INFORMATION,
message: "Task messages have been restored to the checkpoint",
})
break
case "workspace":
vscode.window.showInformationMessage("Workspace files have been restored to the checkpoint")
HostProvider.window.showMessage({
type: ShowMessageType.INFORMATION,
message: "Workspace files have been restored to the checkpoint",
})
break
case "taskAndWorkspace":
vscode.window.showInformationMessage("Task and workspace have been restored to the checkpoint")
HostProvider.window.showMessage({
type: ShowMessageType.INFORMATION,
message: "Task and workspace have been restored to the checkpoint",
})
break
}
@@ -518,7 +546,10 @@ export class Task {
sendRelinquishControlEvent()
}
if (!this.enableCheckpoints) {
vscode.window.showInformationMessage("Checkpoints are disabled in settings. Cannot show diff.")
HostProvider.window.showMessage({
type: ShowMessageType.INFORMATION,
message: "Checkpoints are disabled in settings. Cannot show diff.",
})
relinquishButton()
return
}
@@ -553,7 +584,10 @@ export class Task {
console.error("Failed to initialize checkpoint tracker:", errorMessage)
this.taskState.checkpointTrackerErrorMessage = errorMessage
await this.postStateToWebview()
vscode.window.showErrorMessage(errorMessage)
HostProvider.window.showMessage({
type: ShowMessageType.ERROR,
message: errorMessage,
})
relinquishButton()
return
}
@@ -588,7 +622,10 @@ export class Task {
const previousCheckpointHash = lastTaskCompletedMessageCheckpointHash || firstCheckpointMessageCheckpointHash // either use the diff between the first checkpoint and the task completion, or the diff between the latest two task completions
if (!previousCheckpointHash) {
vscode.window.showErrorMessage("Unexpected error: No checkpoint hash found")
HostProvider.window.showMessage({
type: ShowMessageType.ERROR,
message: "Unexpected error: No checkpoint hash found",
})
relinquishButton()
return
}
@@ -596,7 +633,10 @@ export class Task {
// Get changed files between current state and commit
changedFiles = await this.checkpointTracker?.getDiffSet(previousCheckpointHash, hash)
if (!changedFiles?.length) {
vscode.window.showInformationMessage("No changes found")
HostProvider.window.showMessage({
type: ShowMessageType.INFORMATION,
message: "No changes found",
})
relinquishButton()
return
}
@@ -604,14 +644,20 @@ export class Task {
// Get changed files between current state and commit
changedFiles = await this.checkpointTracker?.getDiffSet(hash)
if (!changedFiles?.length) {
vscode.window.showInformationMessage("No changes found")
HostProvider.window.showMessage({
type: ShowMessageType.INFORMATION,
message: "No changes found",
})
relinquishButton()
return
}
}
} catch (error) {
const errorMessage = error instanceof Error ? error.message : "Unknown error"
vscode.window.showErrorMessage("Failed to retrieve diff set: " + errorMessage)
HostProvider.window.showMessage({
type: ShowMessageType.ERROR,
message: "Failed to retrieve diff set: " + errorMessage,
})
relinquishButton()
return
}
@@ -38,7 +38,10 @@ async function generate(context: vscode.ExtensionContext, scm?: vscode.SourceCon
const inputBox = scm?.inputBox
if (!inputBox) {
vscode.window.showErrorMessage("Git extension not found or no repositories available")
HostProvider.window.showMessage({
type: ShowMessageType.ERROR,
message: "Git extension not found or no repositories available",
})
return
}
@@ -100,7 +103,10 @@ Commit message:`
}
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error)
vscode.window.showErrorMessage(`Failed to generate commit message: ${errorMessage}`)
HostProvider.window.showMessage({
type: ShowMessageType.ERROR,
message: `Failed to generate commit message: ${errorMessage}`,
})
} finally {
vscode.commands.executeCommand("setContext", "cline.isGeneratingCommit", false)
}