Don't need to use Message.create({...}) with the host bridge (#4999)

* Use await when calling async function showMessage.

Use await when calling `windowClient.showMessage`, otherwise the caller doesn't wait for the request to complete and any exceptions are lost.

For the host bridge RPCs, you don't need to do `ShowMessageRequest.create({...})`, you can just pass the request directly like: `{...}. The Message.create() was needed for the ProtoBus because of the way it was implemented, it couldn't be type-checked by the compiled. It's not needed elsewhere.

* Dont use await, because it blocks until the message is dismissed

* Dont need `?.selectedOption`, the response cannot be null

* Dont use await
This commit is contained in:
Sarah Fortune authored and GitHub committed 2025-07-17 20:15:42 -07:00
1 parent 1a3ec9f024
commit 72f16a8c30
17 files changed
+243 -357

No files matched your search

@@ -59,12 +59,10 @@ export function extractCommitMessage(aiResponse: string): string {
*/
export async function copyCommitMessageToClipboard(message: string): Promise<void> {
await writeTextToClipboard(message)
getHostBridgeProvider().windowClient.showMessage(
ShowMessageRequest.create({
type: ShowMessageType.INFORMATION,
message: "Commit message copied to clipboard",
}),
)
getHostBridgeProvider().windowClient.showMessage({
type: ShowMessageType.INFORMATION,
message: "Commit message copied to clipboard",
})
}
/**
@@ -77,18 +75,16 @@ export async function showCommitMessageOptions(message: string): Promise<void> {
const editAction = "Edit Message"
const selectedAction = (
await getHostBridgeProvider().windowClient.showMessage(
ShowMessageRequest.create({
type: ShowMessageType.INFORMATION,
message: "Commit message generated",
options: {
modal: false,
detail: message,
items: [copyAction, applyAction, editAction],
},
}),
)
)?.selectedOption
await getHostBridgeProvider().windowClient.showMessage({
type: ShowMessageType.INFORMATION,
message: "Commit message generated",
options: {
modal: false,
detail: message,
items: [copyAction, applyAction, editAction],
},
})
).selectedOption
// Handle user dismissing the dialog (selectedAction is undefined)
if (!selectedAction) {
@@ -120,28 +116,22 @@ async function applyCommitMessageToGitInput(message: string): Promise<void> {
if (api && api.repositories.length > 0) {
const repo = api.repositories[0]
repo.inputBox.value = message
getHostBridgeProvider().windowClient.showMessage(
ShowMessageRequest.create({
type: ShowMessageType.INFORMATION,
message: "Commit message applied to Git input",
}),
)
getHostBridgeProvider().windowClient.showMessage({
type: ShowMessageType.INFORMATION,
message: "Commit message applied to Git input",
})
} else {
getHostBridgeProvider().windowClient.showMessage(
ShowMessageRequest.create({
type: ShowMessageType.ERROR,
message: "No Git repositories found",
}),
)
getHostBridgeProvider().windowClient.showMessage({
type: ShowMessageType.ERROR,
message: "No Git repositories found",
})
await copyCommitMessageToClipboard(message)
}
} else {
getHostBridgeProvider().windowClient.showMessage(
ShowMessageRequest.create({
type: ShowMessageType.ERROR,
message: "Git extension not found",
}),
)
getHostBridgeProvider().windowClient.showMessage({
type: ShowMessageType.ERROR,
message: "Git extension not found",
})
await copyCommitMessageToClipboard(message)
}
}
@@ -161,10 +151,8 @@ async function editCommitMessage(message: string): Promise<void> {
path: document.uri.fsPath,
}),
)
getHostBridgeProvider().windowClient.showMessage(
ShowMessageRequest.create({
type: ShowMessageType.INFORMATION,
message: "Edit the commit message and copy when ready",
}),
)
getHostBridgeProvider().windowClient.showMessage({
type: ShowMessageType.INFORMATION,
message: "Edit the commit message and copy when ready",
})
}