Skip to content

Commit 0d0dd87

Browse files
committed
Add warning when compiling a file which isn't in the working directory. Fixes #24
1 parent 5b30818 commit 0d0dd87

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/compiler/compiler-base.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { isWhitespace } from "@sourcelib/kv/";
33
import * as main from "../main";
44
import * as fs from "fs";
55
import { execFile } from "child_process";
6+
import path from "path";
67

78
export interface CompileSettings {
89
editor: vscode.TextEditor;
@@ -25,9 +26,13 @@ export async function compileSomething(settings: CompileSettings): Promise<void>
2526
vscode.window.showErrorMessage("The current document is not a file. Cannot compile. Honestly, I have no idea how this is possible, so if you can into this, please message me.");
2627
return;
2728
}
28-
const filePath = fileUri.fsPath;
29-
const workDir: string = main.config.get(`${settings.configPrefix}.workingDirectory`) ?? vscode.Uri.joinPath(fileUri, "..").fsPath;
30-
29+
let filePath = fileUri.fsPath;
30+
let workDir: string = main.config.get(`${settings.configPrefix}.workingDirectory`) ?? vscode.Uri.joinPath(fileUri, "..").fsPath;
31+
32+
if(process.platform === "win32") {
33+
filePath = filePath.toLowerCase();
34+
workDir = workDir.toLowerCase();
35+
}
3136
if( exePath == null || isWhitespace(exePath) ) {
3237
vscode.window.showErrorMessage(`${settings.compilerName} path is empty. Please configure!`);
3338
return;
@@ -42,14 +47,18 @@ export async function compileSomething(settings: CompileSettings): Promise<void>
4247

4348
channel.clear();
4449
channel.appendLine(`Running ${settings.compilerName} for ${filePath}`);
50+
51+
if(!filePath.startsWith(workDir)) {
52+
channel.appendLine("WARNING: The file is not in the compiler's working directory. The compiler may not be able to find the file.");
53+
}
4554

4655
if(shouldOpenOutputWindow) {
4756
channel.show();
4857
}
4958

5059
// Start process ----------------
5160
params.push(filePath);
52-
const process = execFile(exePath, params, {
61+
const proc = execFile(exePath, params, {
5362
cwd: workDir
5463
}, (error, stdout, stderr) => {
5564
if(error) {
@@ -66,15 +75,15 @@ export async function compileSomething(settings: CompileSettings): Promise<void>
6675
}, (progress, token) => {
6776

6877
token.onCancellationRequested(e => {
69-
process.kill();
78+
proc.kill();
7079
channel.appendLine("Cancelled compilation process");
7180
});
7281

7382
progress.report({ message: "Compiling", increment: 0});
7483

7584
const promise = new Promise<void>(resolve => {
7685

77-
process.on("exit", (exitCode: number) => {
86+
proc.on("exit", (exitCode: number) => {
7887
if(exitCode === 0) {
7988
channel.appendLine("Completed successfully!");
8089
} else {

0 commit comments

Comments
 (0)