@@ -11,7 +11,7 @@ import { registerLanguageServerEventListener, registerMessageListeners } from '.
11
11
import { Commands , getLogger , globals , undefinedIfEmpty } from 'aws-core-vscode/shared'
12
12
import { activate as registerLegacyChatListeners } from '../../app/chat/activation'
13
13
import { 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'
15
15
import {
16
16
DidChangeConfigurationNotification ,
17
17
updateConfigurationRequestType ,
@@ -25,11 +25,8 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu
25
25
type : 'profile' ,
26
26
profileArn : AuthUtil . instance . regionProfileManager . activeRegionProfile ?. arn ,
27
27
} )
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 ( )
33
30
34
31
const provider = new AmazonQChatViewProvider ( mynahUIPath )
35
32
@@ -86,10 +83,7 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu
86
83
await provider . refreshWebview ( )
87
84
} ) ,
88
85
Commands . register ( 'aws.amazonq.updateCustomizations' , ( ) => {
89
- void pushConfigUpdate ( languageClient , {
90
- type : 'customization' ,
91
- customization : undefinedIfEmpty ( getSelectedCustomization ( ) . arn ) ,
92
- } )
86
+ pushCustomizationToServer ( languageClient )
93
87
} ) ,
94
88
globals . logOutputChannel . onDidChangeLogLevel ( ( logLevel ) => {
95
89
getLogger ( 'amazonqLsp' ) . info ( `Local log level changed to ${ logLevel } , notifying LSP` )
@@ -98,15 +92,48 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu
98
92
} )
99
93
} )
100
94
)
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
+ }
101
126
}
102
127
103
128
/**
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
105
130
* latest configuration from the client.
106
131
*
107
132
* The issue is we need to push certain configs to different places, since there are
108
133
* different handlers for specific configs. So this determines the correct place to
109
134
* push the given config.
135
+ *
136
+ * TODO: Move this to somewhere more appropriate
110
137
*/
111
138
async function pushConfigUpdate ( client : LanguageClient , config : QConfigs ) {
112
139
switch ( config . type ) {
0 commit comments