Skip to content

Commit 52cbb02

Browse files
committed
sync on save should not depend on compile on save
1 parent 590b138 commit 52cbb02

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/api/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ export class AtelierAPI {
682682
cat: "CLS" | "CSP" | "RTN" | "OTH";
683683
status: string;
684684
enc: boolean;
685-
flag?: "1";
685+
flags?: 0 | 1;
686686
content: string[];
687687
ext: any;
688688
}>

src/commands/compile.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,16 @@ export async function importFile(
128128
ignoreConflict
129129
);
130130
workspaceState.update(`${file.uniqueId}:mtime`, Number(new Date(data.result.ts + "Z")));
131-
if (data.result.flag === "1") {
132-
// putDoc returns new Storage definitions and the file must be a CLS
133-
let content: string[];
134-
(content = new TextDecoder("utf-8").decode(await vscode.workspace.fs.readFile(file.uri)).split(/\r?\n/g)),
135-
(content = updateStorage(content, data.result.content));
136-
await vscode.workspace.fs.writeFile(
137-
file.uri,
138-
new TextEncoder().encode(
139-
content.join(((<CurrentTextFile>file)?.eol ?? vscode.EndOfLine.LF) == vscode.EndOfLine.CRLF ? "\r\n" : "\n")
140-
)
141-
);
131+
if (data.result.flags === 1) {
132+
// If flags === 1, putDoc returns new Storage definitions and the file must be a CLS
133+
const oldContent = new TextDecoder("utf-8").decode(await vscode.workspace.fs.readFile(file.uri));
134+
const oldContentArray = oldContent.split(/\r?\n/g);
135+
const newContentArray = updateStorage(oldContentArray, data.result.content);
136+
if (oldContentArray.some((oldLine, index) => oldLine !== newContentArray[index])) {
137+
const EOL = ((<CurrentTextFile>file)?.eol ?? vscode.EndOfLine.LF) == vscode.EndOfLine.CRLF ? "\r\n" : "\n";
138+
const newContent = newContentArray.join(EOL);
139+
await vscode.workspace.fs.writeFile(file.uri, new TextEncoder().encode(newContent));
140+
}
142141
}
143142
// In case another extension has used an 'objectscript://' uri to load a document read-only from the server,
144143
// make it reload with what we just imported to the server.

0 commit comments

Comments
 (0)