@@ -32,49 +32,66 @@ export function generateFileContent(
32
32
const csp = fileName . startsWith ( "/" ) ;
33
33
if ( fileExt === "cls" && ! csp ) {
34
34
const className = fileName . split ( "." ) . slice ( 0 , - 1 ) . join ( "." ) ;
35
- const content : string [ ] = [ ] ;
35
+ let content : string [ ] = [ ] ;
36
36
const preamble : string [ ] = [ ] ;
37
37
38
- // If content was provided (e.g. when copying a file), use all lines except for
39
- // the Class x.y one. Replace that with one to match fileName.
40
- while ( sourceLines . length > 0 ) {
41
- const nextLine = sourceLines . shift ( ) ;
42
- if ( nextLine . startsWith ( "Class " ) ) {
43
- const classLine = nextLine . split ( " " ) ;
44
- classLine [ 1 ] = className ;
45
- content . push ( ...preamble , classLine . join ( " " ) , ...sourceLines ) ;
46
- break ;
38
+ if ( sourceLines . length ) {
39
+ if ( uri . scheme == "file" && ( fileName . includes ( path . sep ) || fileName . includes ( " " ) ) ) {
40
+ // We couldn't resolve a class name from the file path,
41
+ // so keep the source text unchanged.
42
+ content = sourceLines ;
43
+ } else {
44
+ // Use all lines except for the Class x.y one.
45
+ // Replace that with one to match fileName.
46
+ while ( sourceLines . length > 0 ) {
47
+ const nextLine = sourceLines . shift ( ) ;
48
+ if ( nextLine . startsWith ( "Class " ) ) {
49
+ const classLine = nextLine . split ( " " ) ;
50
+ classLine [ 1 ] = className ;
51
+ content . push ( ...preamble , classLine . join ( " " ) , ...sourceLines ) ;
52
+ break ;
53
+ }
54
+ preamble . push ( nextLine ) ;
55
+ }
47
56
}
48
- preamble . push ( nextLine ) ;
49
- }
50
- if ( content . length === 0 ) {
51
- content . push ( `Class ${ className } Extends %RegisteredObject` , "{" , "}" ) ;
57
+ } else {
58
+ content = [ `Class ${ className } Extends %RegisteredObject` , "{" , "}" ] ;
52
59
}
60
+
53
61
return {
54
62
content,
55
63
enc : false ,
56
64
} ;
57
65
} else if ( [ "int" , "inc" , "mac" ] . includes ( fileExt ) && ! csp ) {
58
- sourceLines . shift ( ) ;
59
- const routineName = fileName . split ( "." ) . slice ( 0 , - 1 ) . join ( "." ) ;
60
- const routineType = fileExt != "mac" ? `[Type=${ fileExt . toUpperCase ( ) } ]` : "" ;
61
- if ( sourceLines . length === 0 && fileExt !== "inc" ) {
62
- const languageId = fileExt === "mac" ? "objectscript" : "objectscript-int" ;
63
-
64
- // Labels cannot contain dots
65
- const firstLabel = routineName . replaceAll ( "." , "" ) ;
66
-
67
- // Be smart about whether to use a Tab or a space between label and comment.
68
- // Doing this will help autodetect to do the right thing.
69
- const lineStart = vscode . workspace . getConfiguration ( "editor" , { languageId, uri } ) . get ( "insertSpaces" )
70
- ? " "
71
- : "\t" ;
72
- sourceLines . push ( `${ firstLabel } ${ lineStart } ;` ) ;
66
+ if ( sourceLines . length && uri . scheme == "file" && ( fileName . includes ( path . sep ) || fileName . includes ( " " ) ) ) {
67
+ // We couldn't resolve a routine name from the file path,
68
+ // so keep the source text unchanged.
69
+ return {
70
+ content : sourceLines ,
71
+ enc : false ,
72
+ } ;
73
+ } else {
74
+ sourceLines . shift ( ) ;
75
+ const routineName = fileName . split ( "." ) . slice ( 0 , - 1 ) . join ( "." ) ;
76
+ const routineType = fileExt != "mac" ? `[Type=${ fileExt . toUpperCase ( ) } ]` : "" ;
77
+ if ( sourceLines . length === 0 && fileExt !== "inc" ) {
78
+ const languageId = fileExt === "mac" ? "objectscript" : "objectscript-int" ;
79
+
80
+ // Labels cannot contain dots
81
+ const firstLabel = routineName . replaceAll ( "." , "" ) ;
82
+
83
+ // Be smart about whether to use a Tab or a space between label and comment.
84
+ // Doing this will help autodetect to do the right thing.
85
+ const lineStart = vscode . workspace . getConfiguration ( "editor" , { languageId, uri } ) . get ( "insertSpaces" )
86
+ ? " "
87
+ : "\t" ;
88
+ sourceLines . push ( `${ firstLabel } ${ lineStart } ;` ) ;
89
+ }
90
+ return {
91
+ content : [ `ROUTINE ${ routineName } ${ routineType } ` , ...sourceLines ] ,
92
+ enc : false ,
93
+ } ;
73
94
}
74
- return {
75
- content : [ `ROUTINE ${ routineName } ${ routineType } ` , ...sourceLines ] ,
76
- enc : false ,
77
- } ;
78
95
}
79
96
return {
80
97
content : [ sourceContent . toString ( "base64" ) ] ,
0 commit comments