Skip to content

Commit 16b8c74

Browse files
committed
done
1 parent 52cbb02 commit 16b8c74

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

src/commands/compile.ts

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export async function checkChangedOnServer(file: CurrentTextFile | CurrentBinary
8585
// Synchronize the client version and the server version of the same file
8686
export async function importFile(
8787
file: CurrentTextFile | CurrentBinaryFile,
88+
willCompile: boolean,
8889
ignoreConflict?: boolean,
8990
skipDeplCheck = false
9091
): Promise<any> {
@@ -128,7 +129,7 @@ export async function importFile(
128129
ignoreConflict
129130
);
130131
workspaceState.update(`${file.uniqueId}:mtime`, Number(new Date(data.result.ts + "Z")));
131-
if (data.result.flags === 1) {
132+
if (data.result.flags === 1 && !willCompile) {
132133
// If flags === 1, putDoc returns new Storage definitions and the file must be a CLS
133134
const oldContent = new TextDecoder("utf-8").decode(await vscode.workspace.fs.readFile(file.uri));
134135
const oldContentArray = oldContent.split(/\r?\n/g);
@@ -180,7 +181,7 @@ What do you want to do?`,
180181
// Clear cache entry
181182
workspaceState.update(`${file.uniqueId}:mtime`, undefined);
182183
// Overwrite
183-
return importFile(file, true, true);
184+
return importFile(file, willCompile, true, true);
184185
case "Pull Server Changes":
185186
loadChanges([file]);
186187
return Promise.reject();
@@ -384,14 +385,16 @@ export async function importAndCompile(document?: vscode.TextDocument, askFlags
384385
return;
385386
}
386387

387-
return (
388-
importFile(file)
389-
.then(() => {
390-
if (isCompilable(file.name)) compile([file], askFlags);
391-
})
392-
// importFile handles any server errors
393-
.catch(() => {})
394-
);
388+
try {
389+
if (isCompilable(file.name)) {
390+
await importFile(file, true);
391+
compile([file], askFlags);
392+
} else {
393+
await importFile(file, false);
394+
}
395+
} catch (_) {
396+
// importFile handles any server errors
397+
}
395398
}
396399

397400
export async function compileOnly(document?: vscode.TextDocument, askFlags = false): Promise<any> {
@@ -461,28 +464,26 @@ async function importFiles(files: vscode.Uri[], noCompile = false) {
461464
await Promise.allSettled<void>(
462465
files.map((uri) =>
463466
rateLimiter.call(async () => {
464-
return vscode.workspace.fs
465-
.readFile(uri)
466-
.then((contentBytes) =>
467-
currentFileFromContent(
468-
uri,
469-
isText(uri.path.split("/").pop(), Buffer.from(contentBytes))
470-
? new TextDecoder().decode(contentBytes)
471-
: Buffer.from(contentBytes)
472-
)
473-
)
474-
.then((curFile) => {
475-
if (curFile) {
476-
if (typeof curFile.content == "string" && isCompilable(curFile.name)) toCompile.push(curFile);
477-
return importFile(curFile).then(() => outputChannel.appendLine("Imported file: " + curFile.fileName));
478-
}
479-
});
467+
const contentBytes = await vscode.workspace.fs.readFile(uri);
468+
const curFile = currentFileFromContent(
469+
uri,
470+
isText(uri.path.split("/").pop(), Buffer.from(contentBytes))
471+
? new TextDecoder().decode(contentBytes)
472+
: Buffer.from(contentBytes)
473+
);
474+
if (curFile) {
475+
if (typeof curFile.content == "string" && isCompilable(curFile.name)) {
476+
toCompile.push(curFile);
477+
}
478+
await importFile(curFile, !noCompile);
479+
outputChannel.appendLine("Imported file: " + curFile.fileName);
480+
}
480481
})
481482
)
482483
);
483484

484485
if (!noCompile && toCompile.length > 0) {
485-
return compile(toCompile);
486+
await compile(toCompile);
486487
}
487488
return;
488489
}

src/utils/documentIndex.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,14 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
263263
if (change.addedOrChanged) {
264264
// Create or update the document on the server
265265
try {
266-
await importFile(change.addedOrChanged);
266+
const willCompile = vscodeChange && vscode.window.activeTextEditor?.document.uri.toString() == uriString;
267+
await importFile(change.addedOrChanged, willCompile);
267268
outputImport(change.addedOrChanged.name, uri);
268269
if (conf.get("compileOnSave") && isCompilable(change.addedOrChanged.name)) {
269270
// Compile right away if this document is in the active text editor.
270271
// This is needed to avoid noticeable latency when a user is editing
271272
// a client-side file, saves it, and the auto-compile kicks in.
272-
if (vscodeChange && vscode.window.activeTextEditor?.document.uri.toString() == uriString) {
273+
if (willCompile) {
273274
compile([change.addedOrChanged]);
274275
} else {
275276
debouncedCompile(change.addedOrChanged);

0 commit comments

Comments
 (0)