Skip to content

Commit eee8be2

Browse files
committed
feat: handle short cut to execute shell command
1 parent 0cebf28 commit eee8be2

File tree

5 files changed

+55
-20
lines changed

5 files changed

+55
-20
lines changed

packages/amazonq/package.json

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,18 @@
544544
},
545545
"commands": [
546546
{
547-
"command": "aws.amazonq.stopToolExecution",
548-
"title": "Stop Amazon Q Tool Execution",
547+
"command": "aws.amazonq.stopCmdExecution",
548+
"title": "Stop Amazon Q Command Execution",
549+
"category": "%AWS.amazonq.title%"
550+
},
551+
{
552+
"command": "aws.amazonq.runCmdExecution",
553+
"title": "Run Amazon Q Command Execution",
554+
"category": "%AWS.amazonq.title%"
555+
},
556+
{
557+
"command": "aws.amazonq.rejectCmdExecution",
558+
"title": "Reject Amazon Q Command Execution",
549559
"category": "%AWS.amazonq.title%"
550560
},
551561
{
@@ -901,9 +911,22 @@
901911
"when": "editorTextFocus && aws.codewhisperer.connected && amazonq.inline.codelensShortcutEnabled"
902912
},
903913
{
904-
"command": "aws.amazonq.stopToolExecution",
914+
"command": "aws.amazonq.stopCmdExecution",
915+
"key": "cmd+alt+s",
916+
"mac": "cmd+alt+s",
917+
"when": "aws.amazonq.amazonqChatLSP.isRunning"
918+
},
919+
{
920+
"command": "aws.amazonq.runCmdExecution",
921+
"key": "cmd+alt+r",
922+
"mac": "cmd+alt+r",
923+
"when": "aws.amazonq.amazonqChatLSP.isRunning"
924+
},
925+
{
926+
"command": "aws.amazonq.rejectCmdExecution",
905927
"key": "cmd+alt+h",
906-
"mac": "cmd+alt+h"
928+
"mac": "cmd+alt+h",
929+
"when": "aws.amazonq.amazonqChatLSP.isRunning"
907930
}
908931
],
909932
"icons": {

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@ import { DefaultAmazonQAppInitContext } from 'aws-core-vscode/amazonq'
1616
*/
1717
export function registerCommands(provider: AmazonQChatViewProvider) {
1818
globals.context.subscriptions.push(
19-
Commands.register('aws.amazonq.stopToolExecution', async () => {
20-
void focusAmazonQPanel().then(() => {
21-
void provider.webview?.postMessage({
22-
command: 'stopChatResponse',
23-
params: {}, // how to get the current tabId?
24-
})
25-
})
26-
}),
2719
registerGenericCommand('aws.amazonq.explainCode', 'Explain', provider),
2820
registerGenericCommand('aws.amazonq.refactorCode', 'Refactor', provider),
2921
registerGenericCommand('aws.amazonq.fixCode', 'Fix', provider),
@@ -92,7 +84,10 @@ export function registerCommands(provider: AmazonQChatViewProvider) {
9284
params: {},
9385
})
9486
})
95-
})
87+
}),
88+
registerShellCommandShortCut('aws.amazonq.runCmdExecution', 'run-shell-command', provider),
89+
registerShellCommandShortCut('aws.amazonq.rejectCmdExecution', 'reject-shell-command', provider),
90+
registerShellCommandShortCut('aws.amazonq.stopCmdExecution', 'stop-shell-command', provider)
9691
)
9792
}
9893

@@ -137,3 +132,14 @@ async function focusAmazonQPanel() {
137132
await Commands.tryExecute('aws.amazonq.AmazonQChatView.focus')
138133
await Commands.tryExecute('aws.amazonq.AmazonCommonAuth.focus')
139134
}
135+
136+
function registerShellCommandShortCut(commandName: string, buttonId: string, provider: AmazonQChatViewProvider) {
137+
return Commands.register(commandName, async () => {
138+
void focusAmazonQPanel().then(() => {
139+
void provider.webview?.postMessage({
140+
command: 'executeShellCommandShortCut',
141+
params: { buttonId },
142+
})
143+
})
144+
})
145+
}

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,6 @@ export function registerMessageListeners(
133133
}
134134

135135
const webview = provider.webview
136-
if (message.command === 'stopChatResponse') {
137-
const tabId = (message as StopChatResponseMessage).params.tabId
138-
const token = chatStreamTokens.get(tabId)
139-
token?.cancel()
140-
token?.dispose()
141-
chatStreamTokens.delete(tabId)
142-
}
143136
switch (message.command) {
144137
case COPY_TO_CLIPBOARD:
145138
languageClient.info('[VSCode Client] Copy to clipboard event received')

packages/amazonq/src/lsp/client.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
getLogger,
3333
undefinedIfEmpty,
3434
getOptOutPreference,
35+
setContext,
3536
} from 'aws-core-vscode/shared'
3637
import { activate } from './chat/activation'
3738
import { AmazonQResourcePaths } from './lspInstaller'
@@ -157,6 +158,17 @@ export async function startLanguageServer(
157158

158159
if (Experiments.instance.get('amazonqChatLSP', true)) {
159160
await activate(client, encryptionKey, resourcePaths.ui)
161+
162+
await setContext('aws.amazonq.amazonqChatLSP.isRunning', true)
163+
getLogger().info('Amazon Q Chat LSP context flag set on client activated')
164+
165+
// Add a disposable to reset the context flag when the client stops
166+
toDispose.push({
167+
dispose: async () => {
168+
await setContext('aws.amazonq.amazonqChatLSP.isRunning', false)
169+
getLogger().info('Amazon Q Chat LSP context flag reset on client disposal')
170+
},
171+
})
160172
}
161173

162174
const refreshInterval = auth.startTokenRefreshInterval(10 * oneSecond)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export type contextKey =
3939
| 'gumby.wasQCodeTransformationUsed'
4040
| 'amazonq.inline.codelensShortcutEnabled'
4141
| 'aws.toolkit.lambda.walkthroughSelected'
42+
| 'aws.amazonq.amazonqChatLSP.isRunning'
4243

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

0 commit comments

Comments
 (0)