Skip to content

Commit 7e25f9e

Browse files
Will Lovowlovo
authored andcommitted
feat(codewhisperer): set customization on connect
Problem: Related to aws-toolkit-vscode-staging#1058, there's a need for enterprises to establish a default customization for onboarding developers based on their need or role. Solution: Provide the ability to define the customization ARN to use after connecting to CodeWhisperer through the `aws.codeWhisperer.connect` command, along side other customization details.
1 parent ff3a695 commit 7e25f9e

File tree

5 files changed

+51
-26
lines changed

5 files changed

+51
-26
lines changed

docs/api.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ Details about any publicly accessible functionalities exposed through [extension
88

99
#### `aws.codeWhisperer.connect`
1010

11-
**Signature**: _async (startUrl?: string, region?: string) => Promise<void>_
11+
**Signature**: _async (startUrl?: string, region?: string, customizationArn?: string, customizationName?: string, customizationDescription?: string) => Promise<void>_
1212

13-
Shortcut command to directly connect to Identity Center or prompt start URL entry, as well as set a customization for CodeWhisperer requests. Customization is not yet supported.
13+
Shortcut command to directly connect to Identity Center or prompt start URL entry, as well as set a customization for CodeWhisperer requests.
1414

15-
This command expects two arguments: startUrl and region (both strings).
16-
If these arguments are provided, they will be used. Otherwise, the commands prompts for them interactively.
15+
This command supports two sets of arguments:
16+
17+
- startUrl and region. If both arguments are provided they will be used, otherwise the command prompts for them interactively.
18+
- customization{Arn, Name, Description}. If at least customizationArn is provided, the command selects this customization.

src/codewhisperer/activation.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ import {
3333
showIntroduction,
3434
reconnect,
3535
refreshStatusBar,
36-
selectCustomization,
36+
selectCustomizationPrompt,
3737
notifyNewCustomizationsCmd,
38-
connectIdCenter,
38+
connectWithCustomization,
3939
} from './commands/basicCommands'
4040
import { sleep } from '../shared/utilities/timeoutUtils'
4141
import { ReferenceLogViewProvider } from './service/referenceLogViewProvider'
@@ -159,8 +159,8 @@ export async function activate(context: ExtContext): Promise<void> {
159159
}),
160160
// show introduction
161161
showIntroduction.register(),
162-
// CodeWhisperer Identity Center connection setup
163-
connectIdCenter.register(),
162+
// direct CodeWhisperer connection setup with customization
163+
connectWithCustomization.register(),
164164
// toggle code suggestions
165165
toggleCodeSuggestions.register(context.extensionContext.globalState),
166166
// enable code suggestions
@@ -184,7 +184,7 @@ export async function activate(context: ExtContext): Promise<void> {
184184
invokeRecommendation(vscode.window.activeTextEditor as vscode.TextEditor, client, await getConfigEntry())
185185
}),
186186
// select customization
187-
selectCustomization.register(),
187+
selectCustomizationPrompt.register(),
188188
// notify new customizations
189189
notifyNewCustomizationsCmd.register(),
190190
/**

src/codewhisperer/commands/basicCommands.ts

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ import { AuthUtil } from '../util/authUtil'
1919
import { isCloud9 } from '../../shared/extensionUtilities'
2020
import { InlineCompletionService } from '../service/inlineCompletionService'
2121
import { openUrl } from '../../shared/utilities/vsCodeUtils'
22-
import { notifyNewCustomizations, showCustomizationPrompt } from '../util/customizationUtil'
22+
import {
23+
getPersistedCustomizations,
24+
notifyNewCustomizations,
25+
selectCustomization,
26+
showCustomizationPrompt,
27+
} from '../util/customizationUtil'
2328
import { get, set } from '../util/commonUtil'
2429
import { CodeWhispererCommandDeclarations } from '../commands/gettingStartedPageCommands'
2530
import { getIcon } from '../../shared/icons'
@@ -40,7 +45,7 @@ export const toggleCodeSuggestions = Commands.declare(
4045
})
4146
}
4247
)
43-
/*
48+
/*
4449
createGettingStartedNode(Learn) will be a childnode of CodeWhisperer
4550
onClick on this "Learn" Node will open the Learn CodeWhisperer Page.
4651
*/
@@ -100,7 +105,7 @@ export const showSecurityScan = Commands.declare(
100105
}
101106
)
102107

103-
export const selectCustomization = Commands.declare('aws.codeWhisperer.selectCustomization', () => async () => {
108+
export const selectCustomizationPrompt = Commands.declare('aws.codeWhisperer.selectCustomization', () => async () => {
104109
telemetry.ui_click.emit({ elementId: 'cw_selectCustomization_Cta' })
105110
showCustomizationPrompt().then()
106111
})
@@ -115,19 +120,37 @@ export const showSsoSignIn = Commands.declare('aws.codeWhisperer.sso', () => asy
115120
})
116121

117122
// Shortcut command to directly connect to Identity Center or prompt start URL entry
118-
// Customization is not yet supported.
119-
export const connectIdCenter = Commands.declare(
123+
// It can optionally set a customization too.
124+
export const connectWithCustomization = Commands.declare(
120125
'aws.codeWhisperer.connect',
121-
() => async (startUrl?: string, region?: string) => {
122-
// This command expects two arguments: startUrl and region (both strings).
123-
// If these arguments are provided, they will be used.
124-
// Otherwise, the commands prompts for them interactively.
125-
if (startUrl && region) {
126-
await connectToEnterpriseSso(startUrl, region)
127-
} else {
128-
await getStartUrl()
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+
}
129153
}
130-
}
131154
)
132155

133156
export const showLearnMore = Commands.declare('aws.codeWhisperer.learnMore', () => async () => {

src/codewhisperer/explorer/codewhispererChildrenNodes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
showLearnMore,
1515
showFreeTierLimit,
1616
reconnect,
17-
selectCustomization,
17+
selectCustomizationPrompt,
1818
} from '../commands/basicCommands'
1919
import { codeScanState } from '../models/model'
2020
import { getNewCustomizationAvailable, getSelectedCustomization } from '../util/customizationUtil'
@@ -96,7 +96,7 @@ export const createSelectCustomizationNode = () => {
9696
const selectedCustomization = getSelectedCustomization()
9797
const newText = newCustomizationsAvailable ? 'new! ' : ''
9898

99-
return selectCustomization.build().asTreeNode({
99+
return selectCustomizationPrompt.build().asTreeNode({
100100
label: localize('AWS.explorerNode.selectCustomization.label', 'Select Customization'),
101101
iconPath: getIcon('vscode-extensions'),
102102
description: `${newText}${selectedCustomization.arn === '' ? '' : selectedCustomization.name}`,

src/codewhisperer/util/customizationUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ const createCustomizationItem = (
279279
} as DataQuickPickItem<string>
280280
}
281281

282-
const selectCustomization = async (customization: Customization) => {
282+
export const selectCustomization = async (customization: Customization) => {
283283
// If the newly selected customization is same as the old one, do nothing
284284
const selectedCustomization = getSelectedCustomization()
285285
if (selectedCustomization.arn === customization.arn) {

0 commit comments

Comments
 (0)