Skip to content

Commit 0be655f

Browse files
committed
save
1 parent 03aba76 commit 0be655f

File tree

18 files changed

+405
-184
lines changed

18 files changed

+405
-184
lines changed

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/amazonq/src/app/chat/activation.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,14 @@
44
*/
55

66
import * as vscode from 'vscode'
7-
import { ExtensionContext, window } from 'vscode'
7+
import { ExtensionContext } from 'vscode'
88
import { telemetry } from 'aws-core-vscode/telemetry'
99
import { AuthUtil, CodeWhispererSettings } from 'aws-core-vscode/codewhisperer'
1010
import { Commands, placeholder, funcUtil } from 'aws-core-vscode/shared'
1111
import * as amazonq from 'aws-core-vscode/amazonq'
12-
import { scanChatAppInit } from '../amazonqScan'
1312

1413
export async function activate(context: ExtensionContext) {
1514
const appInitContext = amazonq.DefaultAmazonQAppInitContext.instance
16-
17-
registerApps(appInitContext, context)
18-
19-
const provider = new amazonq.AmazonQChatViewProvider(
20-
context,
21-
appInitContext.getWebViewToAppsMessagePublishers(),
22-
appInitContext.getAppsToWebViewMessageListener(),
23-
appInitContext.onDidChangeAmazonQVisibility
24-
)
25-
2615
await amazonq.TryChatCodeLensProvider.register(appInitContext.onDidChangeAmazonQVisibility.event)
2716

2817
const setupLsp = funcUtil.debounce(async () => {
@@ -34,11 +23,6 @@ export async function activate(context: ExtensionContext) {
3423
}, 5000)
3524

3625
context.subscriptions.push(
37-
window.registerWebviewViewProvider(amazonq.AmazonQChatViewProvider.viewType, provider, {
38-
webviewOptions: {
39-
retainContextWhenHidden: true,
40-
},
41-
}),
4226
amazonq.focusAmazonQChatWalkthrough.register(),
4327
amazonq.walkthroughInlineSuggestionsExample.register(),
4428
amazonq.walkthroughSecurityScanExample.register(),
@@ -64,15 +48,6 @@ export async function activate(context: ExtensionContext) {
6448
void setupAuthNotification()
6549
}
6650

67-
function registerApps(appInitContext: amazonq.AmazonQAppInitContext, context: ExtensionContext) {
68-
amazonq.cwChatAppInit(appInitContext)
69-
amazonq.featureDevChatAppInit(appInitContext)
70-
amazonq.gumbyChatAppInit(appInitContext)
71-
amazonq.testChatAppInit(appInitContext)
72-
scanChatAppInit(appInitContext)
73-
amazonq.docChatAppInit(appInitContext)
74-
}
75-
7651
/**
7752
* Display a notification to user for Log In.
7853
*
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import * as amazonqNode from 'aws-core-vscode/amazonq/node'
7+
import { scanChatAppInit } from '../../amazonqScan'
8+
import { DefaultAmazonQAppInitContext } from 'aws-core-vscode/amazonq'
9+
10+
export function registerAgents() {
11+
const appInitContext = DefaultAmazonQAppInitContext.instance
12+
13+
amazonqNode.cwChatAppInit(appInitContext)
14+
amazonqNode.featureDevChatAppInit(appInitContext)
15+
amazonqNode.gumbyChatAppInit(appInitContext)
16+
amazonqNode.testChatAppInit(appInitContext)
17+
amazonqNode.docChatAppInit(appInitContext)
18+
scanChatAppInit(appInitContext)
19+
}

packages/amazonq/src/extensionNode.ts

Lines changed: 17 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 './extension'
8-
import { DefaultAmazonQAppInitContext } from 'aws-core-vscode/amazonq'
8+
import { DefaultAmazonQAppInitContext, AmazonQChatViewProvider } from 'aws-core-vscode/amazonq'
99
import { activate as activateQGumby } from 'aws-core-vscode/amazonqGumby'
1010
import {
1111
ExtContext,
@@ -30,6 +30,7 @@ import { beta } from 'aws-core-vscode/dev'
3030
import { activate as activateNotifications, NotificationsController } from 'aws-core-vscode/notifications'
3131
import { AuthState, AuthUtil } from 'aws-core-vscode/codewhisperer'
3232
import { telemetry, AuthUserState } from 'aws-core-vscode/telemetry'
33+
import { registerAgents } from './app/chat/node/registerAgents'
3334

3435
export async function activate(context: vscode.ExtensionContext) {
3536
// IMPORTANT: No other code should be added to this function. Place it in one of the following 2 functions where appropriate.
@@ -53,9 +54,24 @@ async function activateAmazonQNode(context: vscode.ExtensionContext) {
5354
}
5455

5556
if (!Experiments.instance.get('amazonqChatLSP', false)) {
57+
const appInitContext = DefaultAmazonQAppInitContext.instance
58+
const provider = new AmazonQChatViewProvider(
59+
context,
60+
appInitContext.getWebViewToAppsMessagePublishers(),
61+
appInitContext.getAppsToWebViewMessageListener(),
62+
appInitContext.onDidChangeAmazonQVisibility
63+
)
64+
context.subscriptions.push(
65+
vscode.window.registerWebviewViewProvider(AmazonQChatViewProvider.viewType, provider, {
66+
webviewOptions: {
67+
retainContextWhenHidden: true,
68+
},
69+
})
70+
)
5671
await activateCWChat(context)
5772
await activateQGumby(extContext as ExtContext)
5873
}
74+
void registerAgents()
5975
activateInlineChat(context)
6076

6177
const authProvider = new CommonAuthViewProvider(

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import { LanguageClient } from 'vscode-languageclient'
88
import { AmazonQChatViewProvider } from './webviewProvider'
99
import { registerCommands } from './commands'
1010
import { registerLanguageServerEventListener, registerMessageListeners } from './messages'
11-
import { globals } from 'aws-core-vscode/shared'
11+
import { getLogger, globals } from 'aws-core-vscode/shared'
12+
import { activate as registerLegacyChatListeners } from '../../app/chat/activation'
13+
import { DefaultAmazonQAppInitContext } from 'aws-core-vscode/amazonq'
1214

13-
export function activate(languageClient: LanguageClient, encryptionKey: Buffer, mynahUIPath: string) {
15+
export async function activate(languageClient: LanguageClient, encryptionKey: Buffer, mynahUIPath: string) {
1416
const provider = new AmazonQChatViewProvider(mynahUIPath)
1517

1618
globals.context.subscriptions.push(
@@ -29,6 +31,17 @@ export function activate(languageClient: LanguageClient, encryptionKey: Buffer,
2931
registerLanguageServerEventListener(languageClient, provider)
3032

3133
provider.onDidResolveWebview(() => {
34+
if (provider.webview) {
35+
DefaultAmazonQAppInitContext.instance.getAppsToWebViewMessageListener().onMessage((msg) => {
36+
provider.webview?.postMessage(msg).then(undefined, (e) => {
37+
getLogger().error('webView.postMessage failed: %s', (e as Error).message)
38+
})
39+
})
40+
}
41+
3242
registerMessageListeners(languageClient, provider, encryptionKey)
3343
})
44+
45+
// register event listeners from the legacy agent flow
46+
await registerLegacyChatListeners(globals.context)
3447
}

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

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,30 @@
44
*/
55

66
import { Commands, globals } from 'aws-core-vscode/shared'
7-
import { window } from 'vscode'
7+
// import { window } from 'vscode'
88
import { AmazonQChatViewProvider } from './webviewProvider'
99

10+
/**
11+
* TODO: Re-enable these once we can figure out which path they're going to live in
12+
* In hybrid chat mode they were being registered twice causing a registration error
13+
*/
1014
export function registerCommands(provider: AmazonQChatViewProvider) {
1115
globals.context.subscriptions.push(
12-
registerGenericCommand('aws.amazonq.explainCode', 'Explain', provider),
13-
registerGenericCommand('aws.amazonq.refactorCode', 'Refactor', provider),
14-
registerGenericCommand('aws.amazonq.fixCode', 'Fix', provider),
15-
registerGenericCommand('aws.amazonq.optimizeCode', 'Optimize', provider),
16-
Commands.register('aws.amazonq.sendToPrompt', (data) => {
17-
const triggerType = getCommandTriggerType(data)
18-
const selection = getSelectedText()
16+
// registerGenericCommand('aws.amazonq.explainCode', 'Explain', provider),
17+
// registerGenericCommand('aws.amazonq.refactorCode', 'Refactor', provider),
18+
// registerGenericCommand('aws.amazonq.fixCode', 'Fix', provider),
19+
// registerGenericCommand('aws.amazonq.optimizeCode', 'Optimize', provider),
20+
// Commands.register('aws.amazonq.sendToPrompt', (data) => {
21+
// const triggerType = getCommandTriggerType(data)
22+
// const selection = getSelectedText()
1923

20-
void focusAmazonQPanel().then(() => {
21-
void provider.webview?.postMessage({
22-
command: 'sendToPrompt',
23-
params: { selection: selection, triggerType },
24-
})
25-
})
26-
}),
24+
// void focusAmazonQPanel().then(() => {
25+
// void provider.webview?.postMessage({
26+
// command: 'sendToPrompt',
27+
// params: { selection: selection, triggerType },
28+
// })
29+
// })
30+
// }),
2731
Commands.register('aws.amazonq.openTab', () => {
2832
void focusAmazonQPanel().then(() => {
2933
void provider.webview?.postMessage({
@@ -35,36 +39,36 @@ export function registerCommands(provider: AmazonQChatViewProvider) {
3539
)
3640
}
3741

38-
function getSelectedText(): string {
39-
const editor = window.activeTextEditor
40-
if (editor) {
41-
const selection = editor.selection
42-
const selectedText = editor.document.getText(selection)
43-
return selectedText
44-
}
42+
// function getSelectedText(): string {
43+
// const editor = window.activeTextEditor
44+
// if (editor) {
45+
// const selection = editor.selection
46+
// const selectedText = editor.document.getText(selection)
47+
// return selectedText
48+
// }
4549

46-
return ' '
47-
}
50+
// return ' '
51+
// }
4852

49-
function getCommandTriggerType(data: any): string {
50-
// data is undefined when commands triggered from keybinding or command palette. Currently no
51-
// way to differentiate keybinding and command palette, so both interactions are recorded as keybinding
52-
return data === undefined ? 'hotkeys' : 'contextMenu'
53-
}
53+
// function getCommandTriggerType(data: any): string {
54+
// // data is undefined when commands triggered from keybinding or command palette. Currently no
55+
// // way to differentiate keybinding and command palette, so both interactions are recorded as keybinding
56+
// return data === undefined ? 'hotkeys' : 'contextMenu'
57+
// }
5458

55-
function registerGenericCommand(commandName: string, genericCommand: string, provider: AmazonQChatViewProvider) {
56-
return Commands.register(commandName, (data) => {
57-
const triggerType = getCommandTriggerType(data)
58-
const selection = getSelectedText()
59+
// function registerGenericCommand(commandName: string, genericCommand: string, provider: AmazonQChatViewProvider) {
60+
// return Commands.register(commandName, (data) => {
61+
// const triggerType = getCommandTriggerType(data)
62+
// const selection = getSelectedText()
5963

60-
void focusAmazonQPanel().then(() => {
61-
void provider.webview?.postMessage({
62-
command: 'genericCommand',
63-
params: { genericCommand, selection, triggerType },
64-
})
65-
})
66-
})
67-
}
64+
// void focusAmazonQPanel().then(() => {
65+
// void provider.webview?.postMessage({
66+
// command: 'genericCommand',
67+
// params: { genericCommand, selection, triggerType },
68+
// })
69+
// })
70+
// })
71+
// }
6872

6973
/**
7074
* Importing focusAmazonQPanel from aws-core-vscode/amazonq leads to several dependencies down the chain not resolving since AmazonQ chat

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import * as jose from 'jose'
2929
import { AmazonQChatViewProvider } from './webviewProvider'
3030
import { AuthUtil } from 'aws-core-vscode/codewhisperer'
3131
import { AmazonQPromptSettings, messages } from 'aws-core-vscode/shared'
32+
import { DefaultAmazonQAppInitContext, messageDispatcher } from 'aws-core-vscode/amazonq'
3233

3334
export function registerLanguageServerEventListener(languageClient: LanguageClient, provider: AmazonQChatViewProvider) {
3435
languageClient.onDidChangeState(({ oldState, newState }) => {
@@ -60,6 +61,15 @@ export function registerMessageListeners(
6061
provider.webview?.onDidReceiveMessage(async (message) => {
6162
languageClient.info(`[VSCode Client] Received ${JSON.stringify(message)} from chat`)
6263

64+
if ((message.tabType && message.tabType !== 'cwc') || messageDispatcher.isLegacyEvent(message.command)) {
65+
// handle the mynah ui -> agent legacy flow
66+
messageDispatcher.handleWebviewEvent(
67+
message,
68+
DefaultAmazonQAppInitContext.instance.getWebViewToAppsMessagePublishers()
69+
)
70+
return
71+
}
72+
6373
switch (message.command) {
6474
case COPY_TO_CLIPBOARD:
6575
languageClient.info('[VSCode Client] Copy to clipboard event received')

packages/amazonq/src/lsp/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export async function startLanguageServer(
118118
}
119119

120120
if (Experiments.instance.get('amazonqChatLSP', false)) {
121-
activate(client, encryptionKey, resourcePaths.ui)
121+
await activate(client, encryptionKey, resourcePaths.ui)
122122
}
123123

124124
const refreshInterval = auth.startTokenRefreshInterval()

packages/core/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"./web": "./dist/src/extensionWeb.js",
1414
"./webShared": "./dist/src/extensionWebShared.js",
1515
"./amazonq": "./dist/src/amazonq/index.js",
16+
"./amazonq/node": "./dist/src/amazonq/indexNode.js",
1617
"./codewhisperer": "./dist/src/codewhisperer/index.js",
1718
"./codewhisperer/node": "./dist/src/codewhisperer/indexNode.js",
1819
"./shared": "./dist/src/shared/index.js",
@@ -440,6 +441,7 @@
440441
},
441442
"devDependencies": {
442443
"@aws-sdk/types": "^3.13.1",
444+
"@aws/chat-client": "^0.1.4",
443445
"@aws/chat-client-ui-types": "^0.1.12",
444446
"@aws/language-server-runtimes": "^0.2.49",
445447
"@aws/language-server-runtimes-types": "^0.1.10",

packages/core/src/amazonq/index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ export { LspController } from './lsp/lspController'
1919
export { LspClient } from './lsp/lspClient'
2020
export { api } from './extApi'
2121
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 { init as testChatAppInit } from '../amazonqTest/app'
26-
export { init as docChatAppInit } from '../amazonqDoc/app'
2722
export { amazonQHelpUrl } from '../shared/constants'
2823
export * as webviewConstants from './webview/ui/texts/constants'
2924
export * as webviewTabConstants from './webview/ui/tabs/constants'
@@ -48,6 +43,8 @@ export * from './lsp/config'
4843
export * as WorkspaceLspInstaller from './lsp/workspaceInstaller'
4944
export * as secondaryAuth from '../auth/secondaryAuth'
5045
export * as authConnection from '../auth/connection'
46+
export * as featureConfig from './webview/generators/featureConfig'
47+
export * as messageDispatcher from './webview/messages/messageDispatcher'
5148
import { FeatureContext } from '../shared/featureConfig'
5249

5350
/**

0 commit comments

Comments
 (0)