Skip to content

Commit a0f36ab

Browse files
committed
feat: handle short cut to execute shell command
1 parent 81fa3b1 commit a0f36ab

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

packages/amazonq/package.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,21 @@
543543
]
544544
},
545545
"commands": [
546+
{
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",
559+
"category": "%AWS.amazonq.title%"
560+
},
546561
{
547562
"command": "_aws.amazonq.notifications.dismiss",
548563
"title": "%AWS.generic.dismiss%",
@@ -808,6 +823,24 @@
808823
}
809824
],
810825
"keybindings": [
826+
{
827+
"command": "aws.amazonq.stopCmdExecution",
828+
"key": "cmd+alt+s",
829+
"mac": "cmd+alt+s",
830+
"when": "aws.amazonq.amazonqChatLSP.isRunning"
831+
},
832+
{
833+
"command": "aws.amazonq.runCmdExecution",
834+
"key": "cmd+alt+r",
835+
"mac": "cmd+alt+r",
836+
"when": "aws.amazonq.amazonqChatLSP.isRunning"
837+
},
838+
{
839+
"command": "aws.amazonq.rejectCmdExecution",
840+
"key": "cmd+alt+h",
841+
"mac": "cmd+alt+h",
842+
"when": "aws.amazonq.amazonqChatLSP.isRunning"
843+
},
811844
{
812845
"command": "_aws.amazonq.focusChat.keybinding",
813846
"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
@@ -84,7 +84,10 @@ export function registerCommands(provider: AmazonQChatViewProvider) {
8484
params: {},
8585
})
8686
})
87-
})
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)
8891
)
8992
}
9093

@@ -129,3 +132,14 @@ async function focusAmazonQPanel() {
129132
await Commands.tryExecute('aws.amazonq.AmazonQChatView.focus')
130133
await Commands.tryExecute('aws.amazonq.AmazonCommonAuth.focus')
131134
}
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/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)