@@ -121,23 +121,36 @@ export function isImportableLocalFile(file: vscode.TextDocument): boolean {
121
121
export function currentFileFromContent ( fileName : string , content : string ) : CurrentFile {
122
122
const uri = vscode . Uri . file ( fileName ) ;
123
123
const workspaceFolder = workspaceFolderOfUri ( uri ) ;
124
+ const fileExt = fileName . split ( "." ) . pop ( ) . toLowerCase ( ) ;
124
125
let name = "" ;
125
126
let ext = "" ;
126
- if ( fileName . split ( "." ) . pop ( ) . toLowerCase ( ) === "cls" ) {
127
+ if ( fileExt === "cls" ) {
127
128
// Allow Unicode letters
128
129
const match = content . match ( / ^ [ \t ] * C l a s s [ \t ] + ( % ? [ \p{ L} \d ] + (?: \. [ \p{ L} \d ] + ) + ) / imu) ;
129
130
if ( match ) {
130
131
[ , name , ext = "cls" ] = match ;
131
132
}
132
- } else {
133
+ } else if ( fileExt . match ( / ( m a c | i n t | i n c ) / i ) ) {
133
134
const match = content . match ( / ^ R O U T I N E ( [ ^ \s ] + ) (?: \s * \[ \s * T y p e \s * = \s * \b ( [ a - z ] { 3 } ) \b ) ? / i) ;
134
135
if ( match ) {
135
136
[ , name , ext = "mac" ] = match ;
136
137
} else {
137
138
[ name , ext = "mac" ] = path . basename ( fileName ) . split ( "." ) ;
138
139
}
140
+ } else {
141
+ name = getServerDocName ( fileName , workspaceFolder , fileExt ) ;
142
+ // Need to strip leading / for custom Studio documents which should not be treated as files.
143
+ // e.g. For a custom Studio document Test.ZPM, the variable name would be /Test.ZPM which is
144
+ // not the document name. The document name is Test.ZPM so requests made to the Atelier APIs
145
+ // using the name with the leading / would fail to find the document.
146
+ if ( name . charAt ( 0 ) === "/" ) {
147
+ name = name . slice ( 1 ) ;
148
+ }
139
149
}
140
- name = `${ name } .${ ext } ` ;
150
+ if ( ! name ) {
151
+ return null ;
152
+ }
153
+ name += ext ? "." + ext . toLowerCase ( ) : "" ;
141
154
const firstLF = content . indexOf ( "\n" ) ;
142
155
143
156
return {
@@ -212,7 +225,7 @@ export function currentFile(document?: vscode.TextDocument): CurrentFile {
212
225
// not the document name. The document name is Test.ZPM so requests made to the Atelier APIs
213
226
// using the name with the leading / would fail to find the document.
214
227
if ( name . charAt ( 0 ) === "/" ) {
215
- name = name . substr ( 1 ) ;
228
+ name = name . slice ( 1 ) ;
216
229
}
217
230
}
218
231
if ( ! name ) {
0 commit comments