diff --git a/packages/amazonq/package.json b/packages/amazonq/package.json index 47d1c8c2aa0..5b1e5e44282 100644 --- a/packages/amazonq/package.json +++ b/packages/amazonq/package.json @@ -543,6 +543,21 @@ ] }, "commands": [ + { + "command": "aws.amazonq.stopCmdExecution", + "title": "Stop Amazon Q Command Execution", + "category": "%AWS.amazonq.title%" + }, + { + "command": "aws.amazonq.runCmdExecution", + "title": "Run Amazon Q Command Execution", + "category": "%AWS.amazonq.title%" + }, + { + "command": "aws.amazonq.rejectCmdExecution", + "title": "Reject Amazon Q Command Execution", + "category": "%AWS.amazonq.title%" + }, { "command": "_aws.amazonq.notifications.dismiss", "title": "%AWS.generic.dismiss%", @@ -808,6 +823,24 @@ } ], "keybindings": [ + { + "command": "aws.amazonq.stopCmdExecution", + "key": "cmd+alt+s", + "mac": "cmd+alt+s", + "when": "aws.amazonq.amazonqChatLSP.isRunning" + }, + { + "command": "aws.amazonq.runCmdExecution", + "key": "cmd+alt+r", + "mac": "cmd+alt+r", + "when": "aws.amazonq.amazonqChatLSP.isRunning" + }, + { + "command": "aws.amazonq.rejectCmdExecution", + "key": "cmd+alt+h", + "mac": "cmd+alt+h", + "when": "aws.amazonq.amazonqChatLSP.isRunning" + }, { "command": "_aws.amazonq.focusChat.keybinding", "win": "win+alt+i", diff --git a/packages/amazonq/src/lsp/chat/commands.ts b/packages/amazonq/src/lsp/chat/commands.ts index 74c63592a4f..b8e359e8279 100644 --- a/packages/amazonq/src/lsp/chat/commands.ts +++ b/packages/amazonq/src/lsp/chat/commands.ts @@ -84,7 +84,10 @@ export function registerCommands(provider: AmazonQChatViewProvider) { params: {}, }) }) - }) + }), + registerShellCommandShortCut('aws.amazonq.runCmdExecution', 'run-shell-command', provider), + registerShellCommandShortCut('aws.amazonq.rejectCmdExecution', 'reject-shell-command', provider), + registerShellCommandShortCut('aws.amazonq.stopCmdExecution', 'stop-shell-command', provider) ) } @@ -129,3 +132,14 @@ async function focusAmazonQPanel() { await Commands.tryExecute('aws.amazonq.AmazonQChatView.focus') await Commands.tryExecute('aws.amazonq.AmazonCommonAuth.focus') } + +function registerShellCommandShortCut(commandName: string, buttonId: string, provider: AmazonQChatViewProvider) { + return Commands.register(commandName, async () => { + void focusAmazonQPanel().then(() => { + void provider.webview?.postMessage({ + command: 'executeShellCommandShortCut', + params: { buttonId }, + }) + }) + }) +} diff --git a/packages/amazonq/src/lsp/client.ts b/packages/amazonq/src/lsp/client.ts index d813370cb0b..5d8654b681c 100644 --- a/packages/amazonq/src/lsp/client.ts +++ b/packages/amazonq/src/lsp/client.ts @@ -32,6 +32,7 @@ import { getLogger, undefinedIfEmpty, getOptOutPreference, + setContext, } from 'aws-core-vscode/shared' import { activate } from './chat/activation' import { AmazonQResourcePaths } from './lspInstaller' @@ -157,6 +158,17 @@ export async function startLanguageServer( if (Experiments.instance.get('amazonqChatLSP', true)) { await activate(client, encryptionKey, resourcePaths.ui) + + await setContext('aws.amazonq.amazonqChatLSP.isRunning', true) + getLogger().info('Amazon Q Chat LSP context flag set on client activated') + + // Add a disposable to reset the context flag when the client stops + toDispose.push({ + dispose: async () => { + await setContext('aws.amazonq.amazonqChatLSP.isRunning', false) + getLogger().info('Amazon Q Chat LSP context flag reset on client disposal') + }, + }) } const refreshInterval = auth.startTokenRefreshInterval(10 * oneSecond) diff --git a/packages/core/src/shared/vscode/setContext.ts b/packages/core/src/shared/vscode/setContext.ts index b630a708d15..3cdaff36418 100644 --- a/packages/core/src/shared/vscode/setContext.ts +++ b/packages/core/src/shared/vscode/setContext.ts @@ -39,6 +39,7 @@ export type contextKey = | 'gumby.wasQCodeTransformationUsed' | 'amazonq.inline.codelensShortcutEnabled' | 'aws.toolkit.lambda.walkthroughSelected' + | 'aws.amazonq.amazonqChatLSP.isRunning' const contextMap: Partial> = {}