Skip to content

Commit c781460

Browse files
authored
Skip compilation of web app files that do not require it (#1660)
1 parent 3d1fc38 commit c781460

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

src/commands/compile.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
handleError,
2727
isClassDeployed,
2828
isClassOrRtn,
29+
isCompilable,
2930
lastUsedLocalUri,
3031
notIsfs,
3132
notNull,
@@ -333,7 +334,7 @@ export async function importAndCompile(
333334
throw error;
334335
})
335336
.then(() => {
336-
if (compileFile) compile([file], flags);
337+
if (compileFile && isCompilable(file.name)) compile([file], flags);
337338
});
338339
}
339340

@@ -369,7 +370,7 @@ export async function compileOnly(askFlags = false, document?: vscode.TextDocume
369370

370371
const defaultFlags = config().compileFlags;
371372
const flags = askFlags ? await compileFlags() : defaultFlags;
372-
if (!file.fileName.startsWith("\\.vscode\\")) {
373+
if (isCompilable(file.name)) {
373374
compile([file], flags);
374375
}
375376
}
@@ -444,7 +445,7 @@ async function importFiles(files: vscode.Uri[], noCompile = false) {
444445
)
445446
.then((curFile) => {
446447
if (curFile) {
447-
if (typeof curFile.content == "string") toCompile.push(curFile); // Only compile text files
448+
if (typeof curFile.content == "string" && isCompilable(curFile.name)) toCompile.push(curFile);
448449
return importFile(curFile).then(() => outputChannel.appendLine("Imported file: " + curFile.fileName));
449450
}
450451
});

src/providers/FileSystemProvider/FileSystemProvider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
base64EncodeContent,
1818
openLowCodeEditors,
1919
compileErrorMsg,
20+
isCompilable,
2021
} from "../../utils";
2122
import { FILESYSTEM_READONLY_SCHEMA, FILESYSTEM_SCHEMA, intLangId, macLangId } from "../../extension";
2223
import { addIsfsFileToProject, modifyProject } from "../../commands/project";
@@ -578,7 +579,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
578579
if (!entry) return; // entry is only empty when uri is open in a low-code editor
579580
// Compile the document if required
580581
if (
581-
!uri.path.includes("/_vscode/") &&
582+
isCompilable(entry.fileName) &&
582583
vscode.workspace.getConfiguration("objectscript", uri).get("compileOnSave")
583584
) {
584585
// Need to return the compile promise because technically the post-save compilation

src/utils/documentIndex.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
openLowCodeEditors,
1313
outputChannel,
1414
displayableUri,
15+
isCompilable,
1516
} from ".";
1617
import { isText } from "istextorbinary";
1718
import { AtelierAPI } from "../api";
@@ -266,7 +267,7 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
266267
importFile(change.addedOrChanged)
267268
.then(() => {
268269
outputImport(change.addedOrChanged.name, uri);
269-
if (conf.get("compileOnSave")) {
270+
if (conf.get("compileOnSave") && isCompilable(change.addedOrChanged.name)) {
270271
// Compile right away if this document is in the active text editor.
271272
// This is needed to avoid noticeable latency when a user is editing
272273
// a client-side file, saves it, and the auto-compile kicks in.

src/utils/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,12 @@ export function displayableUri(uri: vscode.Uri): string {
10351035
return uri.scheme == "file" ? uri.fsPath : uri.toString(true);
10361036
}
10371037

1038+
/** Return `true` if document `name` can be compiled */
1039+
export function isCompilable(name: string): boolean {
1040+
// Exlcude web app files that are not CSP or CSR files
1041+
return !(name.includes("/") && !["csp", "csr"].includes(name.split(".").pop().toLowerCase()));
1042+
}
1043+
10381044
class Semaphore {
10391045
/** Queue of tasks waiting to acquire the semaphore */
10401046
private _tasks: (() => void)[] = [];

0 commit comments

Comments
 (0)