Skip to content
Open
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
18 changes: 18 additions & 0 deletions !Build.ps1
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
npm-debug.log
out
node_modules
*.vsix
*.vsix
!Build.ps1
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
18 changes: 12 additions & 6 deletions src/codeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> = null;

constructor() {
this._outputChannel = vscode.window.createOutputChannel("Code");
Expand Down Expand Up @@ -103,9 +104,9 @@ export class CodeManager implements vscode.Disposable {
});
}

public stop(): void {
public stop(): Promise<void> {
this._appInsightsClient.sendEvent("stop");
this.stopRunning();
return this.stopRunning();
}

public dispose() {
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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<void>(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) => {
Expand All @@ -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();
});
}

Expand Down
5 changes: 5 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down