Skip to content

Commit 71351d7

Browse files
amazonq: command to show the chat window (#4756)
Before, we had a function to show the chat webview or used the vscode generated show chat command. Now we have a single command which can be used anywhere. This will allow us to get better metrics on when the chat window is opened. Signed-off-by: Nikolas Komonen <[email protected]>
1 parent e0c460e commit 71351d7

File tree

5 files changed

+29
-24
lines changed

5 files changed

+29
-24
lines changed

packages/core/src/amazonq/activation.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import { init as cwChatAppInit } from '../codewhispererChat/app'
99
import { init as featureDevChatAppInit } from '../amazonqFeatureDev/app'
1010
import { init as gumbyChatAppInit } from '../amazonqGumby/app'
1111
import { AmazonQAppInitContext, DefaultAmazonQAppInitContext } from './apps/initContext'
12-
import { Commands, VsCodeCommandArg } from '../shared/vscode/commands2'
12+
import { Commands, VsCodeCommandArg, placeholder } from '../shared/vscode/commands2'
1313
import { MessagePublisher } from './messages/messagePublisher'
1414
import { welcome } from './onboardingPage'
1515
import { learnMoreAmazonQCommand, switchToAmazonQCommand } from './explorer/amazonQChildrenNodes'
1616
import { activateBadge } from './util/viewBadgeHandler'
1717
import { telemetry } from '../shared/telemetry/telemetry'
18-
import { focusAmazonQPanel } from '../auth/ui/vue/show'
18+
import { focusAmazonQPanel } from '../codewhispererChat/commands/registerCommands'
1919

2020
export async function activate(context: ExtensionContext) {
2121
const appInitContext = DefaultAmazonQAppInitContext.instance
@@ -36,7 +36,8 @@ export async function activate(context: ExtensionContext) {
3636
webviewOptions: {
3737
retainContextWhenHidden: true,
3838
},
39-
})
39+
}),
40+
focusAmazonQPanel.register()
4041
)
4142

4243
amazonQWelcomeCommand.register(context, cwcWebViewToAppsPublisher)
@@ -56,7 +57,7 @@ export const amazonQWelcomeCommand = Commands.declare(
5657
{ id: 'aws.amazonq.welcome', compositeKey: { 1: 'source' } },
5758
(context: ExtensionContext, publisher: MessagePublisher<any>) => (_: VsCodeCommandArg, source: string) => {
5859
telemetry.ui_click.run(() => {
59-
void focusAmazonQPanel()
60+
void focusAmazonQPanel.execute(placeholder, 'welcome')
6061
welcome(context, publisher)
6162
telemetry.record({ elementId: 'toolkit_openedWelcomeToAmazonQPage', source })
6263
})

packages/core/src/amazonq/explorer/amazonQChildrenNodes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import { reconnect } from '../../codewhisperer/commands/basicCommands'
1111
import { amazonQHelpUrl } from '../../shared/constants'
1212
import { cwTreeNodeSource } from '../../codewhisperer/commands/types'
1313
import { telemetry } from '../../shared/telemetry/telemetry'
14-
import { focusAmazonQPanel } from '../../auth/ui/vue/show'
1514
import { DataQuickPickItem } from '../../shared/ui/pickerPrompter'
1615
import { TreeNode } from '../../shared/treeview/resourceTreeDataProvider'
16+
import { focusAmazonQPanel } from '../../codewhispererChat/commands/registerCommands'
1717

1818
const localize = nls.loadMessageBundle()
1919

@@ -33,7 +33,7 @@ export const switchToAmazonQCommand = Commands.declare('_aws.amazonq.focusView',
3333
elementId: 'amazonq_switchToQChat',
3434
passive: false,
3535
})
36-
void focusAmazonQPanel()
36+
void focusAmazonQPanel.execute(placeholder, 'switchToQChat')
3737
})
3838

3939
export function switchToAmazonQNode(type: 'item'): DataQuickPickItem<'openChatPanel'>

packages/core/src/amazonq/onboardingPage/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import globals from '../../shared/extensionGlobals'
88
import path from 'path'
99
import { MessagePublisher } from '../messages/messagePublisher'
1010
import { telemetry } from '../../shared/telemetry/telemetry'
11-
import { focusAmazonQPanel } from '../../auth/ui/vue/show'
1211
import { getLogger } from '../../shared/logger'
12+
import { placeholder } from '../../shared/vscode/commands2'
13+
import { focusAmazonQPanel } from '../../codewhispererChat/commands/registerCommands'
1314

