Skip to content

Commit 66f55b1

Browse files
authored
refactor(amazonq): move chat activation into packages/amazonq/ aws#5333
Problem: Q activation lives in `packages/core/`, so it can't call code defined in `packages/amazonq/`. This prevents new, Q-only, application code from being defined in `packages/amazonq/` where it should be. Solution: - Move Q activation into `packages/amazonq/`. - Create an `app/ directory where application logic can live.
1 parent 6dbff72 commit 66f55b1

File tree

6 files changed

+128
-129
lines changed

6 files changed

+128
-129
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import * as vscode from 'vscode'
7+
import { ExtensionContext, window } from 'vscode'
8+
import { Auth } from 'aws-core-vscode/auth'
9+
import { telemetry } from 'aws-core-vscode/telemetry'
10+
import { CodeWhispererSettings } from 'aws-core-vscode/codewhisperer'
11+
import { Commands, placeholder, funcUtil } from 'aws-core-vscode/shared'
12+
import * as amazonq from 'aws-core-vscode/amazonq'
13+
14+
export async function activate(context: ExtensionContext) {
15+
const appInitContext = amazonq.DefaultAmazonQAppInitContext.instance
16+
17+
registerApps(appInitContext)
18+
19+
const provider = new amazonq.AmazonQChatViewProvider(
20+
context,
21+
appInitContext.getWebViewToAppsMessagePublishers(),
22+
appInitContext.getAppsToWebViewMessageListener(),
23+
appInitContext.onDidChangeAmazonQVisibility
24+
)
25+
26+
await amazonq.TryChatCodeLensProvider.register(appInitContext.onDidChangeAmazonQVisibility.event)
27+
28+
const setupLsp = funcUtil.debounce(async () => {
29+
void amazonq.LspController.instance.trySetupLsp(context)
30+
}, 5000)
31+
32+
context.subscriptions.push(
33+
window.registerWebviewViewProvider(amazonq.AmazonQChatViewProvider.viewType, provider, {
34+
webviewOptions: {
35+
retainContextWhenHidden: true,
36+
},
37+
}),
38+
amazonq.focusAmazonQChatWalkthrough.register(),
39+
amazonq.walkthroughInlineSuggestionsExample.register(),
40+
amazonq.walkthroughSecurityScanExample.register(),
41+
amazonq.openAmazonQWalkthrough.register(),
42+
amazonq.listCodeWhispererCommandsWalkthrough.register(),
43+
amazonq.focusAmazonQPanel.register(),
44+
amazonq.focusAmazonQPanelKeybinding.register(),
45+
amazonq.tryChatCodeLensCommand.register(),
46+
vscode.workspace.onDidChangeConfiguration(async (configurationChangeEvent) => {
47+
if (configurationChangeEvent.affectsConfiguration('amazonQ.workspaceIndex')) {
48+
if (CodeWhispererSettings.instance.isLocalIndexEnabled()) {
49+
void setupLsp()
50+
}
51+
}
52+
})
53+
)
54+
55+
Commands.register('aws.amazonq.learnMore', () => {
56+
void vscode.env.openExternal(vscode.Uri.parse(amazonq.amazonQHelpUrl))
57+
})
58+
59+
await amazonq.activateBadge()
60+
void setupLsp()
61+
void setupAuthNotification()
62+
}
63+
64+
function registerApps(appInitContext: amazonq.AmazonQAppInitContext) {
65+
amazonq.cwChatAppInit(appInitContext)
66+
amazonq.featureDevChatAppInit(appInitContext)
67+
amazonq.gumbyChatAppInit(appInitContext)
68+
}
69+
70+
/**
71+
* Display a notification to user for Log In.
72+
*
73+
* Authentication Notification is displayed when:
74+
* - User is not authenticated
75+
* - Once every session
76+
*
77+
*/
78+
async function setupAuthNotification() {
79+
let notificationDisplayed = false // Auth Notification should be displayed only once.
80+
await tryShowNotification()
81+
82+
async function tryShowNotification() {
83+
// Do not show the notification if the IDE starts and user is already authenticated.
84+
if (Auth.instance.activeConnection) {
85+
notificationDisplayed = true
86+
}
87+
88+
if (notificationDisplayed) {
89+
return
90+
}
91+
92+
const source = 'authNotification'
93+
const buttonAction = 'Sign In'
94+
notificationDisplayed = true
95+
96+
telemetry.toolkit_showNotification.emit({
97+
component: 'editor',
98+
id: source,
99+
reason: 'notLoggedIn',
100+
result: 'Succeeded',
101+
})
102+
const selection = await vscode.window.showWarningMessage('Start using Amazon Q', buttonAction)
103+
104+
if (selection === buttonAction) {
105+
void amazonq.focusAmazonQPanel.execute(placeholder, source)
106+
}
107+
}
108+
}

