Skip to content
Closed
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
30 changes: 28 additions & 2 deletions src/compilerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ export class CompilerService {

const extraArgs = cfg.get<string[]>('compilerArgs', []);
const outputFile = this.getOutputPath(filePath);
const args: string[] = [filePath, '--exe', outputFile, ...extraArgs];
if (run) { args.push('--run'); }
// The Windows compilers (pbcompiler.exe / pbcompilerc.exe) use "/EXE",
// while Linux/macOS take "-o" (documented as "--output"). "--executable" is
// an undocumented alias that happens to work on 6.41, so it is not used
// here. Neither has a "run" switch, so the executable is launched
// separately after a successful compile.
const exeSwitch = process.platform === 'win32' ? '/EXE' : '-o';
const args: string[] = [filePath, exeSwitch, outputFile, ...extraArgs];

this.outputChannel.clear();
this.outputChannel.show(true);
Expand Down Expand Up @@ -91,6 +96,7 @@ export class CompilerService {
if (code === 0) {
this.outputChannel.appendLine(`\n✅ Compilation successful → ${outputFile}`);
vscode.window.setStatusBarMessage('PureBasic: Compiled successfully ✅', 5000);
if (run) { this.runExecutable(outputFile); }
} else {
this.outputChannel.appendLine(`\n❌ Compilation failed (exit code ${code})`);
vscode.window.setStatusBarMessage('PureBasic: Compilation failed ❌', 5000);
Expand All @@ -108,6 +114,24 @@ export class CompilerService {
);
}

private runExecutable(exePath: string): void {
this.outputChannel.appendLine(`\n▶ Running: ${path.basename(exePath)}\n`);

const proc = cp.spawn(exePath, [], { cwd: path.dirname(exePath) });

proc.stdout?.on('data', (data: Buffer) => this.outputChannel.append(data.toString()));
proc.stderr?.on('data', (data: Buffer) => this.outputChannel.append(data.toString()));

proc.on('close', (code) => {
this.outputChannel.appendLine(`\n■ Program exited (exit code ${code})`);
});

proc.on('error', (err) => {
this.outputChannel.appendLine(`\n❌ Failed to run program: ${err.message}`);
vscode.window.showErrorMessage(`PureBasic: failed to run program: ${err.message}`);
});
}

private parseCompilerOutput(
text: string,
diags: Map<string, vscode.Diagnostic[]>,
Expand Down Expand Up @@ -171,6 +195,8 @@ export class CompilerService {
candidates.push(
'C:\\Program Files\\PureBasic\\Compilers\\pbcompiler.exe',
'C:\\Program Files (x86)\\PureBasic\\Compilers\\pbcompiler.exe',
'C:\\Program Files\\PureBasic\\Compilers\\pbcompilerc.exe',
'C:\\Program Files (x86)\\PureBasic\\Compilers\\pbcompilerc.exe',
);
} else if (process.platform === 'darwin') {
candidates.push(
Expand Down
Loading