@@ -11,11 +11,8 @@ 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'
15- import {
16- DidChangeConfigurationNotification ,
17- updateConfigurationRequestType ,
18- } from '@aws/language-server-runtimes/protocol'
14+ import { AuthUtil , getSelectedCustomization , notifyNewCustomizations } from 'aws-core-vscode/codewhisperer'
15+ import { pushConfigUpdate } from '../config'
1916
2017export async function activate ( languageClient : LanguageClient , encryptionKey : Buffer , mynahUIPath : string ) {
2118 const disposables = globals . context . subscriptions
@@ -25,11 +22,8 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu
2522 type : 'profile' ,
2623 profileArn : AuthUtil . instance . regionProfileManager . activeRegionProfile ?. arn ,
2724 } )
28- // We need to push the cached customization on startup explicitly
29- await pushConfigUpdate ( languageClient , {
30- type : 'customization' ,
31- customization : getSelectedCustomization ( ) ,
32- } )
25+
26+ await initializeCustomizations ( )
3327
3428 const provider = new AmazonQChatViewProvider ( mynahUIPath )
3529
@@ -79,17 +73,10 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu
7973
8074 disposables . push (
8175 AuthUtil . instance . regionProfileManager . onDidChangeRegionProfile ( async ( ) => {
82- void pushConfigUpdate ( languageClient , {
83- type : 'profile' ,
84- profileArn : AuthUtil . instance . regionProfileManager . activeRegionProfile ?. arn ,
85- } )
8676 await provider . refreshWebview ( )
8777 } ) ,
8878 Commands . register ( 'aws.amazonq.updateCustomizations' , ( ) => {
89- void pushConfigUpdate ( languageClient , {
90- type : 'customization' ,
91- customization : undefinedIfEmpty ( getSelectedCustomization ( ) . arn ) ,
92- } )
79+ pushCustomizationToServer ( languageClient )
9380 } ) ,
9481 globals . logOutputChannel . onDidChangeLogLevel ( ( logLevel ) => {
9582 getLogger ( 'amazonqLsp' ) . info ( `Local log level changed to ${ logLevel } , notifying LSP` )
@@ -98,46 +85,35 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu
9885 } )
9986 } )
10087 )
101- }
10288
103- /**
104- * Push a config value to the language server, effectively updating it with the
105- * latest configuration from the client.
106- *
107- * The issue is we need to push certain configs to different places, since there are
108- * different handlers for specific configs. So this determines the correct place to
109- * push the given config.
110- */
111- async function pushConfigUpdate ( client : LanguageClient , config : QConfigs ) {
112- switch ( config . type ) {
113- case 'profile' :
114- await client . sendRequest ( updateConfigurationRequestType . method , {
115- section : 'aws.q' ,
116- settings : { profileArn : config . profileArn } ,
117- } )
118- break
119- case 'customization' :
120- client . sendNotification ( DidChangeConfigurationNotification . type . method , {
121- section : 'aws.q' ,
122- settings : { customization : config . customization } ,
123- } )
124- break
125- case 'logLevel' :
126- client . sendNotification ( DidChangeConfigurationNotification . type . method , {
127- section : 'aws.logLevel' ,
128- } )
129- break
89+ /**
90+ * Initialize customizations on extension startup
91+ */
92+ async function initializeCustomizations ( ) {
93+ /**
94+ * Even though this function is called "notify", it has a side effect that first restores the
95+ * cached customization. So for {@link getSelectedCustomization()} to work as expected, we must
96+ * call {@link notifyNewCustomizations} first.
97+ *
98+ * TODO: Separate restoring and notifying, or just rename the function to something better
99+ */
100+ if ( AuthUtil . instance . isIdcConnection ( ) && AuthUtil . instance . isConnected ( ) ) {
101+ await notifyNewCustomizations ( )
102+ }
103+
104+ /**
105+ * HACK: We must explicitly push the customization here since restoring the customization from cache
106+ * does not currently trigger a push to server.
107+ *
108+ * TODO: Always push to server whenever restoring from cache.
109+ */
110+ pushCustomizationToServer ( languageClient )
111+ }
112+
113+ function pushCustomizationToServer ( languageClient : LanguageClient ) {
114+ void pushConfigUpdate ( languageClient , {
115+ type : 'customization' ,
116+ customization : undefinedIfEmpty ( getSelectedCustomization ( ) . arn ) ,
117+ } )
130118 }
131119}
132- type ProfileConfig = {
133- type : 'profile'
134- profileArn : string | undefined
135- }
136- type CustomizationConfig = {
137- type : 'customization'
138- customization : string | undefined
139- }
140- type LogLevelConfig = {
141- type : 'logLevel'
142- }
143- type QConfigs = ProfileConfig | CustomizationConfig | LogLevelConfig
0 commit comments