diff --git a/package.json b/package.json index 2995be0..b28304f 100644 --- a/package.json +++ b/package.json @@ -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" } } } diff --git a/src/compiler.ts b/src/compiler.ts index c877201..a479191 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -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; @@ -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(" ")); } diff --git a/src/configuration.ts b/src/configuration.ts index 7b69ec8..aff428a 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -38,6 +38,10 @@ export class Configuration { return this.getSetting("should-show-notifications") ?? true; } + static outputLocation(): string { + return this.getSetting("output-location")?.trim();; + } + static defaultWindowsShell(): string { return workspace.getConfiguration("terminal").get("integrated.shell.windows")?.trim(); } diff --git a/src/runner.ts b/src/runner.ts index 62fe833..00b389d 100644 --- a/src/runner.ts +++ b/src/runner.ts @@ -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;