mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 02:58:56 +01:00
@@ -312,6 +312,7 @@ export abstract class ExtHostQuickOpenShape {
|
||||
|
||||
export abstract class ExtHostTerminalServiceShape {
|
||||
$acceptTerminalClosed(id: number): void { throw ni(); }
|
||||
$acceptTerminalProcessId(id: number, processId: number): void { throw ni(); }
|
||||
}
|
||||
|
||||
// --- proxy identifiers
|
||||
|
||||
@@ -13,6 +13,7 @@ export class ExtHostTerminal implements vscode.Terminal {
|
||||
|
||||
private _name: string;
|
||||
private _id: number;
|
||||
private _processId: number;
|
||||
private _proxy: MainThreadTerminalServiceShape;
|
||||
private _disposed: boolean;
|
||||
private _queuedRequests: ApiRequest[];
|
||||
@@ -34,6 +35,16 @@ export class ExtHostTerminal implements vscode.Terminal {
|
||||
return this._name;
|
||||
}
|
||||
|
||||
public get processId(): Thenable<number> {
|
||||
this._checkDisposed();
|
||||
if (this._processId) {
|
||||
return Promise.resolve<number>(this._processId);
|
||||
}
|
||||
setTimeout(() => {
|
||||
return this.processId;
|
||||
}, 200);
|
||||
}
|
||||
|
||||
public sendText(text: string, addNewLine: boolean = true): void {
|
||||
this._checkDisposed();
|
||||
this._queueApiRequest(this._proxy.$sendText, [text, addNewLine]);
|
||||
@@ -56,6 +67,10 @@ export class ExtHostTerminal implements vscode.Terminal {
|
||||
}
|
||||
}
|
||||
|
||||
public setProcessId(processId: number): void {
|
||||
this._processId = processId;
|
||||
}
|
||||
|
||||
private _queueApiRequest(callback: (...args: any[]) => void, args: any[]) {
|
||||
let request: ApiRequest = new ApiRequest(callback, args);
|
||||
if (!this._id) {
|
||||
@@ -104,6 +119,16 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape {
|
||||
this._onDidCloseTerminal.fire(terminal);
|
||||
}
|
||||
|
||||
public $acceptTerminalProcessId(id: number, processId: number): void {
|
||||
let terminal = this._getTerminalById(id);
|
||||
terminal.setProcessId(processId);
|
||||
}
|
||||
|
||||
private _getTerminalById(id: number): ExtHostTerminal {
|
||||
let index = this._getTerminalIndexById(id);
|
||||
return index !== null ? this._terminals[index] : null;
|
||||
}
|
||||
|
||||
private _getTerminalIndexById(id: number): number {
|
||||
let index: number = null;
|
||||
this._terminals.some((terminal, i) => {
|
||||
@@ -118,6 +143,7 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape {
|
||||
}
|
||||
|
||||
class ApiRequest {
|
||||
|
||||
private _callback: (...args: any[]) => void;
|
||||
private _args: any[];
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ export class MainThreadTerminalService extends MainThreadTerminalServiceShape {
|
||||
this._proxy = threadService.get(ExtHostContext.ExtHostTerminalService);
|
||||
this._toDispose = [];
|
||||
this._toDispose.push(terminalService.onInstanceDisposed((terminalInstance) => this._onTerminalDisposed(terminalInstance)));
|
||||
this._toDispose.push(terminalService.onInstanceProcessIdReady((terminalInstance) => this._onTerminalProcessIdReady(terminalInstance)));
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
@@ -68,4 +69,8 @@ export class MainThreadTerminalService extends MainThreadTerminalServiceShape {
|
||||
private _onTerminalDisposed(terminalInstance: ITerminalInstance): void {
|
||||
this._proxy.$acceptTerminalClosed(terminalInstance.id);
|
||||
}
|
||||
|
||||
private _onTerminalProcessIdReady(terminalInstance: ITerminalInstance): void {
|
||||
this._proxy.$acceptTerminalProcessId(terminalInstance.id, terminalInstance.processId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user