Skip to content

Commit f01b51b

Browse files
committed
Return early if going to useEnvExtension route
1 parent 204c05a commit f01b51b

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

src/client/common/terminal/service.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import {
2020
TerminalShellType,
2121
} from './types';
2222
import { traceVerbose } from '../../logging';
23+
import { useEnvExtension } from '../../envExt/api.internal';
24+
import { ensureTerminalLegacy } from '../../envExt/api.legacy';
2325
import { sleep } from '../utils/async';
2426

2527
@injectable()
@@ -79,7 +81,6 @@ export class TerminalService implements ITerminalService, Disposable {
7981
commandLine: string,
8082
isPythonShell: boolean,
8183
): Promise<TerminalShellExecution | undefined> {
82-
await this.ensureTerminal();
8384
const terminal = this.terminal!;
8485
if (!this.options?.hideFromUser) {
8586
terminal.show(true);
@@ -127,30 +128,34 @@ export class TerminalService implements ITerminalService, Disposable {
127128
}
128129
}
129130
// TODO: Debt switch to Promise<Terminal> ---> breaks 20 tests
130-
// TODO: Properly migrate all creation, ensureTerminal to environment extension.
131131
public async ensureTerminal(preserveFocus: boolean = true): Promise<void> {
132132
if (this.terminal) {
133133
return;
134134
}
135135

136-
// Always use the legacy terminal creation method for now
137-
// The environment extension path can create duplicate terminals
138-
// or show `Cannot read properties of undefined (reading 'show')` error: https://github.com/microsoft/vscode-python-environments/issues/958
139-
this.terminal = this.terminalManager.createTerminal({
140-
name: this.options?.title || 'Python',
141-
hideFromUser: this.options?.hideFromUser,
142-
});
143-
this.terminalShellType = this.terminalHelper.identifyTerminalShell(this.terminal);
144-
this.terminalAutoActivator.disableAutoActivation(this.terminal);
136+
if (useEnvExtension()) {
137+
this.terminal = await ensureTerminalLegacy(this.options?.resource, {
138+
name: this.options?.title || 'Python',
139+
hideFromUser: this.options?.hideFromUser,
140+
});
141+
return;
142+
} else {
143+
this.terminalShellType = this.terminalHelper.identifyTerminalShell(this.terminal);
144+
this.terminal = this.terminalManager.createTerminal({
145+
name: this.options?.title || 'Python',
146+
hideFromUser: this.options?.hideFromUser,
147+
});
148+
this.terminalAutoActivator.disableAutoActivation(this.terminal);
145149

146-
await sleep(100);
150+
await sleep(100);
147151

148-
await this.terminalActivator.activateEnvironmentInTerminal(this.terminal, {
149-
resource: this.options?.resource,
150-
preserveFocus,
151-
interpreter: this.options?.interpreter,
152-
hideFromUser: this.options?.hideFromUser,
153-
});
152+
await this.terminalActivator.activateEnvironmentInTerminal(this.terminal, {
153+
resource: this.options?.resource,
154+
preserveFocus,
155+
interpreter: this.options?.interpreter,
156+
hideFromUser: this.options?.hideFromUser,
157+
});
158+
}
154159

155160
if (!this.options?.hideFromUser) {
156161
this.terminal.show(preserveFocus);

0 commit comments

Comments
 (0)