diff --git a/src/compilerService.ts b/src/compilerService.ts index fbaf085..35bc7c2 100644 --- a/src/compilerService.ts +++ b/src/compilerService.ts @@ -32,8 +32,13 @@ export class CompilerService { const extraArgs = cfg.get('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); @@ -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); @@ -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, @@ -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(