Skip to content

Commit 949ac6e

Browse files
authored
Fix syncing local CSP files (#887)
1 parent d17ab90 commit 949ac6e

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/utils/index.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,23 +121,36 @@ export function isImportableLocalFile(file: vscode.TextDocument): boolean {
121121
export function currentFileFromContent(fileName: string, content: string): CurrentFile {
122122
const uri = vscode.Uri.file(fileName);
123123
const workspaceFolder = workspaceFolderOfUri(uri);
124+
const fileExt = fileName.split(".").pop().toLowerCase();
124125
let name = "";
125126
let ext = "";
126-
if (fileName.split(".").pop().toLowerCase() === "cls") {
127+
if (fileExt === "cls") {
127128
// Allow Unicode letters
128129
const match = content.match(/^[ \t]*Class[ \t]+(%?[\p{L}\d]+(?:\.[\p{L}\d]+)+)/imu);
129130
if (match) {
130131
[, name, ext = "cls"] = match;
131132
}
132-
} else {
133+
} else if (fileExt.match(/(mac|int|inc)/i)) {
133134
const match = content.match(/^ROUTINE ([^\s]+)(?:\s*\[\s*Type\s*=\s*\b([a-z]{3})\b)?/i);
134135
if (match) {
135136
[, name, ext = "mac"] = match;
136137
} else {
137138
[name, ext = "mac"] = path.basename(fileName).split(".");
138139
}
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+
}
139149
}
140-
name = `${name}.${ext}`;
150+
if (!name) {
151+
return null;
152+
}
153+
name += ext ? "." + ext.toLowerCase() : "";
141154
const firstLF = content.indexOf("\n");
142155

143156
return {
@@ -212,7 +225,7 @@ export function currentFile(document?: vscode.TextDocument): CurrentFile {
212225
// not the document name. The document name is Test.ZPM so requests made to the Atelier APIs
213226
// using the name with the leading / would fail to find the document.
214227
if (name.charAt(0) === "/") {
215-
name = name.substr(1);
228+
name = name.slice(1);
216229
}
217230
}
218231
if (!name) {

0 commit comments

Comments
 (0)