@@ -11,7 +11,7 @@ import { registerLanguageServerEventListener, registerMessageListeners } from '.
1111import { Commands , getLogger , globals , undefinedIfEmpty } from 'aws-core-vscode/shared'
1212import { activate as registerLegacyChatListeners } from '../../app/chat/activation'
1313import { DefaultAmazonQAppInitContext } from 'aws-core-vscode/amazonq'
14- import { AuthUtil , getSelectedCustomization } from 'aws-core-vscode/codewhisperer'
14+ import { AuthUtil , getSelectedCustomization , notifyNewCustomizations } from 'aws-core-vscode/codewhisperer'
1515import {
1616 DidChangeConfigurationNotification ,
1717 updateConfigurationRequestType ,
@@ -25,11 +25,8 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu
2525 type : 'profile' ,
2626 profileArn : AuthUtil . instance . regionProfileManager . activeRegionProfile ?. arn ,
2727 } )
28- // We need to push the cached customization on startup explicitly
29- await pushConfigUpdate ( languageClient , {
30- type : 'customization' ,
31- customization : getSelectedCustomization ( ) ,
32- } )
28+
29+ await initializeCustomizations ( )
3330
3431 const provider = new AmazonQChatViewProvider ( mynahUIPath )
3532
@@ -86,10 +83,7 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu
8683 await provider . refreshWebview ( )
8784 } ) ,
8885 Commands . register ( 'aws.amazonq.updateCustomizations' , ( ) => {
89- void pushConfigUpdate ( languageClient , {
90- type : 'customization' ,
91- customization : undefinedIfEmpty ( getSelectedCustomization ( ) . arn ) ,
92- } )
86+ pushCustomizationToServer ( languageClient )
9387 } ) ,
9488 globals . logOutputChannel . onDidChangeLogLevel ( ( logLevel ) => {
9589 getLogger ( 'amazonqLsp' ) . info ( `Local log level changed to ${ logLevel } , notifying LSP` )
@@ -98,15 +92,48 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu
9892 } )
9993 } )
10094 )
95+
96+ /**
97+ * Initialize customizations on extension startup
98+ */
99+ async function initializeCustomizations ( ) {
100+ /**
101+ * Even though this function is called "notify", it has a side effect that first restores the
102+ * cached customization. So for {@link getSelectedCustomization()} to work as expected, we must
103+ * call {@link notifyNewCustomizations} first.
104+ *
105+ * TODO: Separate restoring and notifying, or just rename the function to something better
106+ */
107+ if ( AuthUtil . instance . isIdcConnection ( ) && AuthUtil . instance . isConnected ( ) ) {
108+ await notifyNewCustomizations ( )
109+ }
110+
111+ /**
112+ * HACK: We must explicitly push the customization here since restoring the customization from cache
113+ * does not currently trigger a push to server.
114+ *
115+ * TODO: Always push to server whenever restoring from cache.
116+ */
117+ pushCustomizationToServer ( languageClient )
118+ }
119+
120+ function pushCustomizationToServer ( languageClient : LanguageClient ) {
121+ void pushConfigUpdate ( languageClient , {
122+ type : 'customization' ,
123+ customization : undefinedIfEmpty ( getSelectedCustomization ( ) . arn ) ,
124+ } )
125+ }
101126}
102127
103128/**
104- * Push a config value to the language server, effectively updating it with the
129+ * Request/Notify a config value to the language server, effectively updating it with the
105130 * latest configuration from the client.
106131 *
107132 * The issue is we need to push certain configs to different places, since there are
108133 * different handlers for specific configs. So this determines the correct place to
109134 * push the given config.
135+ *
136+ * TODO: Move this to somewhere more appropriate
110137 */
111138async function pushConfigUpdate ( client : LanguageClient , config : QConfigs ) {
112139 switch ( config . type ) {
0 commit comments