@@ -11,11 +11,8 @@ 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'
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'
19
16
20
17
export async function activate ( languageClient : LanguageClient , encryptionKey : Buffer , mynahUIPath : string ) {
21
18
const disposables = globals . context . subscriptions
@@ -25,11 +22,8 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu
25
22
type : 'profile' ,
26
23
profileArn : AuthUtil . instance . regionProfileManager . activeRegionProfile ?. arn ,
27
24
} )
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 ( )
33
27
34
28
const provider = new AmazonQChatViewProvider ( mynahUIPath )
35
29
@@ -79,17 +73,10 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu
79
73
80
74
disposables . push (
81
75
AuthUtil . instance . regionProfileManager . onDidChangeRegionProfile ( async ( ) => {
82
- void pushConfigUpdate ( languageClient , {
83
- type : 'profile' ,
84
- profileArn : AuthUtil . instance . regionProfileManager . activeRegionProfile ?. arn ,
85
- } )
86
76
await provider . refreshWebview ( )
87
77
} ) ,
88
78
Commands . register ( 'aws.amazonq.updateCustomizations' , ( ) => {
89
- void pushConfigUpdate ( languageClient , {
90
- type : 'customization' ,
91
- customization : undefinedIfEmpty ( getSelectedCustomization ( ) . arn ) ,
92
- } )
79
+ pushCustomizationToServer ( languageClient )
93
80
} ) ,
94
81
globals . logOutputChannel . onDidChangeLogLevel ( ( logLevel ) => {
95
82
getLogger ( 'amazonqLsp' ) . info ( `Local log level changed to ${ logLevel } , notifying LSP` )
@@ -98,46 +85,35 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu
98
85
} )
99
86
} )
100
87
)
101
- }
102
88
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
+ } )
130
118
}
131
119
}
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