@@ -21,7 +21,11 @@ declare function setTimeout(callback: (...args: any[]) => void, ms: number, ...a
2121
2222export type Entry = File | Directory ;
2323
24- export function generateFileContent ( fileName : string , sourceContent : Buffer ) : { content : string [ ] ; enc : boolean } {
24+ export function generateFileContent (
25+ uri : vscode . Uri ,
26+ fileName : string ,
27+ sourceContent : Buffer
28+ ) : { content : string [ ] ; enc : boolean } {
2529 const sourceLines = sourceContent . toString ( ) . split ( "\n" ) ;
2630 const fileExt = fileName . split ( "." ) . pop ( ) . toLowerCase ( ) ;
2731 const csp = fileName . startsWith ( "/" ) ;
@@ -53,6 +57,19 @@ export function generateFileContent(fileName: string, sourceContent: Buffer): {
5357 sourceLines . shift ( ) ;
5458 const routineName = fileName . split ( "." ) . slice ( 0 , - 1 ) . join ( "." ) ;
5559 const routineType = fileExt != "mac" ? `[Type=${ fileExt . toUpperCase ( ) } ]` : "" ;
60+ if ( sourceLines . length === 0 && fileExt !== "inc" ) {
61+ const languageId = fileExt === "mac" ? "objectscript" : "objectscript-int" ;
62+
63+ // Labels cannot contain dots
64+ const firstLabel = routineName . replaceAll ( "." , "" ) ;
65+
66+ // Be smart about whether to use a Tab or a space between label and comment.
67+ // Doing this will help autodetect to do the right thing.
68+ const lineStart = vscode . workspace . getConfiguration ( "editor" , { languageId, uri } ) . get ( "insertSpaces" )
69+ ? " "
70+ : "\t" ;
71+ sourceLines . push ( `${ firstLabel } ${ lineStart } ;` ) ;
72+ }
5673 return {
5774 content : [ `ROUTINE ${ routineName } ${ routineType } ` , ...sourceLines ] ,
5875 enc : false ,
@@ -354,7 +371,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
354371 }
355372 // File doesn't exist on the server, and we are allowed to create it.
356373 // Create content (typically a stub, unless the write-phase of a copy operation).
357- const newContent = generateFileContent ( fileName , content ) ;
374+ const newContent = generateFileContent ( uri , fileName , content ) ;
358375
359376 // Write it to the server
360377 return api
@@ -388,6 +405,12 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
388405 this . _lookupAsFile ( uri ) . then ( ( ) => {
389406 this . _fireSoon ( { type : vscode . FileChangeType . Changed , uri } ) ;
390407 } ) ;
408+
409+ // Ask to put cursor at start of 3rd line.
410+ // For CLS stub this will be where properties and methods need to be inserted.
411+ // For MAC and INT stubs there is no 3rd line, so cursor goes to the end of the 2nd, which is 1st of actual routine and is ready for comment text.
412+ const editor = await vscode . window . showTextDocument ( uri ) ;
413+ editor . selection = new vscode . Selection ( 2 , 0 , 2 , 0 ) ;
391414 } ) ;
392415 }
393416 ) ;
@@ -555,7 +578,11 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
555578 const newCsp = newParams . has ( "csp" ) && [ "" , "1" ] . includes ( newParams . get ( "csp" ) ) ;
556579 const newFileName = newCsp ? newUri . path : newUri . path . slice ( 1 ) . replace ( / \/ / g, "." ) ;
557580 // Generate content for the new file
558- const newContent = generateFileContent ( newFileName , Buffer . from ( await vscode . workspace . fs . readFile ( oldUri ) ) ) ;
581+ const newContent = generateFileContent (
582+ newUri ,
583+ newFileName ,
584+ Buffer . from ( await vscode . workspace . fs . readFile ( oldUri ) )
585+ ) ;
559586 if ( newFileStat ) {
560587 // We're overwriting an existing file so prompt the user to check it out
561588 await fireOtherStudioAction ( OtherStudioAction . AttemptedEdit , newUri ) ;
0 commit comments