Skip to content

Commit 7b4952c

Browse files
committed
Brett's comments
1 parent 16b8c74 commit 7b4952c

File tree

4 files changed

+16
-26
lines changed

4 files changed

+16
-26
lines changed

src/api/atelier.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export interface Document {
4141
cat: "RTN" | "CLS" | "CSP" | "OTH";
4242
status: string;
4343
enc: boolean;
44-
flags: number;
44+
flags?: 0 | 1;
4545
content: string[] | Buffer;
4646
ext?: UserAction | UserAction[];
4747
}

src/api/index.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -674,19 +674,7 @@ export class AtelierAPI {
674674
name: string,
675675
data: { enc: boolean; content: string[]; mtime: number },
676676
ignoreConflict?: boolean
677-
): Promise<
678-
Atelier.Response<{
679-
name: string;
680-
db: string;
681-
ts: string;
682-
cat: "CLS" | "CSP" | "RTN" | "OTH";
683-
status: string;
684-
enc: boolean;
685-
flags?: 0 | 1;
686-
content: string[];
687-
ext: any;
688-
}>
689-
> {
677+
): Promise<Atelier.Response<Atelier.Document>> {
690678
const params = { ignoreConflict };
691679
name = this.transformNameIfCsp(name);
692680
const headers = {};

src/commands/compile.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ export async function importFile(
132132
if (data.result.flags === 1 && !willCompile) {
133133
// If flags === 1, putDoc returns new Storage definitions and the file must be a CLS
134134
const oldContent = new TextDecoder("utf-8").decode(await vscode.workspace.fs.readFile(file.uri));
135-
const oldContentArray = oldContent.split(/\r?\n/g);
136-
const newContentArray = updateStorage(oldContentArray, data.result.content);
135+
const oldContentArray = oldContent.split(/\r?\n/);
136+
const storage = Buffer.isBuffer(data.result.content) ? new TextDecoder().decode(data.result.content).split(/\r?\n/g) : data.result.content;
137+
const newContentArray = updateStorage(oldContentArray, storage);
137138
if (oldContentArray.some((oldLine, index) => oldLine !== newContentArray[index])) {
138139
const EOL = ((<CurrentTextFile>file)?.eol ?? vscode.EndOfLine.LF) == vscode.EndOfLine.CRLF ? "\r\n" : "\n";
139140
const newContent = newContentArray.join(EOL);
@@ -304,14 +305,15 @@ function storageToMap(storage: string[]): Map<string, string> {
304305
if (line.startsWith("Storage ")) {
305306
k = line.slice("Storage ".length, line.length);
306307
v = [];
307-
} else if (line === "{") {
308-
continue;
309-
} else if (line === "}") {
310-
map.set(k, v.join("\n"));
311-
} else if (line === "") {
312-
continue;
313-
} else {
314-
v.push(line);
308+
} else if (k !== undefined) {
309+
if (line === "{") {
310+
continue;
311+
} else if (line === "}") {
312+
map.set(k, v.join("\n"));
313+
k = undefined;
314+
} else {
315+
v.push(line);
316+
}
315317
}
316318
}
317319
return map;
@@ -392,7 +394,7 @@ export async function importAndCompile(document?: vscode.TextDocument, askFlags
392394
} else {
393395
await importFile(file, false);
394396
}
395-
} catch (_) {
397+
} catch {
396398
// importFile handles any server errors
397399
}
398400
}

src/utils/documentIndex.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
276276
debouncedCompile(change.addedOrChanged);
277277
}
278278
}
279-
} catch (_) {
279+
} catch {
280280
// importFile handles any server errors
281281
}
282282
}

0 commit comments

Comments
 (0)