Skip to content

Commit cd9be21

Browse files
authored
feat(amazonq): more global commands aws#4965
Commands Added - Amazon Q: Focus on Chat View - Amazon Q: Open Code Reference Log - Amazon Q: Select Customizations - Amazon Q: Toggle Auto-Scans - Amazon Q: Toggle Auto-Suggestions - Amazon Q: Try inline suggestion example - Amazon Q: Sign out Notes: - Amazon Q commands are now displayed when the user is logged in. - Auto-Scans and Select Customizations commands are enabled when the user is not logged in using builder-id
1 parent b1a65c6 commit cd9be21

File tree

9 files changed

+90
-24
lines changed

9 files changed

+90
-24
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "Add additional commands for Amazon Q."
4+
}

packages/amazonq/package.json

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,10 @@
217217
],
218218
"menus": {
219219
"commandPalette": [
220-
{
221-
"command": "aws.amazonq.signout",
222-
"when": "false"
223-
},
224220
{
225221
"command": "aws.amazonq.reconnect",
226222
"when": "false"
227223
},
228-
{
229-
"command": "aws.amazonq.openReferencePanel",
230-
"when": "false"
231-
},
232224
{
233225
"command": "amazonq.dev.openMenu",
234226
"when": "aws.isDevMode"
@@ -365,42 +357,50 @@
365357
{
366358
"command": "aws.amazonq.explainCode",
367359
"title": "%AWS.command.amazonq.explainCode%",
368-
"category": "%AWS.amazonq.title%"
360+
"category": "%AWS.amazonq.title%",
361+
"enablement": "aws.codewhisperer.connected"
369362
},
370363
{
371364
"command": "aws.amazonq.security.scan",
372365
"title": "%AWS.command.amazonq.security.scan%",
373-
"category": "%AWS.amazonq.title%"
366+
"category": "%AWS.amazonq.title%",
367+
"enablement": "aws.codewhisperer.connected"
374368
},
375369
{
376370
"command": "aws.amazonq.refactorCode",
377371
"title": "%AWS.command.amazonq.refactorCode%",
378-
"category": "%AWS.amazonq.title%"
372+
"category": "%AWS.amazonq.title%",
373+
"enablement": "aws.codewhisperer.connected"
379374
},
380375
{
381376
"command": "aws.amazonq.fixCode",
382377
"title": "%AWS.command.amazonq.fixCode%",
383-
"category": "%AWS.amazonq.title%"
378+
"category": "%AWS.amazonq.title%",
379+
"enablement": "aws.codewhisperer.connected"
384380
},
385381
{
386382
"command": "aws.amazonq.optimizeCode",
387383
"title": "%AWS.command.amazonq.optimizeCode%",
388-
"category": "%AWS.amazonq.title%"
384+
"category": "%AWS.amazonq.title%",
385+
"enablement": "aws.codewhisperer.connected"
389386
},
390387
{
391388
"command": "aws.amazonq.sendToPrompt",
392389
"title": "%AWS.command.amazonq.sendToPrompt%",
393-
"category": "%AWS.amazonq.title%"
390+
"category": "%AWS.amazonq.title%",
391+
"enablement": "aws.codewhisperer.connected"
394392
},
395393
{
396394
"command": "aws.amazonq.reconnect",
397395
"title": "%AWS.command.codewhisperer.reconnect%",
398-
"category": "%AWS.amazonq.title%"
396+
"category": "%AWS.amazonq.title%",
397+
"enablement": "aws.codewhisperer.connected"
399398
},
400399
{
401400
"command": "aws.amazonq.openReferencePanel",
402401
"title": "%AWS.command.codewhisperer.openReferencePanel%",
403-
"category": "%AWS.amazonq.title%"
402+
"category": "%AWS.amazonq.title%",
403+
"enablement": "aws.codewhisperer.connected"
404404
},
405405
{
406406
"command": "aws.amazonq.transformationHub.reviewChanges.acceptChanges",
@@ -455,7 +455,8 @@
455455
{
456456
"command": "aws.amazonq.invokeInlineCompletion",
457457
"title": "%AWS.command.codewhisperer.title%",
458-
"category": "%AWS.amazonq.title%"
458+
"category": "%AWS.amazonq.title%",
459+
"enablement": "aws.codewhisperer.connected"
459460
},
460461
{
461462
"command": "aws.amazonq.configure",
@@ -475,6 +476,12 @@
475476
"category": "%AWS.amazonq.title%",
476477
"icon": "$(debug-disconnect)"
477478
},
479+
{
480+
"command": "aws.amazonq.signout",
481+
"title": "%AWS.command.codewhisperer.signout%",
482+
"category": "%AWS.amazonq.title%",
483+
"enablement": "aws.codewhisperer.connected"
484+
},
478485
{
479486
"command": "aws.amazonq.learnMore",
480487
"title": "%AWS.amazonq.learnMore%",
@@ -501,6 +508,30 @@
501508
"command": "aws.amazonq.showHistoryInHub",
502509
"title": "Show Job Status",
503510
"icon": "$(history)"
511+
},
512+
{
513+
"command": "aws.amazonq.selectCustomization",
514+
"title": "%AWS.codewhisperer.customization.notification.new_customizations.select%",
515+
"category": "%AWS.amazonq.title%",
516+
"enablement": "aws.codewhisperer.connected"
517+
},
518+
{
519+
"command": "aws.amazonq.gettingStarted",
520+
"title": "Try inline suggestion examples",
521+
"category": "%AWS.amazonq.title%",
522+
"enablement": "aws.codewhisperer.connected"
523+
},
524+
{
525+
"command": "aws.amazonq.toggleCodeSuggestion",
526+
"title": "%AWS.amazonq.toggleCodeSuggestion%",
527+
"category": "%AWS.amazonq.title%",
528+
"enablement": "aws.codewhisperer.connected"
529+
},
530+
{
531+
"command": "aws.codeWhisperer.toggleCodeScan",
532+
"title": "%AWS.amazonq.toggleCodeScan%",
533+
"category": "%AWS.amazonq.title%",
534+
"enablement": "aws.codewhisperer.connected"
504535
}
505536
],
506537
"keybindings": [

packages/core/package.nls.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,5 +254,7 @@
254254
"AWS.amazonq.chat": "Chat",
255255
"AWS.amazonq.login": "Login",
256256
"AWS.amazonq.learnMore": "Learn More About Amazon Q",
257-
"AWS.amazonq.codewhisperer.title": "Amazon Q"
257+
"AWS.amazonq.codewhisperer.title": "Amazon Q",
258+
"AWS.amazonq.toggleCodeSuggestion": "Toggle Auto-Suggestions",
259+
"AWS.amazonq.toggleCodeScan": "Toggle Auto-Scans"
258260
}

packages/core/src/codecatalyst/commands.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { CreateDevEnvironmentRequest, UpdateDevEnvironmentRequest } from 'aws-sd
2626
import { Auth } from '../auth/auth'
2727
import { SsoConnection } from '../auth/connection'
2828
import { isInDevEnv, isRemoteWorkspace } from '../shared/vscode/env'
29+
import { commandPalette } from '../codewhisperer/commands/types'
2930

3031
/** "List CodeCatalyst Commands" command. */
3132
export async function listCommands(): Promise<void> {
@@ -303,7 +304,7 @@ export class CodeCatalystCommands {
303304
// need to be careful of mapping explosion so this granular data would either need
304305
// to be flattened or we restrict the names to a pre-determined set
305306
if (id === undefined) {
306-
telemetry.record({ source: 'CommandPalette' })
307+
telemetry.record({ source: commandPalette })
307308
}
308309

309310
if (connection !== undefined) {

packages/core/src/codewhisperer/commands/basicCommands.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ import { SsoAccessTokenProvider } from '../../auth/sso/ssoAccessTokenProvider'
4141
import { SystemUtilities } from '../../shared/systemUtilities'
4242
import { ToolkitError } from '../../shared/errors'
4343
import { isRemoteWorkspace } from '../../shared/vscode/env'
44-
import { hasScopes } from '../../auth/connection'
44+
import { hasScopes, isBuilderIdConnection } from '../../auth/connection'
4545
import globals from '../../shared/extensionGlobals'
4646

47+
const MessageTimeOut = 5_000
48+
4749
export const toggleCodeSuggestions = Commands.declare(
4850
{ id: 'aws.amazonq.toggleCodeSuggestion', compositeKey: { 1: 'source' } },
4951
(suggestionState: CodeSuggestionsState) => async (_: VsCodeCommandArg, source: CodeWhispererSource) => {
@@ -53,12 +55,20 @@ export const toggleCodeSuggestions = Commands.declare(
5355
})
5456

5557
const isSuggestionsEnabled = await suggestionState.toggleSuggestions()
58+
5659
span.record({
5760
settingState: isSuggestionsEnabled
5861
? CodeWhispererConstants.autoSuggestionConfig.activated
5962
: CodeWhispererConstants.autoSuggestionConfig.deactivated,
6063
})
6164
vsCodeState.isFreeTierLimitReached = false
65+
66+
void vscode.window.setStatusBarMessage(
67+
isSuggestionsEnabled
68+
? 'Amazon Q: Auto-Suggestions are currently running.'
69+
: 'Amazon Q: Auto-Suggestions are currently paused.',
70+
MessageTimeOut
71+
)
6272
})
6373
}
6474
)
@@ -81,6 +91,9 @@ export const toggleCodeScans = Commands.declare(
8191
{ id: 'aws.codeWhisperer.toggleCodeScan', compositeKey: { 1: 'source' } },
8292
(scansState: CodeScansState) => async (_: VsCodeCommandArg, source: CodeWhispererSource) => {
8393
await telemetry.aws_modifySetting.run(async span => {
94+
if (isBuilderIdConnection(AuthUtil.instance.conn)) {
95+
throw new Error(`Auto-scans are not supported with the Amazon Builder ID connection.`)
96+
}
8497
span.record({
8598
settingId: CodeWhispererConstants.autoScansConfig.settingId,
8699
})
@@ -93,6 +106,12 @@ export const toggleCodeScans = Commands.declare(
93106
})
94107

95108
await vscode.commands.executeCommand('aws.amazonq.refreshStatusBar')
109+
void vscode.window.setStatusBarMessage(
110+
isScansEnabled
111+
? 'Amazon Q: Auto-Scans are currently running.'
112+
: 'Amazon Q: Auto-Scans are currently paused.',
113+
MessageTimeOut
114+
)
96115
})
97116
}
98117
)
@@ -134,6 +153,9 @@ export const showSecurityScan = Commands.declare(
134153
export const selectCustomizationPrompt = Commands.declare(
135154
{ id: 'aws.amazonq.selectCustomization', compositeKey: { 1: 'source' } },
136155
() => async (_: VsCodeCommandArg, source: CodeWhispererSource) => {
156+
if (isBuilderIdConnection(AuthUtil.instance.conn)) {
157+
throw new Error(`Select Customizations are not supported with the Amazon Builder ID connection.`)
158+
}
137159
telemetry.ui_click.emit({ elementId: 'cw_selectCustomization_Cta' })
138160
void showCustomizationPrompt().then()
139161
}

packages/core/src/codewhisperer/commands/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export const amazonQChatSource = 'amazonQChat'
1616
export const firstStartUpSource = ExtStartUpSources.firstStartUp
1717
/** Indicates a CodeWhisperer command was executed as a result of selecting an ellipses menu item */
1818
export const cwEllipsesMenu = 'ellipsesMenu'
19+
/** Indicates a CodeWhisperer command was executed from the command palette */
20+
export const commandPalette = 'commandPalette'
1921

2022
/**
2123
* Indicates what caused the CodeWhisperer command to be executed, since a command can be executed from different "sources"
@@ -32,3 +34,4 @@ export type CodeWhispererSource =
3234
| typeof amazonQChatSource
3335
| typeof firstStartUpSource
3436
| typeof cwEllipsesMenu
37+
| typeof commandPalette

packages/core/src/codewhispererChat/commands/registerCommands.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
import { commandPalette } from '../../codewhisperer/commands/types'
67
import { CodeScanIssue } from '../../codewhisperer/models/model'
78
import { Commands, VsCodeCommandArg, placeholder } from '../../shared/vscode/commands2'
89
import { ChatControllerMessagePublishers } from '../controllers/chat/controller'
@@ -106,7 +107,7 @@ export type CodeScanIssueCommandType = 'aws.amazonq.explainIssue'
106107

107108
export type EditorContextCommandType = EditorContextBaseCommandType | CodeScanIssueCommandType
108109

109-
export type EditorContextCommandTriggerType = 'contextMenu' | 'keybinding' | 'commandPalette' | 'click'
110+
export type EditorContextCommandTriggerType = 'contextMenu' | 'keybinding' | typeof commandPalette | 'click'
110111

111112
export interface EditorContextCommandBase {
112113
type: EditorContextBaseCommandType

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,9 @@ function handleBadCompositeKey(data: { id: string; args: any[]; compositeKey: Co
520520
Object.entries(compositeKey).forEach(([index, field]) => {
521521
const indexAsInt = parseInt(index)
522522
const arg = args[indexAsInt]
523-
if (field === 'source' && typeof arg !== 'string') {
523+
if (field === 'source' && arg === undefined) {
524+
args[indexAsInt] = 'vscodeUI'
525+
} else if (field === 'source' && typeof arg !== 'string') {
524526
/**
525527
* This case happens when either the caller sets the wrong args themselves through
526528
* vscode.commands.executeCommand OR if through a VS Code UI component like the ellipsis menu

packages/core/src/test/shared/vscode/runCommand.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as sinon from 'sinon'
99
import assert from 'assert'
1010
import { ToolkitError } from '../../../shared/errors'
1111
import { CancellationError } from '../../../shared/utilities/timeoutUtils'
12-
import { Commands, defaultTelemetryThrottleMs, unsetSource } from '../../../shared/vscode/commands2'
12+
import { Commands, defaultTelemetryThrottleMs } from '../../../shared/vscode/commands2'
1313
import { assertTelemetry, installFakeClock } from '../../testUtil'
1414
import { getTestWindow } from '../../shared/vscode/window'
1515

@@ -168,7 +168,7 @@ describe('runCommand', function () {
168168
passive: true,
169169
command: command.id,
170170
result: 'Succeeded',
171-
source: unsetSource,
171+
source: 'vscodeUI',
172172
})
173173
})
174174
})

0 commit comments

Comments
 (0)