@@ -15,12 +15,14 @@ import { AuthUtil } from 'aws-core-vscode/codewhisperer'
1515import { updateConfigurationRequestType } from '@aws/language-server-runtimes/protocol'
1616
1717export async function activate ( languageClient : LanguageClient , encryptionKey : Buffer , mynahUIPath : string ) {
18+ const disposables = globals . context . subscriptions
19+
1820 // Make sure we've sent an auth profile to the language server before even initializing the UI
1921 await updateProfile ( languageClient )
2022
2123 const provider = new AmazonQChatViewProvider ( mynahUIPath )
2224
23- globals . context . subscriptions . push (
25+ disposables . push (
2426 window . registerWebviewViewProvider ( AmazonQChatViewProvider . viewType , provider , {
2527 webviewOptions : {
2628 retainContextWhenHidden : true ,
@@ -36,12 +38,18 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu
3638 registerLanguageServerEventListener ( languageClient , provider )
3739
3840 provider . onDidResolveWebview ( ( ) => {
39- if ( provider . webview ) {
40- DefaultAmazonQAppInitContext . instance . getAppsToWebViewMessageListener ( ) . onMessage ( ( msg ) => {
41- provider . webview ?. postMessage ( msg ) . then ( undefined , ( e ) => {
42- getLogger ( ) . error ( 'webView.postMessage failed: %s' , ( e as Error ) . message )
43- } )
41+ const disposable = DefaultAmazonQAppInitContext . instance . getAppsToWebViewMessageListener ( ) . onMessage ( ( msg ) => {
42+ provider . webview ?. postMessage ( msg ) . then ( undefined , ( e ) => {
43+ getLogger ( ) . error ( 'webView.postMessage failed: %s' , ( e as Error ) . message )
4444 } )
45+ } )
46+
47+ if ( provider . webviewView ) {
48+ disposables . push (
49+ provider . webviewView . onDidDispose ( ( ) => {
50+ disposable . dispose ( )
51+ } )
52+ )
4553 }
4654
4755 registerMessageListeners ( languageClient , provider , encryptionKey )
@@ -50,7 +58,7 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu
5058 // register event listeners from the legacy agent flow
5159 await registerLegacyChatListeners ( globals . context )
5260
53- globals . context . subscriptions . push (
61+ disposables . push (
5462 AuthUtil . instance . regionProfileManager . onDidChangeRegionProfile ( async ( ) => {
5563 void updateProfile ( languageClient )
5664 await provider . refreshWebview ( )
0 commit comments