This repository was archived by the owner on Nov 25, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed
Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import ZigDiagnosticsProvider from "./zigDiagnosticsProvider";
55import ZigMainCodeLensProvider from "./zigMainCodeLens" ;
66import ZigTestRunnerProvider from "./zigTestRunnerProvider" ;
77import { registerDocumentFormatting } from "./zigFormat" ;
8+ import { registerTerminalStateManagement } from "./terminalState" ;
89import { setupZig } from "./zigSetup" ;
910
1011export async function activate ( context : vscode . ExtensionContext ) {
@@ -17,6 +18,7 @@ export async function activate(context: vscode.ExtensionContext) {
1718 const testRunner = new ZigTestRunnerProvider ( ) ;
1819 testRunner . activate ( context . subscriptions ) ;
1920
21+ registerTerminalStateManagement ( ) ;
2022 ZigMainCodeLensProvider . registerCommands ( context ) ;
2123 context . subscriptions . push (
2224 vscode . languages . registerCodeLensProvider (
Original file line number Diff line number Diff line change 1+ /**
2+ * A status monitor for a VSCode terminal.
3+ */
4+
5+ import vscode from "vscode" ;
6+
7+ const terminalsState = new Map < vscode . Terminal , boolean > ( ) ;
8+
9+ export function getTerminalState ( terminal : vscode . Terminal ) : boolean | undefined {
10+ return terminalsState . get ( terminal ) ;
11+ }
12+
13+ export function registerTerminalStateManagement ( ) : void {
14+ vscode . window . onDidOpenTerminal ( ( terminal ) => {
15+ terminalsState . set ( terminal , false ) ;
16+ } ) ;
17+ vscode . window . onDidStartTerminalShellExecution ( ( event ) => {
18+ terminalsState . set ( event . terminal , true ) ;
19+ } ) ;
20+ vscode . window . onDidEndTerminalShellExecution ( ( event ) => {
21+ terminalsState . set ( event . terminal , false ) ;
22+ } ) ;
23+ vscode . window . onDidCloseTerminal ( ( terminal ) => {
24+ terminalsState . delete ( terminal ) ;
25+ } ) ;
26+ }
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import path from "path";
66import util from "util" ;
77
88import { getWorkspaceFolder , isWorkspaceFile } from "./zigUtil" ;
9+ import { getTerminalState } from "./terminalState" ;
910import { zigProvider } from "./zigSetup" ;
1011
1112const execFile = util . promisify ( childProcess . execFile ) ;
@@ -43,7 +44,9 @@ function zigRun() {
4344 const zigPath = zigProvider . getZigPath ( ) ;
4445 if ( ! zigPath ) return ;
4546 const filePath = vscode . window . activeTextEditor . document . uri . fsPath ;
46- const terminal = vscode . window . createTerminal ( "Run Zig Program" ) ;
47+ const terminalName = "Run Zig Program" ;
48+ const terminals = vscode . window . terminals . filter ( ( t ) => t . name === terminalName && getTerminalState ( t ) === false ) ;
49+ const terminal = terminals . length > 0 ? terminals [ 0 ] : vscode . window . createTerminal ( terminalName ) ;
4750 const callOperator = / ( p o w e r s h e l l .e x e $ | p o w e r s h e l l $ | p w s h .e x e $ | p w s h $ ) / . test ( vscode . env . shell ) ? "& " : "" ;
4851 terminal . show ( ) ;
4952 const wsFolder = getWorkspaceFolder ( filePath ) ;
You can’t perform that action at this time.
0 commit comments