@@ -21,7 +21,11 @@ declare function setTimeout(callback: (...args: any[]) => void, ms: number, ...a
21
21
22
22
export type Entry = File | Directory ;
23
23
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 } {
25
29
const sourceLines = sourceContent . toString ( ) . split ( "\n" ) ;
26
30
const fileExt = fileName . split ( "." ) . pop ( ) . toLowerCase ( ) ;
27
31
const csp = fileName . startsWith ( "/" ) ;
@@ -53,6 +57,19 @@ export function generateFileContent(fileName: string, sourceContent: Buffer): {
53
57
sourceLines . shift ( ) ;
54
58
const routineName = fileName . split ( "." ) . slice ( 0 , - 1 ) . join ( "." ) ;
55
59
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
+ }
56
73
return {
57
74
content : [ `ROUTINE ${ routineName } ${ routineType } ` , ...sourceLines ] ,
58
75
enc : false ,
@@ -354,7 +371,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
354
371
}
355
372
// File doesn't exist on the server, and we are allowed to create it.
356
373
// 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 ) ;
358
375
359
376
// Write it to the server
360
377
return api
@@ -388,6 +405,12 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
388
405
this . _lookupAsFile ( uri ) . then ( ( ) => {
389
406
this . _fireSoon ( { type : vscode . FileChangeType . Changed , uri } ) ;
390
407
} ) ;
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 ) ;
391
414
} ) ;
392
415
}
393
416
) ;
@@ -555,7 +578,11 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
555
578
const newCsp = newParams . has ( "csp" ) && [ "" , "1" ] . includes ( newParams . get ( "csp" ) ) ;
556
579
const newFileName = newCsp ? newUri . path : newUri . path . slice ( 1 ) . replace ( / \/ / g, "." ) ;
557
580
// 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
+ ) ;
559
586
if ( newFileStat ) {
560
587
// We're overwriting an existing file so prompt the user to check it out
561
588
await fireOtherStudioAction ( OtherStudioAction . AttemptedEdit , newUri ) ;
0 commit comments