Skip to content

Commit 97e605c

Browse files
committed
fix duplicate PDK terminals
1 parent ae25e13 commit 97e605c

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

src/feature/PDKFeature.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,8 @@ import { PDKCommandStrings } from '../messages';
99
import { reporter } from '../telemetry';
1010

1111
export class PDKFeature implements IFeature {
12-
private terminal: vscode.Terminal;
1312

1413
constructor(context: vscode.ExtensionContext, logger: ILogger) {
15-
const suspendedTerm = vscode.window.terminals.find((tm) => tm.name === 'Puppet PDK');
16-
this.terminal = suspendedTerm === undefined ? vscode.window.createTerminal('Puppet PDK') : suspendedTerm;
17-
18-
this.terminal.processId.then((pid) => {
19-
logger.debug('pdk shell started, pid: ' + pid);
20-
});
21-
context.subscriptions.push(this.terminal);
22-
2314
context.subscriptions.push(
2415
vscode.commands.registerCommand(PDKCommandStrings.PdkNewModuleCommandId, () => {
2516
this.pdkNewModuleCommand();
@@ -34,8 +25,8 @@ export class PDKFeature implements IFeature {
3425
].forEach((command) => {
3526
context.subscriptions.push(
3627
vscode.commands.registerCommand(command.id, () => {
37-
this.terminal.sendText(command.request);
38-
this.terminal.show();
28+
this.getTerminal().sendText(command.request);
29+
this.getTerminal().show();
3930
if (reporter) {
4031
reporter.sendTelemetryEvent(command.id);
4132
}
@@ -63,8 +54,8 @@ export class PDKFeature implements IFeature {
6354
}
6455

6556
const request = `${command.request} ${name}`;
66-
this.terminal.sendText(request);
67-
this.terminal.show();
57+
this.getTerminal().sendText(request);
58+
this.getTerminal().show();
6859
if (reporter) {
6960
reporter.sendTelemetryEvent(command.id);
7061
}
@@ -74,8 +65,13 @@ export class PDKFeature implements IFeature {
7465
});
7566
}
7667

68+
private getTerminal(): vscode.Terminal {
69+
const existingTerm = vscode.window.terminals.find((tm) => tm.name === 'Puppet PDK');
70+
return existingTerm === undefined ? vscode.window.createTerminal('Puppet PDK') : existingTerm;
71+
}
72+
7773
public dispose(): void {
78-
this.terminal.dispose();
74+
this.getTerminal().dispose();
7975
}
8076

8177
private async pdkNewModuleCommand(): Promise<void> {
@@ -99,8 +95,8 @@ export class PDKFeature implements IFeature {
9995

10096
const p = path.join(directory[0].fsPath, name);
10197

102-
this.terminal.sendText(`pdk new module --skip-interview ${name} ${p}`);
103-
this.terminal.show();
98+
this.getTerminal().sendText(`pdk new module --skip-interview ${name} ${p}`);
99+
this.getTerminal().show();
104100

105101
await new Promise<void>((resolve) => {
106102
let count = 0;

0 commit comments

Comments
 (0)