@@ -52,8 +52,8 @@ import { getIdeProperties, isCloud9 } from '../../shared/extensionUtilities'
5252
5353type CreateReason = 'unknown' | 'userCancelled' | 'fileNotFound' | 'complete' | 'error'
5454
55- /** Target file to open after creating a new SAM application */
56- export const SAM_INIT_OPEN_TARGET : string = 'README.md'
55+ export const SAM_INIT_TEMPLATE_FILE : string = 'template.yaml'
56+ export const SAM_INIT_README_FILE : string = 'README.md'
5757
5858export async function resumeCreateNewSamApp (
5959 extContext : ExtContext ,
@@ -64,8 +64,9 @@ export async function resumeCreateNewSamApp(
6464 let samVersion : string | undefined
6565 const samInitState : SamInitState | undefined = activationReloadState . getSamInitState ( )
6666 try {
67- const uri = vscode . Uri . file ( samInitState ?. path ! )
68- const folder = vscode . workspace . getWorkspaceFolder ( uri )
67+ const templateUri = vscode . Uri . file ( samInitState ?. template ! )
68+ const readmeUri = vscode . Uri . file ( samInitState ?. readme ! )
69+ const folder = vscode . workspace . getWorkspaceFolder ( templateUri )
6970 if ( ! folder ) {
7071 createResult = 'Failed'
7172 reason = 'error'
@@ -75,7 +76,7 @@ export async function resumeCreateNewSamApp(
7576 localize (
7677 'AWS.samcli.initWizard.source.error.notInWorkspace' ,
7778 "Could not open file '{0}'. If this file exists on disk, try adding it to your workspace." ,
78- uri . fsPath
79+ templateUri . fsPath
7980 )
8081 )
8182
@@ -87,10 +88,12 @@ export async function resumeCreateNewSamApp(
8788 await addInitialLaunchConfiguration (
8889 extContext ,
8990 folder ,
90- uri ,
91+ templateUri ,
9192 samInitState ?. isImage ? samInitState ?. runtime : undefined
9293 )
93- await vscode . window . showTextDocument ( uri )
94+ isCloud9 ( )
95+ ? await vscode . workspace . openTextDocument ( readmeUri )
96+ : await vscode . commands . executeCommand ( 'markdown.showPreviewToSide' , readmeUri )
9497 } catch ( err ) {
9598 createResult = 'Failed'
9699 reason = 'error'
@@ -201,8 +204,9 @@ export async function createNewSamApplication(
201204
202205 await runSamCliInit ( initArguments , samCliContext )
203206
204- const uri = await getMainUri ( config )
205- if ( ! uri ) {
207+ const templateUri = await getProjectUri ( config , SAM_INIT_TEMPLATE_FILE )
208+ const readmeUri = await getProjectUri ( config , SAM_INIT_README_FILE )
209+ if ( ! templateUri || ! readmeUri ) {
206210 reason = 'fileNotFound'
207211
208212 return
@@ -239,7 +243,8 @@ export async function createNewSamApplication(
239243
240244 // In case adding the workspace folder triggers a VS Code restart, persist relevant state to be used after reload
241245 activationReloadState . setSamInitState ( {
242- path : uri . fsPath ,
246+ template : templateUri . fsPath ,
247+ readme : readmeUri . fsPath ,
243248 runtime : createRuntime ,
244249 isImage : config . packageType === 'Image' ,
245250 } )
@@ -254,7 +259,7 @@ export async function createNewSamApplication(
254259
255260 // Race condition where SAM app is created but template doesn't register in time.
256261 // Poll for 5 seconds, otherwise direct user to codelens.
257- const isTemplateRegistered = await waitUntil ( async ( ) => ext . templateRegistry . getRegisteredItem ( uri ) , {
262+ const isTemplateRegistered = await waitUntil ( async ( ) => ext . templateRegistry . getRegisteredItem ( templateUri ) , {
258263 timeout : 5000 ,
259264 interval : 500 ,
260265 truthy : false ,
@@ -263,8 +268,8 @@ export async function createNewSamApplication(
263268 if ( isTemplateRegistered ) {
264269 const newLaunchConfigs = await addInitialLaunchConfiguration (
265270 extContext ,
266- vscode . workspace . getWorkspaceFolder ( uri ) ! ,
267- uri ,
271+ vscode . workspace . getWorkspaceFolder ( templateUri ) ! ,
272+ templateUri ,
268273 createRuntime
269274 )
270275 if ( newLaunchConfigs && newLaunchConfigs . length > 0 ) {
@@ -296,8 +301,8 @@ export async function createNewSamApplication(
296301 activationReloadState . clearSamInitState ( )
297302 // TODO: Replace when Cloud9 supports `markdown` commands
298303 isCloud9 ( )
299- ? await vscode . workspace . openTextDocument ( uri )
300- : await vscode . commands . executeCommand ( 'markdown.showPreviewToSide' , uri )
304+ ? await vscode . workspace . openTextDocument ( readmeUri )
305+ : await vscode . commands . executeCommand ( 'markdown.showPreviewToSide' , readmeUri )
301306 } catch ( err ) {
302307 createResult = 'Failed'
303308 reason = 'error'
@@ -333,18 +338,19 @@ async function validateSamCli(samCliValidator: SamCliValidator): Promise<void> {
333338 throwAndNotifyIfInvalid ( validationResult )
334339}
335340
336- export async function getMainUri (
337- config : Pick < CreateNewSamAppWizardResponse , 'location' | 'name' >
341+ export async function getProjectUri (
342+ config : Pick < CreateNewSamAppWizardResponse , 'location' | 'name' > ,
343+ file : string
338344) : Promise < vscode . Uri | undefined > {
339- const cfnTemplatePath = path . resolve ( config . location . fsPath , config . name , SAM_INIT_OPEN_TARGET )
345+ const cfnTemplatePath = path . resolve ( config . location . fsPath , config . name , file )
340346 if ( await fileExists ( cfnTemplatePath ) ) {
341347 return vscode . Uri . file ( cfnTemplatePath )
342348 } else {
343349 vscode . window . showWarningMessage (
344350 localize (
345351 'AWS.samcli.initWizard.source.error.notFound' ,
346352 'Project created successfully, but {0} file not found: {1}' ,
347- SAM_INIT_OPEN_TARGET ,
353+ file ,
348354 cfnTemplatePath
349355 )
350356 )
0 commit comments