@@ -8,17 +8,24 @@ import { telemetry } from '../../shared/telemetry/telemetry'
8
8
import { ExtContext } from '../../shared/extensions'
9
9
import { Commands } from '../../shared/vscode/commands2'
10
10
import * as CodeWhispererConstants from '../models/constants'
11
- import { getLogger } from '../../shared/logger'
12
11
import { DefaultCodeWhispererClient } from '../client/codewhisperer'
13
12
import { startSecurityScanWithProgress , confirmStopSecurityScan } from './startSecurityScan'
14
13
import { SecurityPanelViewProvider } from '../views/securityPanelViewProvider'
15
14
import { codeScanState } from '../models/model'
15
+ import { connectToEnterpriseSso , getStartUrl } from '../util/getStartUrl'
16
16
import { showConnectionPrompt } from '../util/showSsoPrompt'
17
17
import { ReferenceLogViewProvider } from '../service/referenceLogViewProvider'
18
18
import { AuthUtil } from '../util/authUtil'
19
19
import { isCloud9 } from '../../shared/extensionUtilities'
20
20
import { InlineCompletionService } from '../service/inlineCompletionService'
21
21
import { openUrl } from '../../shared/utilities/vsCodeUtils'
22
+ import {
23
+ getPersistedCustomizations ,
24
+ notifyNewCustomizations ,
25
+ selectCustomization ,
26
+ showCustomizationPrompt ,
27
+ } from '../util/customizationUtil'
28
+ import { get , set } from '../util/commonUtil'
22
29
import { CodeWhispererCommandDeclarations } from '../commands/gettingStartedPageCommands'
23
30
import { getIcon } from '../../shared/icons'
24
31
import { localize } from '../../shared/utilities/vsCodeUtils'
@@ -38,7 +45,7 @@ export const toggleCodeSuggestions = Commands.declare(
38
45
} )
39
46
}
40
47
)
41
- /*
48
+ /*
42
49
createGettingStartedNode(Learn) will be a childnode of CodeWhisperer
43
50
onClick on this "Learn" Node will open the Learn CodeWhisperer Page.
44
51
*/
@@ -98,28 +105,54 @@ export const showSecurityScan = Commands.declare(
98
105
}
99
106
)
100
107
108
+ export const selectCustomizationPrompt = Commands . declare ( 'aws.codeWhisperer.selectCustomization' , ( ) => async ( ) => {
109
+ telemetry . ui_click . emit ( { elementId : 'cw_selectCustomization_Cta' } )
110
+ showCustomizationPrompt ( ) . then ( )
111
+ } )
112
+
101
113
export const reconnect = Commands . declare ( 'aws.codeWhisperer.reconnect' , ( ) => async ( ) => {
102
114
await AuthUtil . instance . reauthenticate ( )
103
115
} )
104
116
105
- export function get ( key : string , context : vscode . Memento ) : any {
106
- return context . get ( key )
107
- }
108
-
109
- export async function set ( key : string , value : any , context : vscode . Memento ) : Promise < void > {
110
- await context . update ( key , value ) . then (
111
- ( ) => { } ,
112
- error => {
113
- getLogger ( ) . verbose ( `Failed to update global state: ${ error } ` )
114
- }
115
- )
116
- }
117
-
118
117
export const showSsoSignIn = Commands . declare ( 'aws.codeWhisperer.sso' , ( ) => async ( ) => {
119
118
telemetry . ui_click . emit ( { elementId : 'cw_signUp_Cta' } )
120
119
await showConnectionPrompt ( )
121
120
} )
122
121
122
+ // Shortcut command to directly connect to Identity Center or prompt start URL entry
123
+ // It can optionally set a customization too.
124
+ export const connectWithCustomization = Commands . declare (
125
+ 'aws.codeWhisperer.connect' ,
126
+ ( ) =>
127
+ async (
128
+ startUrl ?: string ,
129
+ region ?: string ,
130
+ customizationArn ?: string ,
131
+ customizationName ?: string ,
132
+ customizationDescription ?: string
133
+ ) => {
134
+ // This command supports two sets of arguments:
135
+ // * startUrl and region. If both arguments are provided they will be used, otherwise
136
+ // the command prompts for them interactively.
137
+ // * customization{Arn, Name, Description}. If at least customizationArn is provided,
138
+ // the command selects this customization.
139
+ if ( startUrl && region ) {
140
+ await connectToEnterpriseSso ( startUrl , region )
141
+ } else {
142
+ await getStartUrl ( )
143
+ }
144
+ if ( customizationArn ) {
145
+ const match = getPersistedCustomizations ( ) . find ( c => c . arn == customizationArn )
146
+ const customization = {
147
+ arn : customizationArn ,
148
+ name : customizationName ?? match ?. name ?? 'unknown' ,
149
+ description : customizationDescription ?? match ?. description ?? 'unknown' ,
150
+ }
151
+ await selectCustomization ( customization )
152
+ }
153
+ }
154
+ )
155
+
123
156
export const showLearnMore = Commands . declare ( 'aws.codeWhisperer.learnMore' , ( ) => async ( ) => {
124
157
telemetry . ui_click . emit ( { elementId : 'cw_learnMore_Cta' } )
125
158
openUrl ( vscode . Uri . parse ( CodeWhispererConstants . learnMoreUriGeneral ) )
@@ -149,3 +182,10 @@ export const refreshStatusBar = Commands.declare(
149
182
}
150
183
}
151
184
)
185
+
186
+ export const notifyNewCustomizationsCmd = Commands . declare (
187
+ { id : 'aws.codeWhisperer.notifyNewCustomizations' , logging : false } ,
188
+ ( ) => ( ) => {
189
+ notifyNewCustomizations ( ) . then ( )
190
+ }
191
+ )
0 commit comments