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";
5
5
import ZigMainCodeLensProvider from "./zigMainCodeLens" ;
6
6
import ZigTestRunnerProvider from "./zigTestRunnerProvider" ;
7
7
import { registerDocumentFormatting } from "./zigFormat" ;
8
+ import { registerTerminalStateManagement } from "./terminalState" ;
8
9
import { setupZig } from "./zigSetup" ;
9
10
10
11
export async function activate ( context : vscode . ExtensionContext ) {
@@ -17,6 +18,7 @@ export async function activate(context: vscode.ExtensionContext) {
17
18
const testRunner = new ZigTestRunnerProvider ( ) ;
18
19
testRunner . activate ( context . subscriptions ) ;
19
20
21
+ registerTerminalStateManagement ( ) ;
20
22
ZigMainCodeLensProvider . registerCommands ( context ) ;
21
23
context . subscriptions . push (
22
24
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";
6
6
import util from "util" ;
7
7
8
8
import { getWorkspaceFolder , isWorkspaceFile } from "./zigUtil" ;
9
+ import { getTerminalState } from "./terminalState" ;
9
10
import { zigProvider } from "./zigSetup" ;
10
11
11
12
const execFile = util . promisify ( childProcess . execFile ) ;
@@ -43,7 +44,9 @@ function zigRun() {
43
44
const zigPath = zigProvider . getZigPath ( ) ;
44
45
if ( ! zigPath ) return ;
45
46
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 ) ;
47
50
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 ) ? "& " : "" ;
48
51
terminal . show ( ) ;
49
52
const wsFolder = getWorkspaceFolder ( filePath ) ;
You can’t perform that action at this time.
0 commit comments