@@ -34,6 +34,7 @@ import {
34
34
showFreeTierLimit ,
35
35
updateReferenceLog ,
36
36
showIntroduction ,
37
+ showAccessTokenErrorLearnMore ,
37
38
} from './commands/basicCommands'
38
39
import { sleep } from '../shared/utilities/timeoutUtils'
39
40
import { ReferenceLogViewProvider } from './service/referenceLogViewProvider'
@@ -47,10 +48,10 @@ import { InlineCompletionService, refreshStatusBar } from './service/inlineCompl
47
48
import { isInlineCompletionEnabled } from './util/commonUtil'
48
49
import { CodeWhispererCodeCoverageTracker } from './tracker/codewhispererCodeCoverageTracker'
49
50
import { AuthUtil , isUpgradeableConnection } from './util/authUtil'
50
- import globals from '../shared/extensionGlobals'
51
51
import { Auth } from '../credentials/auth'
52
52
import { isUserCancelledError } from '../shared/errors'
53
53
import { showViewLogsMessage } from '../shared/utilities/messages'
54
+ import globals from '../shared/extensionGlobals'
54
55
55
56
const performance = globalThis . performance ?? require ( 'perf_hooks' ) . performance
56
57
@@ -61,6 +62,7 @@ export async function activate(context: ExtContext): Promise<void> {
61
62
/**
62
63
* Enable essential intellisense default settings for AWS C9 IDE
63
64
*/
65
+
64
66
if ( isCloud9 ( ) ) {
65
67
await enableDefaultConfigCloud9 ( )
66
68
}
@@ -167,6 +169,8 @@ export async function activate(context: ExtContext): Promise<void> {
167
169
showSsoSignIn . register ( ) ,
168
170
// learn more about CodeWhisperer
169
171
showLearnMore . register ( ) ,
172
+ // learn more about CodeWhisperer access token migration
173
+ showAccessTokenErrorLearnMore . register ( ) ,
170
174
// show free tier limit
171
175
showFreeTierLimit . register ( ) ,
172
176
// update reference log instance
@@ -220,6 +224,9 @@ export async function activate(context: ExtContext): Promise<void> {
220
224
221
225
async function showAccessTokenMigrationDialogue ( ) {
222
226
// TODO: Change the color of the buttons
227
+ const accessTokenExpired =
228
+ context . extensionContext . globalState . get < boolean > ( CodeWhispererConstants . accessTokenExpriedKey ) || false
229
+
223
230
if ( AuthUtil . instance . hasAccessToken ( ) ) {
224
231
await Auth . instance . tryAutoConnect ( )
225
232
const conn = Auth . instance . activeConnection
@@ -240,65 +247,101 @@ export async function activate(context: ExtContext): Promise<void> {
240
247
241
248
await vscode . commands . executeCommand ( 'aws.codeWhisperer.refreshRootNode' )
242
249
const t = new Date ( )
243
- const doNotShowAgain =
244
- context . extensionContext . globalState . get < boolean > (
245
- CodeWhispererConstants . accessTokenMigrationDoNotShowAgainKey
246
- ) || false
247
- const notificationLastShown : number =
248
- context . extensionContext . globalState . get < number | undefined > (
249
- CodeWhispererConstants . accessTokenMigrationDoNotShowLastShown
250
- ) || 1
251
-
252
- //Add 7 days to notificationLastShown to determine whether warn message should show
253
- if ( doNotShowAgain || notificationLastShown + 1000 * 60 * 60 * 24 * 7 >= Date . now ( ) ) {
254
- return
255
- } else if ( t <= CodeWhispererConstants . accessTokenCutOffDate ) {
256
- vscode . window
257
- . showWarningMessage (
258
- CodeWhispererConstants . accessTokenMigrationWarningMessage ,
259
- CodeWhispererConstants . accessTokenMigrationWarningButtonMessage ,
260
- CodeWhispererConstants . accessTokenMigrationDoNotShowAgain
261
- )
262
- . then ( async resp => {
263
- if ( resp === CodeWhispererConstants . accessTokenMigrationWarningButtonMessage ) {
264
- await vscode . commands . executeCommand ( 'aws.codeWhisperer.refresh' )
265
- await showSsoSignIn . execute ( )
266
- } else if ( resp === CodeWhispererConstants . accessTokenMigrationDoNotShowAgain ) {
267
- await vscode . window . showInformationMessage (
268
- CodeWhispererConstants . accessTokenMigrationDoNotShowAgainInfo ,
269
- 'OK'
270
- )
271
- await context . extensionContext . globalState . update (
272
- CodeWhispererConstants . accessTokenMigrationDoNotShowAgainKey ,
273
- true
274
- )
275
- }
276
- } )
277
- context . extensionContext . globalState . update (
278
- CodeWhispererConstants . accessTokenMigrationDoNotShowLastShown ,
279
- Date . now ( )
280
- )
250
+
251
+ if ( t <= CodeWhispererConstants . accessTokenCutOffDate ) {
252
+ maybeShowTokenMigrationWarning ( )
281
253
} else {
282
254
await globals . context . globalState . update ( CodeWhispererConstants . accessToken , undefined )
255
+ await globals . context . globalState . update ( CodeWhispererConstants . accessTokenExpriedKey , true )
283
256
await vscode . commands . executeCommand ( 'aws.codeWhisperer.refreshRootNode' )
284
- vscode . window
285
- . showErrorMessage (
286
- CodeWhispererConstants . accessTokenMigrationErrorMessage ,
287
- CodeWhispererConstants . accessTokenMigrationErrorButtonMessage
288
- )
289
- . then ( async resp => {
290
- if ( resp === CodeWhispererConstants . accessTokenMigrationErrorButtonMessage ) {
291
- await vscode . commands . executeCommand ( 'aws.codeWhisperer.refresh' )
292
- await showSsoSignIn . execute ( )
293
- } else if ( resp === CodeWhispererConstants . accessTokenMigrationDoNotShowAgain ) {
294
- await context . extensionContext . globalState . update (
295
- CodeWhispererConstants . accessTokenMigrationDoNotShowAgainKey ,
296
- true
297
- )
298
- }
299
- } )
257
+ maybeShowTokenMigrationError ( )
300
258
}
259
+ } else if ( accessTokenExpired ) {
260
+ maybeShowTokenMigrationError ( )
261
+ }
262
+ }
263
+
264
+ function maybeShowTokenMigrationWarning ( ) {
265
+ const doNotShowAgain =
266
+ context . extensionContext . globalState . get < boolean > (
267
+ CodeWhispererConstants . accessTokenMigrationDoNotShowAgainKey
268
+ ) || false
269
+ const notificationLastShown : number =
270
+ context . extensionContext . globalState . get < number | undefined > (
271
+ CodeWhispererConstants . accessTokenMigrationDoNotShowLastShown
272
+ ) || 1
273
+
274
+ //Add 7 days to notificationLastShown to determine whether warn message should show
275
+ if ( doNotShowAgain || notificationLastShown + 1000 * 60 * 60 * 24 * 7 >= Date . now ( ) ) {
276
+ return
277
+ }
278
+
279
+ vscode . window
280
+ . showWarningMessage (
281
+ CodeWhispererConstants . accessTokenMigrationWarningMessage ,
282
+ CodeWhispererConstants . accessTokenMigrationWarningButtonMessage ,
283
+ CodeWhispererConstants . accessTokenMigrationDoNotShowAgain
284
+ )
285
+ . then ( async resp => {
286
+ if ( resp === CodeWhispererConstants . accessTokenMigrationWarningButtonMessage ) {
287
+ await vscode . commands . executeCommand ( 'aws.codeWhisperer.refresh' )
288
+ await showSsoSignIn . execute ( )
289
+ } else if ( resp === CodeWhispererConstants . accessTokenMigrationDoNotShowAgain ) {
290
+ await vscode . window . showInformationMessage (
291
+ CodeWhispererConstants . accessTokenMigrationDoNotShowAgainInfo ,
292
+ 'OK'
293
+ )
294
+ await context . extensionContext . globalState . update (
295
+ CodeWhispererConstants . accessTokenMigrationDoNotShowAgainKey ,
296
+ true
297
+ )
298
+ }
299
+ } )
300
+ context . extensionContext . globalState . update (
301
+ CodeWhispererConstants . accessTokenMigrationDoNotShowLastShown ,
302
+ Date . now ( )
303
+ )
304
+ }
305
+
306
+ function maybeShowTokenMigrationError ( ) {
307
+ const migrationErrordoNotShowAgain =
308
+ context . extensionContext . globalState . get < boolean > (
309
+ CodeWhispererConstants . accessTokenExpiredDoNotShowAgainKey
310
+ ) || false
311
+ const migrationErrorLastShown : number =
312
+ context . extensionContext . globalState . get < number | undefined > (
313
+ CodeWhispererConstants . accessTokenExpiredDoNotShowLastShown
314
+ ) || 1
315
+
316
+ //Add 7 days to notificationLastShown to determine whether warn message should show
317
+ if ( migrationErrordoNotShowAgain || migrationErrorLastShown + 1000 * 60 * 60 * 24 * 7 >= Date . now ( ) ) {
318
+ return
301
319
}
320
+
321
+ vscode . window
322
+ . showErrorMessage (
323
+ CodeWhispererConstants . accessTokenMigrationErrorMessage ,
324
+ CodeWhispererConstants . accessTokenMigrationErrorButtonMessage ,
325
+ CodeWhispererConstants . accessTokenMigrationLearnMore ,
326
+ CodeWhispererConstants . accessTokenMigrationDoNotShowAgain
327
+ )
328
+ . then ( async resp => {
329
+ if ( resp === CodeWhispererConstants . accessTokenMigrationErrorButtonMessage ) {
330
+ await vscode . commands . executeCommand ( 'aws.codeWhisperer.refresh' )
331
+ await showSsoSignIn . execute ( )
332
+ } else if ( resp === CodeWhispererConstants . accessTokenMigrationDoNotShowAgain ) {
333
+ await context . extensionContext . globalState . update (
334
+ CodeWhispererConstants . accessTokenExpiredDoNotShowAgainKey ,
335
+ true
336
+ )
337
+ } else if ( resp === CodeWhispererConstants . accessTokenMigrationLearnMore ) {
338
+ await vscode . commands . executeCommand ( 'aws.codeWhisperer.accessTokenErrorLearnMore' )
339
+ }
340
+ } )
341
+ context . extensionContext . globalState . update (
342
+ CodeWhispererConstants . accessTokenExpiredDoNotShowLastShown ,
343
+ Date . now ( )
344
+ )
302
345
}
303
346
304
347
function setStatusBarOK ( ) {
0 commit comments