Skip to content

Commit 10376ec

Browse files
committed
samDeployWizard: gather templates just-in-time
- Problem: Before this change, templates were gathered exactly once (at registration time). If the user later adds/deletes template files in their workspace, the gathered list would be stale. - Solution: Gather templates every time user invokes the "SAM deploy" command.
1 parent c543faa commit 10376ec

File tree

2 files changed

+7
-32
lines changed

2 files changed

+7
-32
lines changed

src/lambda/wizards/samDeployWizard.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ export const enum ParameterPromptResult {
3838
}
3939

4040
export interface SamDeployWizardContext {
41-
readonly templateUris: vscode.Uri[]
42-
4341
readonly workspaceFolders: vscode.Uri[] | undefined
4442

4543
/**
@@ -122,15 +120,11 @@ function getSingleResponse(responses: vscode.QuickPickItem[] | undefined): strin
122120
}
123121

124122
export class DefaultSamDeployWizardContext implements SamDeployWizardContext {
125-
public readonly templateUris: vscode.Uri[]
126123
public readonly getParameters = getParameters
127124
public readonly getOverriddenParameters = getOverriddenParameters
128125
private readonly helpButton = createHelpButton(localize('AWS.command.help', 'View Toolkit Documentation'))
129126

130-
public constructor(private readonly regionProvider: RegionProvider, private readonly awsContext: AwsContext) {
131-
const cfnRegistry = CloudFormationTemplateRegistry.getRegistry()
132-
this.templateUris = cfnRegistry.registeredTemplates.map(o => vscode.Uri.file(o.path))
133-
}
127+
public constructor(private readonly regionProvider: RegionProvider, private readonly awsContext: AwsContext) {}
134128

135129
public get workspaceFolders(): vscode.Uri[] | undefined {
136130
return (vscode.workspace.workspaceFolders || []).map(f => f.uri)
@@ -153,7 +147,7 @@ export class DefaultSamDeployWizardContext implements SamDeployWizardContext {
153147
),
154148
},
155149
buttons: [this.helpButton, vscode.QuickInputButtons.Back],
156-
items: await getTemplateChoices(this.templateUris, ...workspaceFolders),
150+
items: await getTemplateChoices(...workspaceFolders),
157151
})
158152

159153
const choices = await picker.promptUser({
@@ -630,10 +624,9 @@ function validateStackName(value: string): string | undefined {
630624
return undefined
631625
}
632626

633-
async function getTemplateChoices(
634-
templateUris: vscode.Uri[],
635-
...workspaceFolders: vscode.Uri[]
636-
): Promise<SamTemplateQuickPickItem[]> {
627+
async function getTemplateChoices(...workspaceFolders: vscode.Uri[]): Promise<SamTemplateQuickPickItem[]> {
628+
const cfnRegistry = CloudFormationTemplateRegistry.getRegistry()
629+
const templateUris = cfnRegistry.registeredTemplates.map(o => vscode.Uri.file(o.path))
637630
const uriToLabel: Map<vscode.Uri, string> = new Map<vscode.Uri, string>()
638631
const labelCounts: Map<string, number> = new Map()
639632

src/test/lambda/wizards/samDeployWizard.test.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class MockSamDeployWizardContext implements SamDeployWizardContext {
4646
}
4747

4848
public constructor(
49-
public readonly templateUris: vscode.Uri[],
5049
private readonly workspaceFoldersResponses: (vscode.Uri[] | undefined)[] = [],
5150
private readonly promptForSamTemplateResponses: (QuickPickUriResponseItem | undefined)[] = [],
5251
private readonly promptForRegionResponses: (QuickPickRegionResponseItem | undefined)[] = [],
@@ -132,23 +131,16 @@ function normalizePath(...paths: string[]): string {
132131
describe('SamDeployWizard', async () => {
133132
describe('TEMPLATE', async () => {
134133
it('fails gracefully when no templates are found', async () => {
135-
const wizard = new SamDeployWizard(new MockSamDeployWizardContext([], [[]], [undefined], [], []))
134+
const wizard = new SamDeployWizard(new MockSamDeployWizardContext([[]], [undefined], [], []))
136135
const result = await wizard.run()
137136

138137
assert.ok(!result)
139138
})
140139

141140
it('exits wizard when cancelled', async () => {
142141
const workspaceFolderPath = normalizePath('my', 'workspace', 'folder')
143-
const templatePath = normalizePath(workspaceFolderPath, 'template.yaml')
144142
const wizard = new SamDeployWizard(
145-
new MockSamDeployWizardContext(
146-
[vscode.Uri.file(templatePath)],
147-
[[vscode.Uri.file(workspaceFolderPath)]],
148-
[undefined],
149-
[],
150-
[]
151-
)
143+
new MockSamDeployWizardContext([[vscode.Uri.file(workspaceFolderPath)]], [undefined], [], [])
152144
)
153145
const result = await wizard.run()
154146

@@ -160,7 +152,6 @@ describe('SamDeployWizard', async () => {
160152
const templatePath = normalizePath(workspaceFolderPath, 'template.yaml')
161153
const wizard = new SamDeployWizard(
162154
new MockSamDeployWizardContext(
163-
[vscode.Uri.file(templatePath)],
164155
[[vscode.Uri.file(workspaceFolderPath)]],
165156
[createQuickPickUriResponseItem(vscode.Uri.file(templatePath))],
166157
[createQuickPickRegionResponseItem('asdf')],
@@ -194,8 +185,6 @@ describe('SamDeployWizard', async () => {
194185
stackName?: string
195186
}): SamDeployWizardContext {
196187
return {
197-
// It's fine to return an empty list if promptUserForSamTemplate is overridden.
198-
templateUris: [],
199188
// It's fine to return an empty list if promptUserForSamTemplate is overridden.
200189
workspaceFolders: [],
201190

@@ -383,7 +372,6 @@ describe('SamDeployWizard', async () => {
383372

384373
const wizard = new SamDeployWizard(
385374
new MockSamDeployWizardContext(
386-
[vscode.Uri.file(templatePath)],
387375
[[vscode.Uri.file(workspaceFolderPath)]],
388376
[createQuickPickUriResponseItem(vscode.Uri.file(templatePath))],
389377
[createQuickPickRegionResponseItem(region)],
@@ -406,7 +394,6 @@ describe('SamDeployWizard', async () => {
406394

407395
const wizard = new SamDeployWizard(
408396
new MockSamDeployWizardContext(
409-
[vscode.Uri.file(templatePath1), vscode.Uri.file(templatePath2)],
410397
[[vscode.Uri.file(workspaceFolderPath1)], [vscode.Uri.file(workspaceFolderPath2)]],
411398
[
412399
createQuickPickUriResponseItem(vscode.Uri.file(templatePath1)),
@@ -438,7 +425,6 @@ describe('SamDeployWizard', async () => {
438425

439426
const wizard = new SamDeployWizard(
440427
new MockSamDeployWizardContext(
441-
[vscode.Uri.file(templatePath1), vscode.Uri.file(templatePath2)],
442428
[[vscode.Uri.file(workspaceFolderPath1)], [vscode.Uri.file(workspaceFolderPath2)]],
443429
[
444430
createQuickPickUriResponseItem(vscode.Uri.file(templatePath1)),
@@ -464,7 +450,6 @@ describe('SamDeployWizard', async () => {
464450
const templatePath = normalizePath(workspaceFolderPath, 'template.yaml')
465451
const wizard = new SamDeployWizard(
466452
new MockSamDeployWizardContext(
467-
[vscode.Uri.file(templatePath)],
468453
[[vscode.Uri.file(workspaceFolderPath)]],
469454
[createQuickPickUriResponseItem(vscode.Uri.file(templatePath))],
470455
[createQuickPickRegionResponseItem('asdf')],
@@ -485,7 +470,6 @@ describe('SamDeployWizard', async () => {
485470
const templatePath = normalizePath(workspaceFolderPath, 'template.yaml')
486471
const wizard = new SamDeployWizard(
487472
new MockSamDeployWizardContext(
488-
[vscode.Uri.file(templatePath)],
489473
[[vscode.Uri.file(workspaceFolderPath)]],
490474
[createQuickPickUriResponseItem(vscode.Uri.file(templatePath))],
491475
[createQuickPickRegionResponseItem('asdf')],
@@ -504,7 +488,6 @@ describe('SamDeployWizard', async () => {
504488
const templatePath = normalizePath(workspaceFolderPath, 'template.yaml')
505489
const wizard = new SamDeployWizard(
506490
new MockSamDeployWizardContext(
507-
[vscode.Uri.file(templatePath)],
508491
[[vscode.Uri.file(workspaceFolderPath)]],
509492
[createQuickPickUriResponseItem(vscode.Uri.file(templatePath))],
510493
[createQuickPickRegionResponseItem('asdf')],
@@ -526,7 +509,6 @@ describe('SamDeployWizard', async () => {
526509
try {
527510
await new SamDeployWizard(
528511
new MockSamDeployWizardContext(
529-
[vscode.Uri.file(templatePath)],
530512
[[vscode.Uri.file(workspaceFolderPath)]],
531513
[createQuickPickUriResponseItem(vscode.Uri.file(templatePath))],
532514
[createQuickPickRegionResponseItem('asdf')],

0 commit comments

Comments
 (0)