Skip to content

Commit 700715e

Browse files
committed
Do not execute when terminal is not ready
1 parent f4cc2dd commit 700715e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/client/common/terminal/service.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import {
2020
TerminalShellType,
2121
} from './types';
2222
import { traceVerbose } from '../../logging';
23+
import { sleep } from '../utils/async';
2324
import { useEnvExtension } from '../../envExt/api.internal';
2425
import { ensureTerminalLegacy } from '../../envExt/api.legacy';
25-
import { sleep } from '../utils/async';
2626

2727
@injectable()
2828
export class TerminalService implements ITerminalService, Disposable {
@@ -81,7 +81,14 @@ export class TerminalService implements ITerminalService, Disposable {
8181
commandLine: string,
8282
isPythonShell: boolean,
8383
): Promise<TerminalShellExecution | undefined> {
84-
const terminal = this.terminal!;
84+
// TODO: First execution of shift+enter may get ignored when using sendText.
85+
// Prevent Cannot read properties of undefined: https://github.com/microsoft/vscode-python-environments/issues/958
86+
if (!this.terminal) {
87+
traceVerbose('Terminal not available yet, cannot execute command');
88+
return undefined;
89+
}
90+
91+
const terminal = this.terminal;
8592
if (!this.options?.hideFromUser) {
8693
terminal.show(true);
8794
}
@@ -128,6 +135,7 @@ export class TerminalService implements ITerminalService, Disposable {
128135
}
129136
}
130137
// TODO: Debt switch to Promise<Terminal> ---> breaks 20 tests
138+
// TODO: Properly migrate all creation, ensureTerminal to environment extension.
131139
public async ensureTerminal(preserveFocus: boolean = true): Promise<void> {
132140
if (this.terminal) {
133141
return;
@@ -138,7 +146,6 @@ export class TerminalService implements ITerminalService, Disposable {
138146
name: this.options?.title || 'Python',
139147
hideFromUser: this.options?.hideFromUser,
140148
});
141-
// Return early to prevent duplicate creation of terminal when using env extension.
142149
return;
143150
} else {
144151
this.terminalShellType = this.terminalHelper.identifyTerminalShell(this.terminal);

0 commit comments

Comments
 (0)