Skip to content

Commit 59a3116

Browse files
committed
remove unncessary exitcode promise
1 parent c896ce7 commit 59a3116

File tree

3 files changed

+16
-42
lines changed

3 files changed

+16
-42
lines changed

src/client/common/terminal/service.ts

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT License.
33

44
import { inject, injectable } from 'inversify';
5-
import { CancellationToken, Disposable, Event, EventEmitter, Terminal } from 'vscode';
5+
import { CancellationToken, Disposable, Event, EventEmitter, Terminal, TerminalShellExecution } from 'vscode';
66
import '../../common/extensions';
77
import { IInterpreterService } from '../../interpreter/contracts';
88
import { IServiceContainer } from '../../ioc/types';
@@ -18,7 +18,6 @@ import {
1818
ITerminalService,
1919
TerminalCreationOptions,
2020
TerminalShellType,
21-
ITerminalExecutedCommand,
2221
} from './types';
2322
import { traceVerbose } from '../../logging';
2423

@@ -35,6 +34,8 @@ export class TerminalService implements ITerminalService, Disposable {
3534
public get onDidCloseTerminal(): Event<void> {
3635
return this.terminalClosed.event.bind(this.terminalClosed);
3736
}
37+
38+
// private _shellIntegrationEnabled
3839
constructor(
3940
@inject(IServiceContainer) private serviceContainer: IServiceContainer,
4041
private readonly options?: TerminalCreationOptions,
@@ -73,7 +74,7 @@ export class TerminalService implements ITerminalService, Disposable {
7374
}
7475
this.terminal!.sendText(text);
7576
}
76-
public async executeCommand(commandLine: string): Promise<ITerminalExecutedCommand | undefined> {
77+
public async executeCommand(commandLine: string): Promise<TerminalShellExecution | undefined> {
7778
const terminal = this.terminal!;
7879
if (!this.options?.hideFromUser) {
7980
terminal.show(true);
@@ -82,15 +83,14 @@ export class TerminalService implements ITerminalService, Disposable {
8283
// If terminal was just launched, wait some time for shell integration to onDidChangeShellIntegration.
8384
if (!terminal.shellIntegration) {
8485
const promise = new Promise<boolean>((resolve) => {
85-
const shellIntegrationChangeEventListener = this.terminalManager.onDidChangeTerminalShellIntegration(
86-
() => {
87-
this.executeCommandListeners.delete(shellIntegrationChangeEventListener);
88-
resolve(true);
89-
},
90-
);
86+
const disposable = this.terminalManager.onDidChangeTerminalShellIntegration(() => {
87+
clearTimeout(timer); //racetimeout
88+
disposable.dispose();
89+
resolve(true);
90+
});
9191
const TIMEOUT_DURATION = 500;
92-
setTimeout(() => {
93-
this.executeCommandListeners.add(shellIntegrationChangeEventListener);
92+
const timer = setTimeout(() => {
93+
disposable.dispose();
9494
resolve(true);
9595
}, TIMEOUT_DURATION);
9696
});
@@ -101,28 +101,7 @@ export class TerminalService implements ITerminalService, Disposable {
101101
// TODO: executeCommand would not execute command manually typed inside Python Terminal REPL.
102102
// We only run executeCommand when user shift+enter in .py file, and hence run command in terminal on user's behalf.
103103
const execution = terminal.shellIntegration.executeCommand(commandLine);
104-
traceVerbose(`Shell Integration is enabled, executeCommand: ${commandLine}`);
105-
// exitCode as promise for the case:
106-
// In the case where SI is enabled in zsh/pwsh in Windows but not inside Python REPL so Python command won't finish until user exit()
107-
// This means OnDidEndTerminalShellExecution would not fire inside REPL launched once REPL is launched for above case.
108-
109-
return {
110-
execution,
111-
exitCode: new Promise((resolve) => {
112-
const listener = this.terminalManager.onDidEndTerminalShellExecution((e) => {
113-
if (e.execution === execution) {
114-
this.executeCommandListeners.delete(listener);
115-
resolve(e.exitCode);
116-
traceVerbose(
117-
`onDidEndTerminalShellExecution handler is called: Shell Integration exitCode: ${e.exitCode}`,
118-
);
119-
}
120-
});
121-
if (listener) {
122-
this.executeCommandListeners.add(listener);
123-
}
124-
}),
125-
};
104+
return execution;
126105
} else {
127106
terminal.sendText(commandLine);
128107
traceVerbose(`Shell Integration is disabled, sendText: ${commandLine}`);

src/client/common/terminal/syncTerminalService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
'use strict';
55

66
import { inject } from 'inversify';
7-
import { CancellationToken, Disposable, Event } from 'vscode';
7+
import { CancellationToken, Disposable, Event, TerminalShellExecution } from 'vscode';
88
import { IInterpreterService } from '../../interpreter/contracts';
99
import { traceVerbose } from '../../logging';
1010
import { PythonEnvironment } from '../../pythonEnvironments/info';
@@ -14,7 +14,7 @@ import * as internalScripts from '../process/internal/scripts';
1414
import { createDeferred, Deferred } from '../utils/async';
1515
import { noop } from '../utils/misc';
1616
import { TerminalService } from './service';
17-
import { ITerminalService, ITerminalExecutedCommand } from './types';
17+
import { ITerminalService } from './types';
1818

1919
enum State {
2020
notStarted = 0,
@@ -145,7 +145,7 @@ export class SynchronousTerminalService implements ITerminalService, Disposable
145145
public sendText(text: string): Promise<void> {
146146
return this.terminalService.sendText(text);
147147
}
148-
public executeCommand(commandLine: string): Promise<ITerminalExecutedCommand | undefined> {
148+
public executeCommand(commandLine: string): Promise<TerminalShellExecution | undefined> {
149149
return this.terminalService.executeCommand(commandLine);
150150
}
151151
public show(preserveFocus?: boolean | undefined): Promise<void> {

src/client/common/terminal/types.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,10 @@ export interface ITerminalService extends IDisposable {
5454
): Promise<void>;
5555
/** @deprecated */
5656
sendText(text: string): Promise<void>;
57-
executeCommand(commandLine: string): Promise<ITerminalExecutedCommand | undefined>;
57+
executeCommand(commandLine: string): Promise<TerminalShellExecution | undefined>;
5858
show(preserveFocus?: boolean): Promise<void>;
5959
}
6060

61-
export interface ITerminalExecutedCommand {
62-
execution: TerminalShellExecution;
63-
exitCode: Promise<number | undefined>;
64-
}
65-
6661
export const ITerminalServiceFactory = Symbol('ITerminalServiceFactory');
6762

6863
export type TerminalCreationOptions = {

0 commit comments

Comments
 (0)