Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions packages/amazonq/src/lsp/chat/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import { AuthUtil } from 'aws-core-vscode/codewhisperer'
import { updateConfigurationRequestType } from '@aws/language-server-runtimes/protocol'

export async function activate(languageClient: LanguageClient, encryptionKey: Buffer, mynahUIPath: string) {
const disposables = globals.context.subscriptions

// Make sure we've sent an auth profile to the language server before even initializing the UI
await updateProfile(languageClient)

const provider = new AmazonQChatViewProvider(mynahUIPath)

globals.context.subscriptions.push(
disposables.push(
window.registerWebviewViewProvider(AmazonQChatViewProvider.viewType, provider, {
webviewOptions: {
retainContextWhenHidden: true,
Expand All @@ -36,12 +38,18 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu
registerLanguageServerEventListener(languageClient, provider)

provider.onDidResolveWebview(() => {
if (provider.webview) {
DefaultAmazonQAppInitContext.instance.getAppsToWebViewMessageListener().onMessage((msg) => {
provider.webview?.postMessage(msg).then(undefined, (e) => {
getLogger().error('webView.postMessage failed: %s', (e as Error).message)
})
const disposable = DefaultAmazonQAppInitContext.instance.getAppsToWebViewMessageListener().onMessage((msg) => {
provider.webview?.postMessage(msg).then(undefined, (e) => {
getLogger().error('webView.postMessage failed: %s', (e as Error).message)
})
})

if (provider.webviewView) {
disposables.push(
provider.webviewView.onDidDispose(() => {
disposable.dispose()
})
)
}

registerMessageListeners(languageClient, provider, encryptionKey)
Expand All @@ -50,7 +58,7 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu
// register event listeners from the legacy agent flow
await registerLegacyChatListeners(globals.context)

globals.context.subscriptions.push(
disposables.push(
AuthUtil.instance.regionProfileManager.onDidChangeRegionProfile(async () => {
void updateProfile(languageClient)
await provider.refreshWebview()
Expand Down
16 changes: 12 additions & 4 deletions packages/amazonq/src/lsp/chat/webviewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import {
EventEmitter,
CancellationToken,
Webview,
WebviewView,
WebviewViewProvider,
WebviewViewResolveContext,
Uri,
Webview,
} from 'vscode'
import * as path from 'path'
import {
Expand All @@ -28,7 +28,8 @@ export class AmazonQChatViewProvider implements WebviewViewProvider {
private readonly onDidResolveWebviewEmitter = new EventEmitter<void>()
public readonly onDidResolveWebview = this.onDidResolveWebviewEmitter.event

webview: Webview | undefined
webviewView?: WebviewView
webview?: Webview

connectorAdapterPath?: string
uiPath?: string
Expand All @@ -40,8 +41,6 @@ export class AmazonQChatViewProvider implements WebviewViewProvider {
context: WebviewViewResolveContext,
_token: CancellationToken
) {
this.webview = webviewView.webview

const lspDir = Uri.parse(LanguageServerResolver.defaultDir())
const dist = Uri.joinPath(globals.context.extensionUri, 'dist')
webviewView.webview.options = {
Expand All @@ -63,7 +62,16 @@ export class AmazonQChatViewProvider implements WebviewViewProvider {

webviewView.webview.html = await this.getWebviewContent()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: to make it easier to read/navigate the webviews in this file, consider only using the webview properties you define in line 65-66


this.webviewView = webviewView
this.webview = this.webviewView.webview
Comment on lines +65 to +66
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a lot of views 👀


this.onDidResolveWebviewEmitter.fire()
globals.context.subscriptions.push(
this.webviewView.onDidDispose(() => {
this.webviewView = undefined
this.webview = undefined
})
)
performance.mark(amazonqMark.open)
}

Expand Down
Loading