1415
export function welcome(context: vscode.ExtensionContext, cwcWebViewToAppsPublisher: MessagePublisher<any>): void {
1516
const panel = vscode.window.createWebviewPanel(
@@ -35,7 +36,7 @@ export function welcome(context: vscode.ExtensionContext, cwcWebViewToAppsPublis
3536
switch (message.command) {
3637
case 'sendToQ':
3738
telemetry.record({ elementId: 'amazonq_meet_askq' })
38-
focusAmazonQPanel().then(
39+
focusAmazonQPanel.execute(placeholder, 'sendToQ').then(
3940
() => {
4041
cwcWebViewToAppsPublisher.publish({
4142
type: 'onboarding-page-cwc-button-clicked',

packages/core/src/auth/ui/vue/show.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import { debounce } from 'lodash'
5454
import { submitFeedback } from '../../../feedback/vue/submitFeedback'
5555
import { InvalidGrantException } from '@aws-sdk/client-sso-oidc'
5656
import { isWeb } from '../../../common/webUtils'
57+
import { focusAmazonQPanel } from '../../../codewhispererChat/commands/registerCommands'
5758

5859
export class AuthWebview extends VueWebview {
5960
public static readonly sourcePath: string = 'src/auth/ui/vue/index.js'
@@ -183,7 +184,7 @@ export class AuthWebview extends VueWebview {
183184
}
184185

185186
async showAmazonQChat(): Promise<void> {
186-
return focusAmazonQPanel()
187+
return focusAmazonQPanel.execute(placeholder, 'addConnectionPage')
187188
}
188189

189190
async getIdentityCenterRegion(): Promise<Region | undefined> {
@@ -858,11 +859,3 @@ export async function emitWebviewClosed(authWebview: ClassToInterfaceType<AuthWe
858859
return result
859860
}
860861
}
861-
862-
/**
863-
* Forces focus to Amazon Q panel - USE THIS SPARINGLY (don't betray customer trust by hijacking the IDE)
864-
* Used on first load, and any time we want to directly populate chat.
865-
*/
866-
export async function focusAmazonQPanel(): Promise<void> {
867-
await vscode.commands.executeCommand('aws.AmazonQChatView.focus')
868-
}

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { focusAmazonQPanel } from '../../auth/ui/vue/show'
7-
import { Commands } from '../../shared/vscode/commands2'
6+
import { Commands, VsCodeCommandArg, placeholder } from '../../shared/vscode/commands2'
87
import { ChatControllerMessagePublishers } from '../controllers/chat/controller'
8+
import vscode from 'vscode'
9+
10+
/**
11+
* Opens the Amazon Q chat window.
12+
*/
13+
export const focusAmazonQPanel = Commands.declare(
14+
{ id: `aws.amazonq.focusChat`, compositeKey: { 1: 'source' } },
15+
() => async (_: VsCodeCommandArg, source: string) => {
16+
await vscode.commands.executeCommand('aws.AmazonQChatView.focus')
17+
}
18+
)
919

1020
const getCommandTriggerType = (data: any): EditorContextCommandTriggerType => {
1121
// data is undefined when commands triggered from keybinding or command palette. Currently no
@@ -15,39 +25,39 @@ const getCommandTriggerType = (data: any): EditorContextCommandTriggerType => {
1525

1626
export function registerCommands(controllerPublishers: ChatControllerMessagePublishers) {
1727
Commands.register('aws.amazonq.explainCode', async data => {
18-
return focusAmazonQPanel().then(() => {
28+
return focusAmazonQPanel.execute(placeholder, 'amazonq.explainCode').then(() => {
1929
controllerPublishers.processContextMenuCommand.publish({
2030
type: 'aws.amazonq.explainCode',
2131
triggerType: getCommandTriggerType(data),
2232
})
2333
})
2434
})
2535
Commands.register('aws.amazonq.refactorCode', async data => {
26-
return focusAmazonQPanel().then(() => {
36+
return focusAmazonQPanel.execute(placeholder, 'amazonq.refactorCode').then(() => {
2737
controllerPublishers.processContextMenuCommand.publish({
2838
type: 'aws.amazonq.refactorCode',
2939
triggerType: getCommandTriggerType(data),
3040
})
3141
})
3242
})
3343
Commands.register('aws.amazonq.fixCode', async data => {
34-
return focusAmazonQPanel().then(() => {
44+
return focusAmazonQPanel.execute(placeholder, 'amazonq.fixCode').then(() => {
3545
controllerPublishers.processContextMenuCommand.publish({
3646
type: 'aws.amazonq.fixCode',
3747
triggerType: getCommandTriggerType(data),
3848
})
3949
})
4050
})
4151
Commands.register('aws.amazonq.optimizeCode', async data => {
42-
return focusAmazonQPanel().then(() => {
52+
return focusAmazonQPanel.execute(placeholder, 'amazonq.optimizeCode').then(() => {
4353
controllerPublishers.processContextMenuCommand.publish({
4454
type: 'aws.amazonq.optimizeCode',
4555
triggerType: getCommandTriggerType(data),
4656
})
4757
})
4858
})
4959
Commands.register('aws.amazonq.sendToPrompt', async data => {
50-
return focusAmazonQPanel().then(() => {
60+
return focusAmazonQPanel.execute(placeholder, 'amazonq.sendToPrompt').then(() => {
5161
controllerPublishers.processContextMenuCommand.publish({
5262
type: 'aws.amazonq.sendToPrompt',
5363
triggerType: getCommandTriggerType(data),

0 commit comments

Comments
 (0)