packages/amazonq/src/extension.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as vscode from 'vscode'
77
import { activateAmazonQCommon, amazonQContextPrefix, deactivateCommon } from './extensionCommon'
8-
import { DefaultAmazonQAppInitContext, activate as activateCWChat } from 'aws-core-vscode/amazonq'
8+
import { DefaultAmazonQAppInitContext } from 'aws-core-vscode/amazonq'
99
import { activate as activateQGumby } from 'aws-core-vscode/amazonqGumby'
1010
import { ExtContext } from 'aws-core-vscode/shared'
1111
import { updateDevMode } from 'aws-core-vscode/dev'
@@ -15,6 +15,7 @@ import { registerSubmitFeedback } from 'aws-core-vscode/feedback'
1515
import { DevOptions } from 'aws-core-vscode/dev'
1616
import { Auth } from 'aws-core-vscode/auth'
1717
import api from './api'
18+
import { activate as activateCWChat } from './app/chat/activation'
1819

1920
export async function activate(context: vscode.ExtensionContext) {
2021
// IMPORTANT: No other code should be added to this function. Place it in one of the following 2 functions where appropriate.

packages/core/src/amazonq/activation.ts

Lines changed: 0 additions & 125 deletions
This file was deleted.

packages/core/src/amazonq/index.ts

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

6-
export { activate } from './activation'
7-
export { DefaultAmazonQAppInitContext } from './apps/initContext'
6+
export { AmazonQAppInitContext, DefaultAmazonQAppInitContext } from './apps/initContext'
87
export { TabType } from './webview/ui/storages/tabsStorage'
98
export { MessagePublisher } from './messages/messagePublisher'
109
export { MessageListener } from './messages/messageListener'
1110
export { AuthController } from './auth/controller'
1211
export { showAmazonQWalkthroughOnce } from './onboardingPage/walkthrough'
13-
export { openAmazonQWalkthrough } from './onboardingPage/walkthrough'
12+
export {
13+
focusAmazonQChatWalkthrough,
14+
openAmazonQWalkthrough,
15+
walkthroughInlineSuggestionsExample,
16+
walkthroughSecurityScanExample,
17+
} from './onboardingPage/walkthrough'
1418
export { LspController, Content } from './lsp/lspController'
1519
export { LspClient } from './lsp/lspClient'
1620
export { api } from './extApi'
21+
export { AmazonQChatViewProvider } from './webview/webView'
22+
export { init as cwChatAppInit } from '../codewhispererChat/app'
23+
export { init as featureDevChatAppInit } from '../amazonqFeatureDev/app'
24+
export { init as gumbyChatAppInit } from '../amazonqGumby/app'
25+
export { activateBadge } from './util/viewBadgeHandler'
26+
export { amazonQHelpUrl } from '../shared/constants'
27+
export { listCodeWhispererCommandsWalkthrough } from '../codewhisperer/ui/statusBarMenu'
28+
export { focusAmazonQPanel, focusAmazonQPanelKeybinding } from '../codewhispererChat/commands/registerCommands'
29+
export { TryChatCodeLensProvider, tryChatCodeLensCommand } from '../codewhispererChat/editor/codelens'
1730

1831
/**
1932
* main from createMynahUI is a purely browser dependency. Due to this

packages/core/src/codewhisperer/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export * from './util/zipUtil'
9292
export * from './util/commonUtil'
9393
export * from './util/supplementalContext/codeParsingUtil'
9494
export * from './util/supplementalContext/supplementalContextUtil'
95+
export * from './util/codewhispererSettings'
9596
export * as supplementalContextUtil from './util/supplementalContext/supplementalContextUtil'
9697
export * from './service/diagnosticsProvider'
9798
export * as diagnosticsProvider from './service/diagnosticsProvider'

packages/core/src/shared/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ export * from './utilities/pathUtils'
4343
export * from './errors'
4444
export * as messages from './utilities/messages'
4545
export * as errors from './errors'
46+
export * as funcUtil from './utilities/functionUtils'
4647
export { fs } from './fs/fs'

0 commit comments

Comments
 (0)