Skip to content

Commit c4f47a2

Browse files
committed
feat(sam): "Sync SAM" shows more info if no template.yaml found
Problem: When trying the "Sync SAM" command, the "No items found" message is confusing. Solution: - Show a more informative message. - Visit the help page if user hits Enter. related: #2996
1 parent eaf4b14 commit c4f47a2

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/shared/constants.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
import * as vscode from 'vscode'
7+
68
import { isCloud9 } from './extensionUtilities'
79

810
export const extensionSettingsPrefix = 'aws'
@@ -38,9 +40,11 @@ export const supportedLambdaRuntimesUrl: string =
3840
'https://docs.aws.amazon.com/lambda/latest/dg/runtime-support-policy.html'
3941
export const createUrlForLambdaFunctionUrl = 'https://docs.aws.amazon.com/lambda/latest/dg/urls-configuration.html'
4042
// URLs for samInitWizard
41-
export const samInitDocUrl: string = isCloud9()
42-
? 'https://docs.aws.amazon.com/cloud9/latest/user-guide/serverless-apps-toolkit.html#sam-create'
43-
: 'https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/serverless-apps.html#serverless-apps-create'
43+
export const samInitDocUrl = vscode.Uri.parse(
44+
isCloud9()
45+
? 'https://docs.aws.amazon.com/cloud9/latest/user-guide/serverless-apps-toolkit.html#sam-create'
46+
: 'https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/serverless-apps.html#serverless-apps-create'
47+
)
4448
export const launchConfigDocUrl: string = isCloud9()
4549
? 'https://docs.aws.amazon.com/cloud9/latest/user-guide/sam-debug-config-ref.html'
4650
: 'https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/serverless-apps-run-debug-config-ref.html'
@@ -50,8 +54,9 @@ export const samDeployDocUrl: string = isCloud9()
5054
: 'https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/serverless-apps.html#serverless-apps-deploy'
5155
export const lambdaFunctionUrlConfigUrl: string = 'https://docs.aws.amazon.com/lambda/latest/dg/urls-configuration.html'
5256
// URLs for "sam sync" wizard.
53-
export const samSyncUrl: string =
57+
export const samSyncUrl = vscode.Uri.parse(
5458
'https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/accelerate-getting-started.html'
59+
)
5560

5661
// URLs for CDK
5762
export const cdkProvideFeedbackUrl: string = `${githubUrl}/issues/new/choose`

src/shared/sam/sync.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import globals from '../extensionGlobals'
77

88
import * as vscode from 'vscode'
99
import * as path from 'path'
10+
import * as nls from 'vscode-nls'
1011
import * as localizedText from '../localizedText'
1112
import { DefaultS3Client } from '../clients/s3Client'
1213
import { Wizard } from '../wizards/wizard'
@@ -40,7 +41,9 @@ import { parse } from 'semver'
4041
import { isAutomation } from '../vscode/env'
4142
import { getOverriddenParameters } from '../../lambda/config/parameterUtils'
4243
import { addTelemetryEnvVar } from './cli/samCliInvokerUtils'
43-
import { samSyncUrl } from '../constants'
44+
import { samSyncUrl, samInitDocUrl } from '../constants'
45+
46+
const localize = nls.loadMessageBundle()
4447

4548
export interface SyncParams {
4649
readonly region: string
@@ -166,8 +169,14 @@ function createTemplatePrompter() {
166169

167170
const trimmedItems = folders.size === 1 ? items.map(item => ({ ...item, description: undefined })) : items
168171
return createQuickPick(trimmedItems, {
169-
title: 'Select a CloudFormation Template',
172+
title: 'Select a SAM CloudFormation Template',
173+
placeholder: 'Select a SAM template.yaml file',
170174
buttons: createCommonButtons(samSyncUrl),
175+
noItemsFoundItem: {
176+
label: localize('aws.sam.noWorkspace', 'No SAM template.yaml file(s) found. Select for help'),
177+
data: undefined,
178+
onClick: () => vscode.env.openExternal(samInitDocUrl),
179+
},
171180
})
172181
}
173182

src/test/shared/sam/sync.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('SyncWizard', function () {
2121
const createTester = (params?: Partial<SyncParams>) =>
2222
createWizardTester(new SyncWizard({ deployType: 'code', ...params }))
2323

24-
it('prompts for region -> template -> stackName -> bucketName', function () {
24+
it('shows steps in correct order', function () {
2525
const tester = createTester()
2626
tester.region.assertShowFirst()
2727
tester.template.assertShowSecond()

0 commit comments

Comments
 (0)