diff --git a/!Build.ps1 b/!Build.ps1 new file mode 100644 index 0000000..5cf93af --- /dev/null +++ b/!Build.ps1 @@ -0,0 +1,18 @@ +tsc --build --verbose + +vsce package --allow-missing-repository --allow-star-activation +Write-Host + +$name = Get-ChildItem -Name -File -Filter *.vsix | Select-Object -First 1 +Invoke-Expression "code --force --install-extension $name" +Write-Host + +Write-Host "AHK" +RunAhk.ps1 @' +WinActivate "ahk_exe Code.exe" +WinWaitActive "ahk_exe Code.exe" +Send "^!+r" +'@ +Write-Host + +PressEnterToContinue.ps1 diff --git a/.gitignore b/.gitignore index 2ec91bc..547b5da 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ npm-debug.log out node_modules -*.vsix \ No newline at end of file +*.vsix +!Build.ps1 diff --git a/package.json b/package.json index 075781c..b95a218 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,11 @@ "command": "code-runner.stop", "title": "Stop Code Run", "icon": "$(debug-stop)" + }, + { + "command": "code-runner.stopWait", + "title": "Stop Code Run and wait for it to exit", + "icon": "$(debug-stop)" } ], "keybindings": [ diff --git a/src/codeManager.ts b/src/codeManager.ts index 3de6e2e..af524bf 100644 --- a/src/codeManager.ts +++ b/src/codeManager.ts @@ -25,6 +25,7 @@ export class CodeManager implements vscode.Disposable { private _config: vscode.WorkspaceConfiguration; private _appInsightsClient: AppInsightsClient; private _TERMINAL_DEFAULT_SHELL_WINDOWS: string | null = null; + private _closePromise: Promise = null; constructor() { this._outputChannel = vscode.window.createOutputChannel("Code"); @@ -103,9 +104,9 @@ export class CodeManager implements vscode.Disposable { }); } - public stop(): void { + public stop(): Promise { this._appInsightsClient.sendEvent("stop"); - this.stopRunning(); + return this.stopRunning(); } public dispose() { @@ -132,6 +133,7 @@ export class CodeManager implements vscode.Disposable { vscode.commands.executeCommand("setContext", "code-runner.codeRunning", false); const kill = require("tree-kill"); kill(this._process.pid); + return this._closePromise; } } @@ -471,7 +473,10 @@ export class CodeManager implements vscode.Disposable { this._outputChannel.appendLine("[Running] " + command); } this.sendRunEvent(executor, false); - const startTime = new Date(); + let resolveClosePromise; + this._closePromise = new Promise(resolve => (resolveClosePromise = resolve)); + const { performance } = require('node:perf_hooks'); + const startTime = performance.now(); this._process = spawn(command, [], { cwd: this._cwd, shell: true }); this._process.stdout.on("data", (data) => { @@ -485,16 +490,17 @@ export class CodeManager implements vscode.Disposable { this._process.on("close", (code) => { this._isRunning = false; vscode.commands.executeCommand("setContext", "code-runner.codeRunning", false); - const endTime = new Date(); - const elapsedTime = (endTime.getTime() - startTime.getTime()) / 1000; + const endTime = performance.now(); + const elapsedTime = (endTime - startTime) / 1000; this._outputChannel.appendLine(""); if (showExecutionMessage) { - this._outputChannel.appendLine("[Done] exited with code=" + code + " in " + elapsedTime + " seconds"); + this._outputChannel.appendLine("[Done] exited with code=" + code + " in " + elapsedTime.toFixed(3) + " seconds"); this._outputChannel.appendLine(""); } if (this._isTmpFile) { fs.unlinkSync(this._codeFile); } + resolveClosePromise(); }); } diff --git a/src/extension.ts b/src/extension.ts index 7c38f10..efb77a5 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -26,10 +26,15 @@ export function activate(context: vscode.ExtensionContext) { codeManager.stop(); }); + const stopWait = vscode.commands.registerCommand("code-runner.stopWait", () => { + return codeManager.stop(); + }); + context.subscriptions.push(run); context.subscriptions.push(runCustomCommand); context.subscriptions.push(runByLanguage); context.subscriptions.push(stop); + context.subscriptions.push(stopWait); context.subscriptions.push(codeManager); }