Skip to content

Commit 7f20ce5

Browse files
committed
feat(amazonq): add keyboard shortcut for stop/reject/run commands; avaiable if webview is focus
1 parent e49f15f commit 7f20ce5

File tree

6 files changed

+73
-3
lines changed

6 files changed

+73
-3
lines changed

packages/amazonq/package.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,21 @@
560560
]
561561
},
562562
"commands": [
563+
{
564+
"command": "aws.amazonq.stopCmdExecution",
565+
"title": "Stop Amazon Q Command Execution",
566+
"category": "%AWS.amazonq.title%"
567+
},
568+
{
569+
"command": "aws.amazonq.runCmdExecution",
570+
"title": "Run Amazon Q Command Execution",
571+
"category": "%AWS.amazonq.title%"
572+
},
573+
{
574+
"command": "aws.amazonq.rejectCmdExecution",
575+
"title": "Reject Amazon Q Command Execution",
576+
"category": "%AWS.amazonq.title%"
577+
},
563578
{
564579
"command": "_aws.amazonq.notifications.dismiss",
565580
"title": "%AWS.generic.dismiss%",
@@ -850,6 +865,24 @@
850865
}
851866
],
852867
"keybindings": [
868+
{
869+
"command": "aws.amazonq.stopCmdExecution",
870+
"key": "ctrl+shift+backspace",
871+
"mac": "cmd+shift+backspace",
872+
"when": "aws.amazonq.amazonqChatLSP.isFocus"
873+
},
874+
{
875+
"command": "aws.amazonq.runCmdExecution",
876+
"key": "ctrl+shift+enter",
877+
"mac": "cmd+shift+enter",
878+
"when": "aws.amazonq.amazonqChatLSP.isFocus"
879+
},
880+
{
881+
"command": "aws.amazonq.rejectCmdExecution",
882+
"key": "ctrl+shift+r",
883+
"mac": "cmd+shift+r",
884+
"when": "aws.amazonq.amazonqChatLSP.isFocus"
885+
},
853886
{
854887
"command": "_aws.amazonq.focusChat.keybinding",
855888
"win": "win+alt+i",

packages/amazonq/src/lsp/chat/commands.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ export function registerCommands(provider: AmazonQChatViewProvider) {
5959
params: {},
6060
})
6161
})
62-
})
62+
}),
63+
registerShellCommandShortCut('aws.amazonq.runCmdExecution', 'run-shell-command', provider),
64+
registerShellCommandShortCut('aws.amazonq.rejectCmdExecution', 'reject-shell-command', provider),
65+
registerShellCommandShortCut('aws.amazonq.stopCmdExecution', 'stop-shell-command', provider)
6366
)
6467
}
6568

@@ -156,3 +159,14 @@ export async function focusAmazonQPanel() {
156159
await Commands.tryExecute('aws.amazonq.AmazonQChatView.focus')
157160
await Commands.tryExecute('aws.amazonq.AmazonCommonAuth.focus')
158161
}
162+
163+
function registerShellCommandShortCut(commandName: string, buttonId: string, provider: AmazonQChatViewProvider) {
164+
return Commands.register(commandName, async () => {
165+
void focusAmazonQPanel().then(() => {
166+
void provider.webview?.postMessage({
167+
command: 'aws/chat/executeShellCommandShortCut',
168+
params: { id: buttonId },
169+
})
170+
})
171+
})
172+
}

packages/amazonq/src/lsp/chat/messages.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,14 @@ import {
8181
SecurityIssueTreeViewProvider,
8282
CodeWhispererConstants,
8383
} from 'aws-core-vscode/codewhisperer'
84-
import { amazonQDiffScheme, AmazonQPromptSettings, messages, openUrl, isTextEditor } from 'aws-core-vscode/shared'
84+
import {
85+
amazonQDiffScheme,
86+
AmazonQPromptSettings,
87+
messages,
88+
openUrl,
89+
isTextEditor,
90+
setContext,
91+
} from 'aws-core-vscode/shared'
8592
import {
8693
DefaultAmazonQAppInitContext,
8794
messageDispatcher,
@@ -451,6 +458,11 @@ export function registerMessageListeners(
451458
}
452459
default:
453460
if (isServerEvent(message.command)) {
461+
if (enterFocus(message.params)) {
462+
await setContext('aws.amazonq.amazonqChatLSP.isFocus', true)
463+
} else if (exitFocus(message.params)) {
464+
await setContext('aws.amazonq.amazonqChatLSP.isFocus', false)
465+
}
454466
languageClient.sendNotification(message.command, message.params)
455467
}
456468
break
@@ -660,6 +672,14 @@ function isServerEvent(command: string) {
660672
return command.startsWith('aws/chat/') || command === 'telemetry/event'
661673
}
662674

675+
function enterFocus(params: any) {
676+
return params.name === 'enterFocus'
677+
}
678+
679+
function exitFocus(params: any) {
680+
return params.name === 'exitFocus'
681+
}
682+
663683
/**
664684
* Decodes partial chat responses from the language server before sending them to mynah UI
665685
*/

packages/amazonq/src/lsp/chat/webviewProvider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
Webview,
1414
} from 'vscode'
1515
import * as path from 'path'
16+
import * as os from 'os'
1617
import {
1718
globals,
1819
isSageMaker,
@@ -149,7 +150,7 @@ export class AmazonQChatViewProvider implements WebviewViewProvider {
149150
const vscodeApi = acquireVsCodeApi()
150151
const hybridChatConnector = new HybridChatAdapter(${(await AuthUtil.instance.getChatAuthState()).amazonQ === 'connected'},${featureConfigData},${welcomeCount},${disclaimerAcknowledged},${regionProfileString},${disabledCommands},${isSMUS},${isSM},vscodeApi.postMessage)
151152
const commands = [hybridChatConnector.initialQuickActions[0]]
152-
qChat = amazonQChat.createChat(vscodeApi, {disclaimerAcknowledged: ${disclaimerAcknowledged}, pairProgrammingAcknowledged: ${pairProgrammingAcknowledged}, agenticMode: true, quickActionCommands: commands, modelSelectionEnabled: ${modelSelectionEnabled}}, hybridChatConnector, ${JSON.stringify(featureConfigData)});
153+
qChat = amazonQChat.createChat(vscodeApi, {os: "${os.platform()}", disclaimerAcknowledged: ${disclaimerAcknowledged}, pairProgrammingAcknowledged: ${pairProgrammingAcknowledged}, agenticMode: true, quickActionCommands: commands, modelSelectionEnabled: ${modelSelectionEnabled}}, hybridChatConnector, ${JSON.stringify(featureConfigData)});
153154
}
154155
window.addEventListener('message', (event) => {
155156
/**

packages/amazonq/src/lsp/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ export async function startLanguageServer(
183183
pinnedContextEnabled: true,
184184
imageContextEnabled: true,
185185
mcp: true,
186+
shortcut: true,
186187
reroute: true,
187188
modelSelection: true,
188189
workspaceFilePath: vscode.workspace.workspaceFile?.fsPath,

packages/core/src/shared/vscode/setContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export type contextKey =
4040
| 'gumby.wasQCodeTransformationUsed'
4141
| 'amazonq.inline.codelensShortcutEnabled'
4242
| 'aws.toolkit.lambda.walkthroughSelected'
43+
| 'aws.amazonq.amazonqChatLSP.isFocus'
4344

4445
const contextMap: Partial<Record<contextKey, any>> = {}
4546

0 commit comments

Comments
 (0)