Skip to content

Commit edb91ba

Browse files
committed
try different way in service,ts
1 parent 6b4b097 commit edb91ba

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

src/client/common/terminal/service.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,24 +100,38 @@ export class TerminalService implements ITerminalService, Disposable {
100100
if (terminal.shellIntegration) {
101101
const execution = terminal.shellIntegration.executeCommand(commandLine);
102102

103-
let result = undefined;
104-
let disposable: Disposable | undefined;
105-
try {
106-
result = await new Promise<ITerminalExecutedCommand>((resolve) => {
107-
disposable = this.terminalManager.onDidEndTerminalShellExecution((e) => {
103+
// let result = undefined;
104+
// let disposable: Disposable | undefined;
105+
// try {
106+
// result = await new Promise<ITerminalExecutedCommand>((resolve) => {
107+
// disposable = this.terminalManager.onDidEndTerminalShellExecution((e) => {
108+
// if (e.execution === execution) {
109+
// resolve({ execution, exitCode: e.exitCode });
110+
// console.log('Resolving inside onDidEndTerminalShellExecution');
111+
// }
112+
// });
113+
114+
// traceVerbose(`Shell Integration is enabled, executeCommand: ${commandLine}`);
115+
// });
116+
// return result;
117+
// } catch {
118+
// } finally {
119+
// disposable?.dispose();
120+
// }
121+
return {
122+
execution,
123+
exitCode: new Promise((resolve) => {
124+
const listener = this.terminalManager.onDidEndTerminalShellExecution((e) => {
108125
if (e.execution === execution) {
109-
resolve({ execution, exitCode: e.exitCode });
110-
console.log('Resolving inside onDidEndTerminalShellExecution');
126+
this.executeCommandListeners.delete(listener);
127+
resolve(e.exitCode);
111128
}
112129
});
113-
114-
traceVerbose(`Shell Integration is enabled, executeCommand: ${commandLine}`);
115-
});
116-
return result;
117-
} catch {
118-
} finally {
119-
disposable?.dispose();
120-
}
130+
if (listener) {
131+
this.executeCommandListeners.add(listener);
132+
}
133+
}),
134+
};
121135
} else {
122136
terminal.sendText(commandLine);
123137
traceVerbose(`Shell Integration is disabled, sendText: ${commandLine}`);

src/client/common/terminal/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export interface ITerminalService extends IDisposable {
6060

6161
export interface ITerminalExecutedCommand {
6262
execution: TerminalShellExecution;
63-
exitCode: number | undefined;
63+
exitCode: Promise<number | undefined>;
6464
}
6565

6666
export const ITerminalServiceFactory = Symbol('ITerminalServiceFactory');

0 commit comments

Comments
 (0)