Skip to content

Commit 77d7f48

Browse files
committed
support isfs copy
1 parent c75b393 commit 77d7f48

File tree

2 files changed

+42
-19
lines changed

2 files changed

+42
-19
lines changed

src/api/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ export class AtelierAPI {
390390
throw { statusCode: response.status, message: response.statusText, errorText: data.status.summary };
391391
}
392392
if (data.result.status && data.result.status !== "") {
393-
// This is a 4XX error on a doc request
393+
// This could be a 4XX error on a doc request
394+
// or a 200 from a deleteDoc request for which server-side source control blocked deletion
394395
throw { statusCode: response.status, message: response.statusText, errorText: data.result.status };
395396
}
396397
if (response.status >= 400) {

src/providers/FileSystemProvider/FileSystemProvider.ts

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -143,24 +143,42 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
143143
});
144144
}
145145

146-
private generateFileContent(fileName: string, content: Buffer): { content: string[]; enc: boolean } {
146+
private generateFileContent(fileName: string, sourceContent: Buffer): { content: string[]; enc: boolean } {
147+
const sourceLines = sourceContent.toString().split("\n");
147148
const fileExt = fileName.split(".").pop().toLowerCase();
148149
if (fileExt === "cls") {
149150
const className = fileName.split(".").slice(0, -1).join(".");
151+
const content: string[] = [];
152+
const preamble: string[] = [];
153+
154+
// If content was provided (e.g. when copying a file), use all lines except for
155+
// the Class x.y one. Replace that with one to match fileName.
156+
while (sourceLines.length > 0) {
157+
const nextLine = sourceLines.shift();
158+
if (nextLine.startsWith("Class ")) {
159+
content.push(...preamble, `Class ${className}`, ...sourceLines);
160+
break;
161+
}
162+
preamble.push(nextLine);
163+
}
164+
if (content.length === 0) {
165+
content.push(`Class ${className}`, "{", "}");
166+
}
150167
return {
151-
content: [`Class ${className} {}`],
168+
content,
152169
enc: false,
153170
};
154171
} else if (["int", "inc", "mac"].includes(fileExt)) {
172+
sourceLines.shift();
155173
const routineName = fileName.split(".").slice(0, -1).join(".");
156174
const routineType = `[ type = ${fileExt}]`;
157175
return {
158-
content: [`ROUTINE ${routineName} ${routineType}`],
176+
content: [`ROUTINE ${routineName} ${routineType}`, ...sourceLines],
159177
enc: false,
160178
};
161179
}
162180
return {
163-
content: [content.toString("base64")],
181+
content: [sourceContent.toString("base64")],
164182
enc: true,
165183
};
166184
}
@@ -266,27 +284,31 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
266284
return;
267285
}
268286
const api = new AtelierAPI(uri);
269-
return api.deleteDoc(fileName).then((response) => {
270-
if (response.result.ext) {
271-
fireOtherStudioAction(OtherStudioAction.DeletedDocument, uri, response.result.ext);
287+
return api.deleteDoc(fileName).then(
288+
(response) => {
289+
if (response.result.ext) {
290+
fireOtherStudioAction(OtherStudioAction.DeletedDocument, uri, response.result.ext);
291+
}
292+
// Remove entry from our cache
293+
this._lookupParentDirectory(uri).then((parent) => {
294+
const name = path.basename(uri.path);
295+
parent.entries.delete(name);
296+
});
297+
this._fireSoon({ type: vscode.FileChangeType.Deleted, uri });
298+
},
299+
(error) => {
300+
if (error.statusCode === 200 && error.errorText !== "") {
301+
error.message = error.errorText;
302+
}
303+
throw error;
272304
}
273-
// Remove entry from our cache
274-
this._lookupParentDirectory(uri).then((parent) => {
275-
const name = path.basename(uri.path);
276-
parent.entries.delete(name);
277-
});
278-
this._fireSoon({ type: vscode.FileChangeType.Deleted, uri });
279-
});
305+
);
280306
}
281307

282308
public rename(oldUri: vscode.Uri, newUri: vscode.Uri, options: { overwrite: boolean }): void | Thenable<void> {
283309
throw new Error("Not implemented");
284310
return;
285311
}
286-
public copy?(source: vscode.Uri, destination: vscode.Uri, options: { overwrite: boolean }): void | Thenable<void> {
287-
throw new Error("Not implemented");
288-
return;
289-
}
290312

291313
public watch(uri: vscode.Uri): vscode.Disposable {
292314
return new vscode.Disposable(() => {

0 commit comments

Comments
 (0)