Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 🎸 Add support for custom output location #265

Merged
merged 1 commit into from
Oct 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@
"default": true,
"description": "Whether should show notifications",
"scope": "resource"
},
"c-cpp-compile-run.output-location": {
"type": "string",
"description": "Where output file should be located",
"scope": "resource"
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { commandExists, isProccessRunning } from "./utils/common-utils";
import { Result } from "./enums/result";
import { isStringNullOrWhiteSpace } from "./utils/string-utils";
import { Notification } from "./notification";
import path = require("path");

export class Compiler {
private file: File;
Expand Down Expand Up @@ -50,7 +51,15 @@ export class Compiler {
}
}

let compilerArgs = [`"${this.file.name}"`, "-o", `"${this.file.executable}"`];
let compilerArgs;

let outputLocation = Configuration.outputLocation();
if (outputLocation) {
compilerArgs = [`"${this.file.name}"`, "-o", `"${outputLocation}${path.sep}${this.file.executable}"`];
} else {
compilerArgs = [`"${this.file.name}"`, "-o", `"${this.file.executable}"`];
}

if (this.inputFlags) {
compilerArgs = compilerArgs.concat(this.inputFlags.split(" "));
}
Expand Down
4 changes: 4 additions & 0 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export class Configuration {
return this.getSetting<boolean>("should-show-notifications") ?? true;
}

static outputLocation(): string {
return this.getSetting<string>("output-location")?.trim();;
}

static defaultWindowsShell(): string {
return workspace.getConfiguration("terminal").get<string>("integrated.shell.windows")?.trim();
}
Expand Down
9 changes: 7 additions & 2 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,22 @@ export class Runner {
this.arguments = await promptRunArguments(this.arguments);
}

let outputLocation = Configuration.outputLocation();
if (!outputLocation) {
outputLocation = this.file.directory;
}

if (shouldRunInExternalTerminal) {
const command = await this.getExternalCommand();
if (isStringNullOrWhiteSpace(command)) {
return Result.error;
}

exec(command, { cwd: this.file.directory });
exec(command, { cwd: outputLocation });
}
else {
await terminal.runInTerminal(`${getRunPrefix()}"${this.file.executable}" ${this.arguments}`,
{ name: "C/C++ Compile Run", cwd: this.file.directory });
{ name: "C/C++ Compile Run", cwd: outputLocation });
}

return Result.success;
Expand Down