mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 18:49:00 +01:00
Merge pull request #10635 from Microsoft/tyriar/terminal_api
Implement integrated terminal extension API
This commit is contained in:
@@ -20,6 +20,7 @@ import {ExtHostQuickOpen} from 'vs/workbench/api/node/extHostQuickOpen';
|
||||
import {ExtHostStatusBar} from 'vs/workbench/api/node/extHostStatusBar';
|
||||
import {ExtHostCommands} from 'vs/workbench/api/node/extHostCommands';
|
||||
import {ExtHostOutputService} from 'vs/workbench/api/node/extHostOutputService';
|
||||
import {ExtHostTerminalService} from 'vs/workbench/api/node/extHostTerminalService';
|
||||
import {ExtHostMessageService} from 'vs/workbench/api/node/extHostMessageService';
|
||||
import {ExtHostEditors} from 'vs/workbench/api/node/extHostEditors';
|
||||
import {ExtHostLanguages} from 'vs/workbench/api/node/extHostLanguages';
|
||||
@@ -119,6 +120,7 @@ export class ExtHostAPIImplementation {
|
||||
const extHostMessageService = new ExtHostMessageService(threadService);
|
||||
const extHostStatusBar = new ExtHostStatusBar(threadService);
|
||||
const extHostOutputService = new ExtHostOutputService(threadService);
|
||||
const extHostTerminalService = new ExtHostTerminalService(threadService);
|
||||
const workspacePath = contextService.getWorkspace() ? contextService.getWorkspace().resource.fsPath : undefined;
|
||||
const extHostWorkspace = new ExtHostWorkspace(threadService, workspacePath);
|
||||
const languages = new ExtHostLanguages(threadService);
|
||||
@@ -255,6 +257,9 @@ export class ExtHostAPIImplementation {
|
||||
},
|
||||
createOutputChannel(name: string): vscode.OutputChannel {
|
||||
return extHostOutputService.createOutputChannel(name);
|
||||
},
|
||||
createTerminal(name?: string): vscode.Terminal {
|
||||
return extHostTerminalService.createTerminal(name);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import {MainThreadQuickOpen} from './mainThreadQuickOpen';
|
||||
import {MainThreadStatusBar} from './mainThreadStatusBar';
|
||||
import {MainThreadStorage} from './mainThreadStorage';
|
||||
import {MainThreadTelemetry} from './mainThreadTelemetry';
|
||||
import {MainThreadTerminalService} from './mainThreadTerminalService';
|
||||
import {MainThreadWorkspace} from './mainThreadWorkspace';
|
||||
import {MainProcessExtensionService} from './mainThreadExtensionService';
|
||||
import {MainThreadFileSystemEventService} from './mainThreadFileSystemEventService';
|
||||
@@ -72,6 +73,7 @@ export class ExtHostContribution implements IWorkbenchContribution {
|
||||
col.define(MainContext.MainThreadStatusBar).set(create(MainThreadStatusBar));
|
||||
col.define(MainContext.MainThreadStorage).set(create(MainThreadStorage));
|
||||
col.define(MainContext.MainThreadTelemetry).set(create(MainThreadTelemetry));
|
||||
col.define(MainContext.MainThreadTerminalService).set(create(MainThreadTerminalService));
|
||||
col.define(MainContext.MainThreadWorkspace).set(create(MainThreadWorkspace));
|
||||
if (this.extensionService instanceof MainProcessExtensionService) {
|
||||
col.define(MainContext.MainProcessExtensionService).set(<MainProcessExtensionService>this.extensionService);
|
||||
|
||||
@@ -146,6 +146,14 @@ export abstract class MainThreadOutputServiceShape {
|
||||
$close(channelId: string): TPromise<void> { throw ni(); }
|
||||
}
|
||||
|
||||
export abstract class MainThreadTerminalServiceShape {
|
||||
$createTerminal(name?: string): TPromise<number> { throw ni(); }
|
||||
$dispose(terminalId: number): void { throw ni(); }
|
||||
$hide(terminalId: number): void { throw ni(); }
|
||||
$sendText(terminalId: number, text: string, addNewLine: boolean): void { throw ni(); }
|
||||
$show(terminalId: number, preserveFocus: boolean): void { throw ni(); }
|
||||
}
|
||||
|
||||
export interface MyQuickPickItems extends IPickOpenEntry {
|
||||
handle: number;
|
||||
}
|
||||
@@ -294,6 +302,7 @@ export const MainContext = {
|
||||
MainThreadStatusBar: createMainId<MainThreadStatusBarShape>('MainThreadStatusBar', MainThreadStatusBarShape),
|
||||
MainThreadStorage: createMainId<MainThreadStorageShape>('MainThreadStorage', MainThreadStorageShape),
|
||||
MainThreadTelemetry: createMainId<MainThreadTelemetryShape>('MainThreadTelemetry', MainThreadTelemetryShape),
|
||||
MainThreadTerminalService: createMainId<MainThreadTerminalServiceShape>('MainThreadTerminalService', MainThreadTerminalServiceShape),
|
||||
MainThreadWorkspace: createMainId<MainThreadWorkspaceShape>('MainThreadWorkspace', MainThreadWorkspaceShape),
|
||||
MainProcessExtensionService: createMainId<MainProcessExtensionServiceShape>('MainProcessExtensionService', MainProcessExtensionServiceShape),
|
||||
};
|
||||
|
||||
77
src/vs/workbench/api/node/extHostTerminalService.ts
Normal file
77
src/vs/workbench/api/node/extHostTerminalService.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import {IThreadService} from 'vs/workbench/services/thread/common/threadService';
|
||||
import vscode = require('vscode');
|
||||
import {MainContext, MainThreadTerminalServiceShape} from './extHost.protocol';
|
||||
|
||||
export class ExtHostTerminal implements vscode.Terminal {
|
||||
|
||||
public name: string;
|
||||
|
||||
private _id: number;
|
||||
private _proxy: MainThreadTerminalServiceShape;
|
||||
private _disposed: boolean;
|
||||
|
||||
constructor(proxy: MainThreadTerminalServiceShape, id: number, name?: string) {
|
||||
this.name = name;
|
||||
this._proxy = proxy;
|
||||
this._proxy.$createTerminal(name).then((terminalId) => {
|
||||
this._id = terminalId;
|
||||
});
|
||||
}
|
||||
|
||||
public sendText(text: string, addNewLine: boolean = true): void {
|
||||
this.checkId();
|
||||
this.checkDisposed();
|
||||
this._proxy.$sendText(this._id, text, addNewLine);
|
||||
}
|
||||
|
||||
public show(preserveFocus: boolean): void {
|
||||
this.checkId();
|
||||
this.checkDisposed();
|
||||
this._proxy.$show(this._id, preserveFocus);
|
||||
}
|
||||
|
||||
public hide(): void {
|
||||
this.checkId();
|
||||
this.checkDisposed();
|
||||
this._proxy.$hide(this._id);
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
this.checkId();
|
||||
if (!this._disposed) {
|
||||
this._disposed = true;
|
||||
this._proxy.$dispose(this._id);
|
||||
}
|
||||
}
|
||||
|
||||
private checkId() {
|
||||
if (!this._id) {
|
||||
throw new Error('Terminal has not been initialized yet');
|
||||
}
|
||||
}
|
||||
|
||||
private checkDisposed() {
|
||||
if (this._disposed) {
|
||||
throw new Error('Terminal has already been disposed');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class ExtHostTerminalService {
|
||||
|
||||
private _proxy: MainThreadTerminalServiceShape;
|
||||
|
||||
constructor(threadService: IThreadService) {
|
||||
this._proxy = threadService.get(MainContext.MainThreadTerminalService);
|
||||
}
|
||||
|
||||
public createTerminal(name?: string): vscode.Terminal {
|
||||
return new ExtHostTerminal(this._proxy, -1, name);
|
||||
}
|
||||
}
|
||||
50
src/vs/workbench/api/node/mainThreadTerminalService.ts
Normal file
50
src/vs/workbench/api/node/mainThreadTerminalService.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import {TPromise} from 'vs/base/common/winjs.base';
|
||||
import {ITerminalService} from 'vs/workbench/parts/terminal/electron-browser/terminal';
|
||||
import {MainThreadTerminalServiceShape} from './extHost.protocol';
|
||||
|
||||
export class MainThreadTerminalService extends MainThreadTerminalServiceShape {
|
||||
|
||||
private _terminalService: ITerminalService;
|
||||
|
||||
constructor(
|
||||
@ITerminalService terminalService: ITerminalService
|
||||
) {
|
||||
super();
|
||||
this._terminalService = terminalService;
|
||||
}
|
||||
|
||||
public $createTerminal(name?: string): TPromise<number> {
|
||||
return this._terminalService.createNew(name);
|
||||
}
|
||||
|
||||
public $show(terminalId: number, preserveFocus: boolean): void {
|
||||
this._terminalService.show(!preserveFocus).then((terminalPanel) => {
|
||||
terminalPanel.setActiveTerminalById(terminalId);
|
||||
});
|
||||
}
|
||||
|
||||
public $hide(terminalId: number): void {
|
||||
// TODO: Use terminalId to hide it
|
||||
this._terminalService.hide();
|
||||
}
|
||||
|
||||
public $dispose(terminalId: number): void {
|
||||
// TODO: This could be improved by not first showing the terminal to be disposed
|
||||
this._terminalService.show(false).then((terminalPanel) => {
|
||||
terminalPanel.closeTerminalById(terminalId);
|
||||
});;
|
||||
}
|
||||
|
||||
public $sendText(terminalId: number, text: string, addNewLine: boolean): void {
|
||||
this._terminalService.show(false).then((terminalPanel) => {
|
||||
terminalPanel.setActiveTerminalById(terminalId);
|
||||
terminalPanel.sendTextToActiveTerminal(text, addNewLine);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user