Skip to content

Commit 8fdd45c

Browse files
committed
draft
1 parent 2fa4ad6 commit 8fdd45c

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

src/api/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ export class AtelierAPI {
626626
}
627627

628628
// api v1+
629-
public getDoc(name: string, scope: vscode.Uri | string, mtime?: number): Promise<Atelier.Response<Atelier.Document>> {
629+
public getDoc(name: string, scope: vscode.Uri | string, mtime?: number, storageOnly: boolean = false): Promise<Atelier.Response<Atelier.Document>> {
630630
let params, headers;
631631
name = this.transformNameIfCsp(name);
632632
if (
@@ -642,6 +642,11 @@ export class AtelierAPI {
642642
.get("multilineMethodArgs")
643643
) {
644644
params = { format: "udl-multiline" };
645+
} else {
646+
params = {}
647+
}
648+
if (storageOnly) {
649+
params["storageOnly"] = "1"
645650
}
646651
if (mtime && mtime > 0) {
647652
headers = { "IF-NONE-MATCH": new Date(mtime).toISOString().replace(/T|Z/g, " ").trim() };

src/commands/compile.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
exportedUris,
2525
getWsFolder,
2626
handleError,
27+
isClass,
2728
isClassDeployed,
2829
isClassOrRtn,
2930
isCompilable,
@@ -37,6 +38,7 @@ import {
3738
import { StudioActions } from "./studio";
3839
import { NodeBase, PackageNode, RootNode } from "../explorer/nodes";
3940
import { getUrisForDocument, updateIndex } from "../utils/documentIndex";
41+
import { Document } from "../api/atelier";
4042

4143
/**
4244
* For files being locally edited, get and return its mtime timestamp from workspace-state cache if present there,
@@ -218,7 +220,32 @@ export async function loadChanges(files: (CurrentTextFile | CurrentBinaryFile)[]
218220
const mtime = Number(new Date(doc.ts + "Z"));
219221
workspaceState.update(`${file.uniqueId}:mtime`, mtime > 0 ? mtime : undefined);
220222
if (notIsfs(file.uri)) {
221-
const content = await api.getDoc(file.name, file.uri).then((data) => data.result.content);
223+
let content: Document["content"];
224+
if (isClass(file.uri.path)) {
225+
// Insert/update the storage part of class definition.
226+
content = new TextDecoder('utf-8').decode(await vscode.workspace.fs.readFile(file.uri)).split(/\r?\n/g);
227+
let storageBegin = -1;
228+
let storageEnd = -1;
229+
let classEnd;
230+
for (let i = 0; i < content.length; i ++) {
231+
if (content[i].startsWith("<Storage ")) {
232+
storageBegin = i;
233+
} else if (content[i].startsWith("</Storage>")) {
234+
storageEnd = i;
235+
} else if (content[i].startsWith("}")) {
236+
classEnd = i;
237+
}
238+
}
239+
let storage = (await api.getDoc(file.name, file.uri, undefined, true)).result.content;
240+
storage = Buffer.isBuffer(storage) ? new TextDecoder().decode(storage).split(/\r?\n/g) : storage;
241+
if ((0 <= storageBegin) && (storageBegin < storageEnd)) {
242+
content.splice(storageBegin, storageEnd - storageEnd, ...storage)
243+
} else {
244+
content.splice(classEnd, 0, ...storage)
245+
}
246+
} else {
247+
content = (await api.getDoc(file.name, file.uri)).result.content;
248+
}
222249
exportedUris.add(file.uri.toString()); // Set optimistically
223250
await vscode.workspace.fs
224251
.writeFile(

src/utils/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,11 @@ export function base64EncodeContent(content: Buffer): string[] {
885885
return result;
886886
}
887887

888+
/** Returns `true` if `uri` has a class file extension */
889+
export function isClass(uriOrName: string): boolean {
890+
return "cls" == uriOrName.split(".").pop().toLowerCase();
891+
}
892+
888893
/** Returns `true` if `uri` has a class or routine file extension */
889894
export function isClassOrRtn(uriOrName: string): boolean {
890895
return ["cls", "mac", "int", "inc"].includes(uriOrName.split(".").pop().toLowerCase());

0 commit comments

Comments
 (0)