@@ -69,6 +69,7 @@ import { UserWrittenCodeTracker } from '../tracker/userWrittenCodeTracker'
6969import { parsePatch } from 'diff'
7070import { createCodeIssueGroupingStrategyPrompter } from '../ui/prompters'
7171import { cancel , confirm } from '../../shared/localizedText'
72+ import { LanguageClient } from 'vscode-languageclient'
7273
7374const MessageTimeOut = 5_000
7475
@@ -237,15 +238,18 @@ export const showFileScan = Commands.declare(
237238 }
238239)
239240
240- export const selectCustomizationPrompt = Commands . declare (
241- { id : 'aws.amazonq.selectCustomization' , compositeKey : { 1 : 'source' } } ,
242- ( ) => async ( _ : VsCodeCommandArg , source : CodeWhispererSource ) => {
241+ export const selectCustomizationHandler =
242+ ( client ?: LanguageClient ) => async ( _ : VsCodeCommandArg , source : CodeWhispererSource ) => {
243243 if ( isBuilderIdConnection ( AuthUtil . instance . conn ) ) {
244244 throw new Error ( `Select Customizations are not supported with the Amazon Builder ID connection.` )
245245 }
246246 telemetry . ui_click . emit ( { elementId : 'cw_selectCustomization_Cta' } )
247- void showCustomizationPrompt ( ) . then ( )
247+ void showCustomizationPrompt ( client ) . then ( )
248248 }
249+
250+ export const selectCustomizationPrompt = Commands . declare (
251+ { id : 'aws.amazonq.selectCustomization' , compositeKey : { 1 : 'source' } } ,
252+ ( ) => selectCustomizationHandler ( )
249253)
250254
251255export const reconnect = Commands . declare (
@@ -263,6 +267,53 @@ export const showSsoSignIn = Commands.declare('aws.amazonq.sso', () => async ()
263267// It can optionally set a customization too based on given values to match on
264268
265269// This command is only declared and registered in Amazon Q if Q exists
270+
271+ export const connectCustomizationHandler =
272+ ( client ?: LanguageClient ) =>
273+ async (
274+ source : string ,
275+ startUrl ?: string ,
276+ region ?: string ,
277+ customizationArn ?: string ,
278+ customizationNamePrefix ?: string
279+ ) => {
280+ SsoAccessTokenProvider . authSource = source
281+ if ( startUrl && region ) {
282+ await connectToEnterpriseSso ( startUrl , region )
283+ } else {
284+ await getStartUrl ( )
285+ }
286+
287+ // No customization match information given, exit early.
288+ if ( ! customizationArn && ! customizationNamePrefix ) {
289+ return
290+ }
291+
292+ let persistedCustomizations = getPersistedCustomizations ( )
293+
294+ // Check if any customizations have already been persisted.
295+ // If not, call `notifyNewCustomizations` to handle it then recheck.
296+ if ( persistedCustomizations . length === 0 ) {
297+ await notifyNewCustomizations ( client )
298+ persistedCustomizations = getPersistedCustomizations ( )
299+ }
300+
301+ // If given an ARN, assume a specific customization is desired and find an entry that matches it. Ignores the prefix logic.
302+ // Otherwise if only a prefix is given, find an entry that matches it.
303+ // Backwards compatible with previous implementation.
304+ const match = customizationArn
305+ ? persistedCustomizations . find ( ( c ) => c . arn === customizationArn )
306+ : persistedCustomizations . find ( ( c ) => c . name ?. startsWith ( customizationNamePrefix as string ) )
307+
308+ // If no match is found, nothing to do :)
309+ if ( ! match ) {
310+ getLogger ( ) . error ( `No customization match found: arn=${ customizationArn } prefix=${ customizationNamePrefix } ` )
311+ return
312+ }
313+ // Since we selected based on a match, we'll reuse the persisted values.
314+ await selectCustomization ( match , client )
315+ }
316+
266317export const connectWithCustomization = Commands . declare (
267318 { id : 'aws.codeWhisperer.connect' , compositeKey : { 0 : 'source' } } ,
268319 /**
@@ -273,52 +324,7 @@ export const connectWithCustomization = Commands.declare(
273324 * customizationArn: select customization by ARN. If provided, `customizationNamePrefix` is ignored.
274325 * customizationNamePrefix: select customization by prefix, if `customizationArn` is `undefined`.
275326 */
276- ( ) =>
277- async (
278- source : string ,
279- startUrl ?: string ,
280- region ?: string ,
281- customizationArn ?: string ,
282- customizationNamePrefix ?: string
283- ) => {
284- SsoAccessTokenProvider . authSource = source
285- if ( startUrl && region ) {
286- await connectToEnterpriseSso ( startUrl , region )
287- } else {
288- await getStartUrl ( )
289- }
290-
291- // No customization match information given, exit early.
292- if ( ! customizationArn && ! customizationNamePrefix ) {
293- return
294- }
295-
296- let persistedCustomizations = getPersistedCustomizations ( )
297-
298- // Check if any customizations have already been persisted.
299- // If not, call `notifyNewCustomizations` to handle it then recheck.
300- if ( persistedCustomizations . length === 0 ) {
301- await notifyNewCustomizations ( )
302- persistedCustomizations = getPersistedCustomizations ( )
303- }
304-
305- // If given an ARN, assume a specific customization is desired and find an entry that matches it. Ignores the prefix logic.
306- // Otherwise if only a prefix is given, find an entry that matches it.
307- // Backwards compatible with previous implementation.
308- const match = customizationArn
309- ? persistedCustomizations . find ( ( c ) => c . arn === customizationArn )
310- : persistedCustomizations . find ( ( c ) => c . name ?. startsWith ( customizationNamePrefix as string ) )
311-
312- // If no match is found, nothing to do :)
313- if ( ! match ) {
314- getLogger ( ) . error (
315- `No customization match found: arn=${ customizationArn } prefix=${ customizationNamePrefix } `
316- )
317- return
318- }
319- // Since we selected based on a match, we'll reuse the persisted values.
320- await selectCustomization ( match )
321- }
327+ ( ) => connectCustomizationHandler ( )
322328)
323329
324330export const showLearnMore = Commands . declare (
0 commit comments