diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index 152ced1b0fe..22d4183a505 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -94,14 +94,14 @@ export class ExtHostAPIImplementation { // Addressable instances const col = new InstanceCollection(); - const extHostDocuments = col.define(ExtHostContext.ExtHostDocuments).set(new ExtHostDocuments(threadService)); - const extHostEditors = col.define(ExtHostContext.ExtHostEditors).set(new ExtHostEditors(threadService, extHostDocuments)); - const extHostCommands = col.define(ExtHostContext.ExtHostCommands).set(new ExtHostCommands(threadService, extHostEditors)); - const extHostConfiguration = col.define(ExtHostContext.ExtHostConfiguration).set(new ExtHostConfiguration()); - const extHostDiagnostics = col.define(ExtHostContext.ExtHostDiagnostics).set(new ExtHostDiagnostics(threadService)); - const languageFeatures = col.define(ExtHostContext.ExtHostLanguageFeatures).set(new ExtHostLanguageFeatures(threadService, extHostDocuments, extHostCommands, extHostDiagnostics)); - const extHostFileSystemEvent = col.define(ExtHostContext.ExtHostFileSystemEventService).set(new ExtHostFileSystemEventService()); - const extHostQuickOpen = col.define(ExtHostContext.ExtHostQuickOpen).set(new ExtHostQuickOpen(threadService)); + const extHostDocuments = col.define(ExtHostContext.ExtHostDocuments).set(new ExtHostDocuments(threadService)); + const extHostEditors = col.define(ExtHostContext.ExtHostEditors).set(new ExtHostEditors(threadService, extHostDocuments)); + const extHostCommands = col.define(ExtHostContext.ExtHostCommands).set(new ExtHostCommands(threadService, extHostEditors)); + const extHostConfiguration = col.define(ExtHostContext.ExtHostConfiguration).set(new ExtHostConfiguration()); + const extHostDiagnostics = col.define(ExtHostContext.ExtHostDiagnostics).set(new ExtHostDiagnostics(threadService)); + const languageFeatures = col.define(ExtHostContext.ExtHostLanguageFeatures).set(new ExtHostLanguageFeatures(threadService, extHostDocuments, extHostCommands, extHostDiagnostics)); + const extHostFileSystemEvent = col.define(ExtHostContext.ExtHostFileSystemEventService).set(new ExtHostFileSystemEventService()); + const extHostQuickOpen = col.define(ExtHostContext.ExtHostQuickOpen).set(new ExtHostQuickOpen(threadService)); col.define(ExtHostContext.ExtHostExtensionService).set(extensionService); col.finish(false, threadService); diff --git a/src/vs/workbench/api/node/extHostCommands.ts b/src/vs/workbench/api/node/extHostCommands.ts index 5b51f294779..8443632ce02 100644 --- a/src/vs/workbench/api/node/extHostCommands.ts +++ b/src/vs/workbench/api/node/extHostCommands.ts @@ -12,8 +12,7 @@ import {ExtHostEditors} from 'vs/workbench/api/node/extHostEditors'; import * as extHostTypes from 'vs/workbench/api/node/extHostTypes'; import * as extHostTypeConverter from 'vs/workbench/api/node/extHostTypeConverters'; import {cloneAndChange} from 'vs/base/common/objects'; -import {MainContext} from './extHostProtocol'; -import {MainThreadCommands} from './mainThreadCommands'; +import {MainContext, MainThreadCommandsShape} from './extHostProtocol'; interface CommandHandler { callback: Function; @@ -24,7 +23,7 @@ interface CommandHandler { export class ExtHostCommands { private _commands: { [n: string]: CommandHandler } = Object.create(null); - private _proxy: MainThreadCommands; + private _proxy: MainThreadCommandsShape; private _extHostEditors: ExtHostEditors; constructor( diff --git a/src/vs/workbench/api/node/extHostDiagnostics.ts b/src/vs/workbench/api/node/extHostDiagnostics.ts index 70d74e02124..a4a90f8d2e6 100644 --- a/src/vs/workbench/api/node/extHostDiagnostics.ts +++ b/src/vs/workbench/api/node/extHostDiagnostics.ts @@ -9,20 +9,19 @@ import {IMarkerData} from 'vs/platform/markers/common/markers'; import URI from 'vs/base/common/uri'; import Severity from 'vs/base/common/severity'; import * as vscode from 'vscode'; -import {MainContext} from './extHostProtocol'; -import {MainThreadDiagnostics} from './mainThreadDiagnostics'; +import {MainContext, MainThreadDiagnosticsShape} from './extHostProtocol'; export class DiagnosticCollection implements vscode.DiagnosticCollection { private static _maxDiagnosticsPerFile: number = 250; private _name: string; - private _proxy: MainThreadDiagnostics; + private _proxy: MainThreadDiagnosticsShape; private _isDisposed = false; private _data: {[uri:string]: vscode.Diagnostic[]} = Object.create(null); - constructor(name: string, proxy: MainThreadDiagnostics) { + constructor(name: string, proxy: MainThreadDiagnosticsShape) { this._name = name; this._proxy = proxy; } @@ -180,7 +179,7 @@ export class ExtHostDiagnostics { private static _idPool: number = 0; - private _proxy: MainThreadDiagnostics; + private _proxy: MainThreadDiagnosticsShape; private _collections: DiagnosticCollection[]; constructor(threadService: IThreadService) { diff --git a/src/vs/workbench/api/node/extHostDocuments.ts b/src/vs/workbench/api/node/extHostDocuments.ts index 94614d20b1f..f817314a299 100644 --- a/src/vs/workbench/api/node/extHostDocuments.ts +++ b/src/vs/workbench/api/node/extHostDocuments.ts @@ -17,16 +17,7 @@ import {TPromise} from 'vs/base/common/winjs.base'; import * as vscode from 'vscode'; import {asWinJsPromise} from 'vs/base/common/async'; import {getWordAtText, ensureValidWordDefinition} from 'vs/editor/common/model/wordHelper'; -import {MainContext} from './extHostProtocol'; -import {MainThreadDocuments} from './mainThreadDocuments'; - -export interface IModelAddedData { - url: URI; - versionId: number; - value: editorCommon.IRawText; - modeId: string; - isDirty: boolean; -} +import {MainContext, MainThreadDocumentsShape, IModelAddedData} from './extHostProtocol'; const _modeId2WordDefinition: { [modeId: string]: RegExp; @@ -60,7 +51,7 @@ export class ExtHostDocuments { private _documentLoader: { [modelUri: string]: TPromise }; private _documentContentProviders: { [handle: number]: vscode.TextDocumentContentProvider; }; - private _proxy: MainThreadDocuments; + private _proxy: MainThreadDocumentsShape; constructor(threadService: IThreadService) { this._proxy = threadService.get(MainContext.MainThreadDocuments); @@ -229,13 +220,13 @@ export class ExtHostDocuments { export class ExtHostDocumentData extends MirrorModel2 { - private _proxy: MainThreadDocuments; + private _proxy: MainThreadDocumentsShape; private _languageId: string; private _isDirty: boolean; private _textLines: vscode.TextLine[]; private _document: vscode.TextDocument; - constructor(proxy: MainThreadDocuments, uri: URI, lines: string[], eol: string, + constructor(proxy: MainThreadDocumentsShape, uri: URI, lines: string[], eol: string, languageId: string, versionId: number, isDirty: boolean) { super(uri, lines, eol, versionId); diff --git a/src/vs/workbench/api/node/extHostEditors.ts b/src/vs/workbench/api/node/extHostEditors.ts index a0327f99e98..bb8df791782 100644 --- a/src/vs/workbench/api/node/extHostEditors.ts +++ b/src/vs/workbench/api/node/extHostEditors.ts @@ -13,24 +13,10 @@ import {IThreadService} from 'vs/workbench/services/thread/common/threadService' import {ExtHostDocuments, ExtHostDocumentData} from 'vs/workbench/api/node/extHostDocuments'; import {Selection, Range, Position, EditorOptions, EndOfLine, TextEditorRevealType} from './extHostTypes'; import {ISingleEditOperation, ISelection} from 'vs/editor/common/editorCommon'; -import {Position as EditorPosition} from 'vs/platform/editor/common/editor'; import {IResolvedTextEditorConfiguration} from 'vs/workbench/api/node/mainThreadEditorsTracker'; import * as TypeConverters from './extHostTypeConverters'; import {TextDocument, TextEditorSelectionChangeEvent, TextEditorOptionsChangeEvent, TextEditorOptions, TextEditorViewColumnChangeEvent, ViewColumn} from 'vscode'; -import {MainContext} from './extHostProtocol'; -import {MainThreadEditors} from './mainThreadEditors'; - -export interface ITextEditorAddData { - id: string; - document: URI; - options: IResolvedTextEditorConfiguration; - selections: ISelection[]; - editorPosition: EditorPosition; -} - -export interface ITextEditorPositionData { - [id: string]: EditorPosition; -} +import {MainContext, MainThreadEditorsShape, ITextEditorAddData, ITextEditorPositionData} from './extHostProtocol'; export class ExtHostEditors { @@ -44,7 +30,7 @@ export class ExtHostEditors { private _onDidChangeTextEditorViewColumn: Emitter; private _editors: { [id: string]: ExtHostTextEditor }; - private _proxy: MainThreadEditors; + private _proxy: MainThreadEditorsShape; private _onDidChangeActiveTextEditor: Emitter; private _extHostDocuments: ExtHostDocuments; private _activeEditorId: string; @@ -168,10 +154,10 @@ class TextEditorDecorationType implements vscode.TextEditorDecorationType { private static _Keys = new IdGenerator('TextEditorDecorationType'); - private _proxy: MainThreadEditors; + private _proxy: MainThreadEditorsShape; public key: string; - constructor(proxy: MainThreadEditors, options: vscode.DecorationRenderOptions) { + constructor(proxy: MainThreadEditorsShape, options: vscode.DecorationRenderOptions) { this.key = TextEditorDecorationType._Keys.nextId(); this._proxy = proxy; this._proxy._registerTextEditorDecorationType(this.key, options); @@ -284,7 +270,7 @@ function deprecated(name: string, message: string = 'Refer to the documentation class ExtHostTextEditor implements vscode.TextEditor { - private _proxy: MainThreadEditors; + private _proxy: MainThreadEditorsShape; private _id: string; private _documentData: ExtHostDocumentData; @@ -292,7 +278,7 @@ class ExtHostTextEditor implements vscode.TextEditor { private _options: TextEditorOptions; private _viewColumn: vscode.ViewColumn; - constructor(proxy: MainThreadEditors, id: string, document: ExtHostDocumentData, selections: Selection[], options: EditorOptions, viewColumn: vscode.ViewColumn) { + constructor(proxy: MainThreadEditorsShape, id: string, document: ExtHostDocumentData, selections: Selection[], options: EditorOptions, viewColumn: vscode.ViewColumn) { this._proxy = proxy; this._id = id; this._documentData = document; diff --git a/src/vs/workbench/api/node/extHostExtensionService.ts b/src/vs/workbench/api/node/extHostExtensionService.ts index c2a2855386f..399ddeb5a35 100644 --- a/src/vs/workbench/api/node/extHostExtensionService.ts +++ b/src/vs/workbench/api/node/extHostExtensionService.ts @@ -15,8 +15,7 @@ import {ExtensionsRegistry} from 'vs/platform/extensions/common/extensionsRegist import {ExtHostStorage} from 'vs/workbench/api/node/extHostStorage'; import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry'; import {IThreadService} from 'vs/workbench/services/thread/common/threadService'; -import {MainContext} from './extHostProtocol'; -import {MainProcessExtensionService} from './mainThreadExtensionService'; +import {MainContext, MainProcessExtensionServiceShape} from './extHostProtocol'; const hasOwnProperty = Object.hasOwnProperty; @@ -113,7 +112,7 @@ export class ExtHostExtensionService extends AbstractExtensionService(++mainCounter), - MainThreadConfiguration: createMainId(++mainCounter), - MainThreadDiagnostics: createMainId(++mainCounter), - MainThreadDocuments: createMainId(++mainCounter), - MainThreadEditors: createMainId(++mainCounter), - MainThreadErrors: createMainId(++mainCounter), - MainThreadLanguageFeatures: createMainId(++mainCounter), - MainThreadLanguages: createMainId(++mainCounter), - MainThreadMessageService: createMainId(++mainCounter), - MainThreadOutputService: createMainId(++mainCounter), - MainThreadQuickOpen: createMainId(++mainCounter), - MainThreadStatusBar: createMainId(++mainCounter), - MainThreadStorage: createMainId(++mainCounter), - MainThreadTelemetry: createMainId(++mainCounter), - MainThreadWorkspace: createMainId(++mainCounter), - MainProcessExtensionService: createMainId(++mainCounter), -}; +import {IMarkerData} from 'vs/platform/markers/common/markers'; +import {Position as EditorPosition} from 'vs/platform/editor/common/editor'; +import {IMessage, IExtensionDescription} from 'vs/platform/extensions/common/extensions'; +import {StatusbarAlignment as MainThreadStatusBarAlignment} from 'vs/platform/statusbar/common/statusbar'; +import {ITelemetryInfo} from 'vs/platform/telemetry/common/telemetry'; +import {ICommandHandlerDescription} from 'vs/platform/keybinding/common/keybindingService'; -let extCounter = 0; -export const ExtHostContext = { - ExtHostCommands: createExtId(++extCounter), - ExtHostConfiguration: createExtId(++extCounter), - ExtHostDiagnostics: createExtId(++extCounter), - ExtHostDocuments: createExtId(++extCounter), - ExtHostEditors: createExtId(++extCounter), - ExtHostFileSystemEventService: createExtId(++extCounter), - ExtHostLanguageFeatures: createExtId(++extCounter), - ExtHostQuickOpen: createExtId(++extCounter), - ExtHostExtensionService: createExtId(++extCounter), -}; +import * as editorCommon from 'vs/editor/common/editorCommon'; +import * as modes from 'vs/editor/common/modes'; +import {IResourceEdit} from 'vs/editor/common/services/bulkEdit'; + +import {IPickOpenEntry, IPickOptions} from 'vs/workbench/services/quickopen/common/quickOpenService'; +import {ITypeBearing} from 'vs/workbench/parts/search/common/search'; +import {TextEditorRevealType, ITextEditorConfigurationUpdate, IResolvedTextEditorConfiguration} from './mainThreadEditorsTracker'; +import {EndOfLine} from './extHostTypes'; export interface InstanceSetter { - set(instance:T): T; + set(instance:T): R; } export class InstanceCollection { @@ -109,3 +70,242 @@ export class InstanceCollection { }); } } + +function ni() { return new Error('Not implemented'); } + +// --- main thread + +export abstract class MainThreadCommandsShape { + $registerCommand(id: string): TPromise { throw ni(); } + $executeCommand(id: string, args: any[]): Thenable { throw ni(); } + $getCommands(): Thenable { throw ni(); } +} + +export abstract class MainThreadConfigurationShape { +} + +export abstract class MainThreadDiagnosticsShape { + $changeMany(owner: string, entries: [URI, IMarkerData[]][]): TPromise { throw ni(); } + $clear(owner: string): TPromise { throw ni(); } +} + +export abstract class MainThreadDocumentsShape { + _tryOpenDocument(uri: URI): TPromise { throw ni(); } + $registerTextContentProvider(handle:number, scheme: string): void { throw ni(); } + $onVirtualDocumentChange(uri: URI, value: string): void { throw ni(); } + $unregisterTextContentProvider(handle: number): void { throw ni(); } + _trySaveDocument(uri: URI): TPromise { throw ni(); } +} + +export abstract class MainThreadEditorsShape { + _tryShowTextDocument(resource: URI, position: EditorPosition, preserveFocus: boolean): TPromise { throw ni(); } + _registerTextEditorDecorationType(key: string, options: editorCommon.IDecorationRenderOptions): void { throw ni(); } + _removeTextEditorDecorationType(key: string): void { throw ni(); } + _tryShowEditor(id: string, position: EditorPosition): TPromise { throw ni(); } + _tryHideEditor(id: string): TPromise { throw ni(); } + _trySetOptions(id: string, options: ITextEditorConfigurationUpdate): TPromise { throw ni(); } + _trySetDecorations(id: string, key: string, ranges: editorCommon.IDecorationOptions[]): TPromise { throw ni(); } + _tryRevealRange(id: string, range: editorCommon.IRange, revealType: TextEditorRevealType): TPromise { throw ni(); } + _trySetSelections(id: string, selections: editorCommon.ISelection[]): TPromise { throw ni(); } + _tryApplyEdits(id: string, modelVersionId: number, edits: editorCommon.ISingleEditOperation[], setEndOfLine:EndOfLine): TPromise { throw ni(); } +} + +export abstract class MainThreadErrorsShape { + onUnexpectedExtHostError(err: any): void { throw ni(); } +} + +export abstract class MainThreadLanguageFeaturesShape { + $unregister(handle: number): TPromise { throw ni(); } + $registerOutlineSupport(handle: number, selector: vscode.DocumentSelector): TPromise { throw ni(); } + $registerCodeLensSupport(handle: number, selector: vscode.DocumentSelector): TPromise { throw ni(); } + $registerDeclaractionSupport(handle: number, selector: vscode.DocumentSelector): TPromise { throw ni(); } + $registerHoverProvider(handle: number, selector: vscode.DocumentSelector): TPromise { throw ni(); } + $registerDocumentHighlightProvider(handle: number, selector: vscode.DocumentSelector): TPromise { throw ni(); } + $registerReferenceSupport(handle: number, selector: vscode.DocumentSelector): TPromise { throw ni(); } + $registerQuickFixSupport(handle: number, selector: vscode.DocumentSelector): TPromise { throw ni(); } + $registerDocumentFormattingSupport(handle: number, selector: vscode.DocumentSelector): TPromise { throw ni(); } + $registerRangeFormattingSupport(handle: number, selector: vscode.DocumentSelector): TPromise { throw ni(); } + $registerOnTypeFormattingSupport(handle: number, selector: vscode.DocumentSelector, autoFormatTriggerCharacters: string[]): TPromise { throw ni(); } + $registerNavigateTypeSupport(handle: number): TPromise { throw ni(); } + $registerRenameSupport(handle: number, selector: vscode.DocumentSelector): TPromise { throw ni(); } + $registerSuggestSupport(handle: number, selector: vscode.DocumentSelector, triggerCharacters: string[]): TPromise { throw ni(); } + $registerSignatureHelpProvider(handle: number, selector: vscode.DocumentSelector, triggerCharacter: string[]): TPromise { throw ni(); } + $setLanguageConfiguration(handle: number, languageId:string, configuration: vscode.LanguageConfiguration): TPromise { throw ni(); } +} + +export abstract class MainThreadLanguagesShape { + _getLanguages(): TPromise { throw ni(); } +} + +export abstract class MainThreadMessageServiceShape { + $showMessage(severity: Severity, message: string, commands: { title: string; isCloseAffordance: boolean; handle: number; }[]): Thenable { throw ni(); } +} + +export abstract class MainThreadOutputServiceShape { + append(channelId: string, label: string, value: string): TPromise { throw ni(); } + clear(channelId: string, label: string): TPromise { throw ni(); } + reveal(channelId: string, label: string, preserveFocus: boolean): TPromise { throw ni(); } + close(channelId: string): TPromise { throw ni(); } +} + +export interface MyQuickPickItems extends IPickOpenEntry { + handle: number; +} +export abstract class MainThreadQuickOpenShape { + $show(options: IPickOptions): Thenable { throw ni(); } + $setItems(items: MyQuickPickItems[]): Thenable { throw ni(); } + $setError(error: Error): Thenable { throw ni(); } + $input(options: vscode.InputBoxOptions, validateInput: boolean): Thenable { throw ni(); } +} + +export abstract class MainThreadStatusBarShape { + setEntry(id: number, text: string, tooltip: string, command: string, color: string, alignment: MainThreadStatusBarAlignment, priority: number): void { throw ni(); } + dispose(id: number) { throw ni(); } +} + +export abstract class MainThreadStorageShape { + getValue(shared: boolean, key: string): TPromise { throw ni(); } + setValue(shared: boolean, key: string, value: any): TPromise { throw ni(); } +} + +export abstract class MainThreadTelemetryShape { + $publicLog(eventName: string, data?: any): void { throw ni(); } + $getTelemetryInfo(): TPromise { throw ni(); } +} + +export abstract class MainThreadWorkspaceShape { + $startSearch(include: string, exclude: string, maxResults: number, requestId: number): Thenable { throw ni(); } + $cancelSearch(requestId: number): Thenable { throw ni(); } + $saveAll(includeUntitled?: boolean): Thenable { throw ni(); } + $applyWorkspaceEdit(edits: IResourceEdit[]): TPromise { throw ni(); } +} + +export abstract class MainProcessExtensionServiceShape { + public $onExtensionHostReady(extensionDescriptions: IExtensionDescription[], messages: IMessage[]): TPromise { throw ni(); } + public $localShowMessage(severity: Severity, msg: string): void { throw ni(); } + public $onExtensionActivated(extensionId: string): void { throw ni(); } + public $onExtensionActivationFailed(extensionId: string): void { throw ni(); } +} + +// -- extension host + +export abstract class ExtHostCommandsShape { + $executeContributedCommand(id: string, ...args: any[]): Thenable { throw ni(); } + $getContributedCommandHandlerDescriptions(): TPromise<{ [id: string]: string | ICommandHandlerDescription }> { throw ni(); } +} + +export abstract class ExtHostConfigurationShape { + $acceptConfigurationChanged(config: any) { throw ni(); } +} + +export abstract class ExtHostDiagnosticsShape { + +} + +export interface IModelAddedData { + url: URI; + versionId: number; + value: editorCommon.IRawText; + modeId: string; + isDirty: boolean; +} +export abstract class ExtHostDocumentsShape { + $provideTextDocumentContent(handle: number, uri: URI): TPromise { throw ni(); } + _acceptModelAdd(initData: IModelAddedData): void { throw ni(); } + _acceptModelModeChanged(strURL: string, oldModeId: string, newModeId: string): void { throw ni(); } + _acceptModelSaved(strURL: string): void { throw ni(); } + _acceptModelDirty(strURL: string): void { throw ni(); } + _acceptModelReverted(strURL: string): void { throw ni(); } + _acceptModelRemoved(strURL: string): void { throw ni(); } + _acceptModelChanged(strURL: string, events: editorCommon.IModelContentChangedEvent2[]): void { throw ni(); } +} + +export interface ITextEditorAddData { + id: string; + document: URI; + options: IResolvedTextEditorConfiguration; + selections: editorCommon.ISelection[]; + editorPosition: EditorPosition; +} +export interface ITextEditorPositionData { + [id: string]: EditorPosition; +} +export abstract class ExtHostEditorsShape { + _acceptTextEditorAdd(data: ITextEditorAddData): void { throw ni(); } + _acceptOptionsChanged(id: string, opts: IResolvedTextEditorConfiguration): void { throw ni(); } + _acceptSelectionsChanged(id: string, _selections: editorCommon.ISelection[]): void { throw ni(); } + _acceptActiveEditorAndVisibleEditors(id: string, visibleIds: string[]): void { throw ni(); } + _acceptEditorPositionData(data: ITextEditorPositionData): void { throw ni(); } + _acceptTextEditorRemove(id: string): void { throw ni(); } +} + +export abstract class ExtHostExtensionServiceShape { + $localShowMessage(severity: Severity, msg: string): void { throw ni(); } + $activateExtension(extensionDescription: IExtensionDescription): TPromise { throw ni(); } +} + +export interface FileSystemEvents { + created: URI[]; + changed: URI[]; + deleted: URI[]; +} +export abstract class ExtHostFileSystemEventServiceShape { + _onFileEvent(events: FileSystemEvents) { throw ni(); } +} + +export abstract class ExtHostLanguageFeaturesShape { + $provideDocumentSymbols(handle: number, resource: URI): TPromise { throw ni(); } + $provideCodeLenses(handle: number, resource: URI): TPromise { throw ni(); } + $resolveCodeLens(handle: number, resource: URI, symbol: modes.ICodeLensSymbol): TPromise { throw ni(); } + $provideDefinition(handle: number, resource: URI, position: editorCommon.IPosition): TPromise { throw ni(); } + $provideHover(handle: number, resource: URI, position: editorCommon.IPosition): TPromise { throw ni(); } + $provideDocumentHighlights(handle: number, resource: URI, position: editorCommon.IPosition): TPromise { throw ni(); } + $provideReferences(handle: number, resource: URI, position: editorCommon.IPosition, context: modes.ReferenceContext): TPromise { throw ni(); } + $provideCodeActions(handle: number, resource: URI, range: editorCommon.IRange): TPromise { throw ni(); } + $provideDocumentFormattingEdits(handle: number, resource: URI, options: modes.FormattingOptions): TPromise { throw ni(); } + $provideDocumentRangeFormattingEdits(handle: number, resource: URI, range: editorCommon.IRange, options: modes.FormattingOptions): TPromise { throw ni(); } + $provideOnTypeFormattingEdits(handle: number, resource: URI, position: editorCommon.IPosition, ch: string, options: modes.FormattingOptions): TPromise { throw ni(); } + $getNavigateToItems(handle: number, search: string): TPromise { throw ni(); } + $provideRenameEdits(handle: number, resource: URI, position: editorCommon.IPosition, newName: string): TPromise { throw ni(); } + $provideCompletionItems(handle: number, resource: URI, position: editorCommon.IPosition): TPromise { throw ni(); } + $resolveCompletionItem(handle: number, resource: URI, position: editorCommon.IPosition, suggestion: modes.ISuggestion): TPromise { throw ni(); } + $provideSignatureHelp(handle: number, resource: URI, position: editorCommon.IPosition): TPromise { throw ni(); } +} + +export abstract class ExtHostQuickOpenShape { + $onItemSelected(handle: number): void { throw ni(); } + $validateInput(input: string): TPromise { throw ni(); } +} + +// --- proxy identifiers + +export const MainContext = { + MainThreadCommands: createMainId('MainThreadCommands', MainThreadCommandsShape), + MainThreadConfiguration: createMainId('MainThreadConfiguration', MainThreadConfigurationShape), + MainThreadDiagnostics: createMainId('MainThreadDiagnostics', MainThreadDiagnosticsShape), + MainThreadDocuments: createMainId('MainThreadDocuments', MainThreadDocumentsShape), + MainThreadEditors: createMainId('MainThreadEditors', MainThreadEditorsShape), + MainThreadErrors: createMainId('MainThreadErrors', MainThreadErrorsShape), + MainThreadLanguageFeatures: createMainId('MainThreadLanguageFeatures', MainThreadLanguageFeaturesShape), + MainThreadLanguages: createMainId('MainThreadLanguages', MainThreadLanguagesShape), + MainThreadMessageService: createMainId('MainThreadMessageService', MainThreadMessageServiceShape), + MainThreadOutputService: createMainId('MainThreadOutputService', MainThreadOutputServiceShape), + MainThreadQuickOpen: createMainId('MainThreadQuickOpen', MainThreadQuickOpenShape), + MainThreadStatusBar: createMainId('MainThreadStatusBar', MainThreadStatusBarShape), + MainThreadStorage: createMainId('MainThreadStorage', MainThreadStorageShape), + MainThreadTelemetry: createMainId('MainThreadTelemetry', MainThreadTelemetryShape), + MainThreadWorkspace: createMainId('MainThreadWorkspace', MainThreadWorkspaceShape), + MainProcessExtensionService: createMainId('MainProcessExtensionService', MainProcessExtensionServiceShape), +}; + +export const ExtHostContext = { + ExtHostCommands: createExtId('ExtHostCommands', ExtHostCommandsShape), + ExtHostConfiguration: createExtId('ExtHostConfiguration', ExtHostConfigurationShape), + ExtHostDiagnostics: createExtId('ExtHostDiagnostics', ExtHostDiagnosticsShape), + ExtHostDocuments: createExtId('ExtHostDocuments', ExtHostDocumentsShape), + ExtHostEditors: createExtId('ExtHostEditors', ExtHostEditorsShape), + ExtHostFileSystemEventService: createExtId('ExtHostFileSystemEventService', ExtHostFileSystemEventServiceShape), + ExtHostLanguageFeatures: createExtId('ExtHostLanguageFeatures', ExtHostLanguageFeaturesShape), + ExtHostQuickOpen: createExtId('ExtHostQuickOpen', ExtHostQuickOpenShape), + ExtHostExtensionService: createExtId('ExtHostExtensionService', ExtHostExtensionServiceShape), +}; diff --git a/src/vs/workbench/api/node/extHostQuickOpen.ts b/src/vs/workbench/api/node/extHostQuickOpen.ts index bb2c1c80a79..5bed2fc6e5f 100644 --- a/src/vs/workbench/api/node/extHostQuickOpen.ts +++ b/src/vs/workbench/api/node/extHostQuickOpen.ts @@ -6,20 +6,14 @@ import {TPromise} from 'vs/base/common/winjs.base'; import {IThreadService} from 'vs/workbench/services/thread/common/threadService'; -import {IPickOpenEntry} from 'vs/workbench/services/quickopen/common/quickOpenService'; import {QuickPickOptions, QuickPickItem, InputBoxOptions} from 'vscode'; -import {MainContext} from './extHostProtocol'; -import {MainThreadQuickOpen} from './mainThreadQuickOpen'; - -export interface MyQuickPickItems extends IPickOpenEntry { - handle: number; -} +import {MainContext, MainThreadQuickOpenShape, MyQuickPickItems} from './extHostProtocol'; export type Item = string | QuickPickItem; export class ExtHostQuickOpen { - private _proxy: MainThreadQuickOpen; + private _proxy: MainThreadQuickOpenShape; private _onDidSelectItem: (handle: number) => void; private _validateInput: (input: string) => string; diff --git a/src/vs/workbench/api/node/extHostStatusBar.ts b/src/vs/workbench/api/node/extHostStatusBar.ts index 0e4a0b05c38..ea3e8740d0c 100644 --- a/src/vs/workbench/api/node/extHostStatusBar.ts +++ b/src/vs/workbench/api/node/extHostStatusBar.ts @@ -8,8 +8,7 @@ import {IThreadService} from 'vs/workbench/services/thread/common/threadService' import {StatusbarAlignment as MainThreadStatusBarAlignment} from 'vs/platform/statusbar/common/statusbar'; import {StatusBarAlignment as ExtHostStatusBarAlignment, Disposable} from './extHostTypes'; import {StatusBarItem, StatusBarAlignment} from 'vscode'; -import {MainContext} from './extHostProtocol'; -import {MainThreadStatusBar} from './mainThreadStatusBar'; +import {MainContext, MainThreadStatusBarShape} from './extHostProtocol'; export class ExtHostStatusBarEntry implements StatusBarItem { private static ID_GEN = 0; @@ -26,9 +25,9 @@ export class ExtHostStatusBarEntry implements StatusBarItem { private _command: string; private _timeoutHandle: number; - private _proxy: MainThreadStatusBar; + private _proxy: MainThreadStatusBarShape; - constructor(proxy: MainThreadStatusBar, alignment: ExtHostStatusBarAlignment = ExtHostStatusBarAlignment.Left, priority?: number) { + constructor(proxy: MainThreadStatusBarShape, alignment: ExtHostStatusBarAlignment = ExtHostStatusBarAlignment.Left, priority?: number) { this._id = ExtHostStatusBarEntry.ID_GEN++; this._proxy = proxy; this._alignment = alignment; @@ -159,7 +158,7 @@ class StatusBarMessage { export class ExtHostStatusBar { - private _proxy: MainThreadStatusBar; + private _proxy: MainThreadStatusBarShape; private _statusMessage: StatusBarMessage; constructor(threadService: IThreadService) { diff --git a/src/vs/workbench/api/node/extHostStorage.ts b/src/vs/workbench/api/node/extHostStorage.ts index 05ed11b6b7e..8b171c47df9 100644 --- a/src/vs/workbench/api/node/extHostStorage.ts +++ b/src/vs/workbench/api/node/extHostStorage.ts @@ -6,12 +6,11 @@ import {TPromise} from 'vs/base/common/winjs.base'; import {IThreadService} from 'vs/workbench/services/thread/common/threadService'; -import {MainContext} from './extHostProtocol'; -import {MainThreadStorage} from './mainThreadStorage'; +import {MainContext, MainThreadStorageShape} from './extHostProtocol'; export class ExtHostStorage { - private _proxy: MainThreadStorage; + private _proxy: MainThreadStorageShape; constructor(threadService: IThreadService) { this._proxy = threadService.get(MainContext.MainThreadStorage); diff --git a/src/vs/workbench/api/node/extHostTelemetry.ts b/src/vs/workbench/api/node/extHostTelemetry.ts index 1cc345c1117..0006649f24d 100644 --- a/src/vs/workbench/api/node/extHostTelemetry.ts +++ b/src/vs/workbench/api/node/extHostTelemetry.ts @@ -8,15 +8,14 @@ import {notImplemented} from 'vs/base/common/errors'; import {TPromise} from 'vs/base/common/winjs.base'; import {ITelemetryService, ITelemetryInfo} from 'vs/platform/telemetry/common/telemetry'; import {IThreadService} from 'vs/workbench/services/thread/common/threadService'; -import {MainContext} from './extHostProtocol'; -import {MainThreadTelemetry} from './mainThreadTelemetry'; +import {MainContext, MainThreadTelemetryShape} from './extHostProtocol'; export class RemoteTelemetryService implements ITelemetryService { serviceId: any; private _name: string; - private _proxy: MainThreadTelemetry; + private _proxy: MainThreadTelemetryShape; constructor(name: string, threadService: IThreadService) { this._name = name; diff --git a/src/vs/workbench/api/node/extHostWorkspace.ts b/src/vs/workbench/api/node/extHostWorkspace.ts index c7846877fe7..fb32d9bc839 100644 --- a/src/vs/workbench/api/node/extHostWorkspace.ts +++ b/src/vs/workbench/api/node/extHostWorkspace.ts @@ -10,14 +10,13 @@ import {IResourceEdit} from 'vs/editor/common/services/bulkEdit'; import {TPromise} from 'vs/base/common/winjs.base'; import {fromRange} from 'vs/workbench/api/node/extHostTypeConverters'; import {Uri, CancellationToken} from 'vscode'; -import {MainContext} from './extHostProtocol'; -import {MainThreadWorkspace} from './mainThreadWorkspace'; +import {MainContext, MainThreadWorkspaceShape} from './extHostProtocol'; export class ExtHostWorkspace { private static _requestIdPool = 0; - private _proxy: MainThreadWorkspace; + private _proxy: MainThreadWorkspaceShape; private _workspacePath: string; constructor(threadService: IThreadService, workspacePath:string) { diff --git a/src/vs/workbench/api/node/mainThreadCommands.ts b/src/vs/workbench/api/node/mainThreadCommands.ts index 2775bc19ef1..d050dd6cfe1 100644 --- a/src/vs/workbench/api/node/mainThreadCommands.ts +++ b/src/vs/workbench/api/node/mainThreadCommands.ts @@ -8,14 +8,13 @@ import {IThreadService} from 'vs/workbench/services/thread/common/threadService' import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry'; import {IKeybindingService, ICommandHandlerDescription} from 'vs/platform/keybinding/common/keybindingService'; import {TPromise} from 'vs/base/common/winjs.base'; -import {ExtHostContext} from './extHostProtocol'; -import {ExtHostCommands} from './extHostCommands'; +import {ExtHostContext, ExtHostCommandsShape} from './extHostProtocol'; export class MainThreadCommands { private _threadService: IThreadService; private _keybindingService: IKeybindingService; - private _proxy: ExtHostCommands; + private _proxy: ExtHostCommandsShape; constructor( @IThreadService threadService: IThreadService, diff --git a/src/vs/workbench/api/node/mainThreadConfiguration.ts b/src/vs/workbench/api/node/mainThreadConfiguration.ts index 6bbf391fa99..4c06bf9f960 100644 --- a/src/vs/workbench/api/node/mainThreadConfiguration.ts +++ b/src/vs/workbench/api/node/mainThreadConfiguration.ts @@ -7,17 +7,18 @@ import {IDisposable, dispose} from 'vs/base/common/lifecycle'; import {IThreadService} from 'vs/workbench/services/thread/common/threadService'; import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; -import {ExtHostContext} from './extHostProtocol'; -import {ExtHostConfiguration} from './extHostConfiguration'; +import {ExtHostContext, ExtHostConfigurationShape} from './extHostProtocol'; export class MainThreadConfiguration { private _configurationService: IConfigurationService; private _toDispose: IDisposable; - private _proxy: ExtHostConfiguration; + private _proxy: ExtHostConfigurationShape; - constructor(@IConfigurationService configurationService: IConfigurationService, - @IThreadService threadService: IThreadService) { + constructor( + @IConfigurationService configurationService: IConfigurationService, + @IThreadService threadService: IThreadService + ) { this._configurationService = configurationService; this._proxy = threadService.get(ExtHostContext.ExtHostConfiguration); diff --git a/src/vs/workbench/api/node/mainThreadDocuments.ts b/src/vs/workbench/api/node/mainThreadDocuments.ts index bbe839b1f6a..8b48d048a18 100644 --- a/src/vs/workbench/api/node/mainThreadDocuments.ts +++ b/src/vs/workbench/api/node/mainThreadDocuments.ts @@ -19,8 +19,7 @@ import {IFileService} from 'vs/platform/files/common/files'; import {IModeService} from 'vs/editor/common/services/modeService'; import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService'; import {ResourceEditorInput} from 'vs/workbench/common/editor/resourceEditorInput'; -import {ExtHostContext} from './extHostProtocol'; -import {ExtHostDocuments} from './extHostDocuments'; +import {ExtHostContext, ExtHostDocumentsShape} from './extHostProtocol'; export class MainThreadDocuments { private _modelService: IModelService; @@ -31,7 +30,7 @@ export class MainThreadDocuments { private _untitledEditorService: IUntitledEditorService; private _toDispose: IDisposable[]; private _modelToDisposeMap: { [modelUrl: string]: IDisposable; }; - private _proxy: ExtHostDocuments; + private _proxy: ExtHostDocumentsShape; private _modelIsSynced: { [modelId: string]: boolean; }; private _resourceContentProvider: { [handle: number]: IDisposable }; private _virtualDocumentSet: { [resource: string]: boolean }; diff --git a/src/vs/workbench/api/node/mainThreadEditors.ts b/src/vs/workbench/api/node/mainThreadEditors.ts index 0c721adf95e..a7b1fc61831 100644 --- a/src/vs/workbench/api/node/mainThreadEditors.ts +++ b/src/vs/workbench/api/node/mainThreadEditors.ts @@ -20,12 +20,11 @@ import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry'; import {IEventService} from 'vs/platform/event/common/event'; import {equals as arrayEquals} from 'vs/base/common/arrays'; import {equals as objectEquals} from 'vs/base/common/objects'; -import {ExtHostContext} from './extHostProtocol'; -import {ExtHostEditors, ITextEditorPositionData} from './extHostEditors'; +import {ExtHostContext, ExtHostEditorsShape, ITextEditorPositionData} from './extHostProtocol'; export class MainThreadEditors { - private _proxy: ExtHostEditors; + private _proxy: ExtHostEditorsShape; private _workbenchEditorService: IWorkbenchEditorService; private _telemetryService: ITelemetryService; private _editorTracker: MainThreadEditorsTracker; diff --git a/src/vs/workbench/api/node/mainThreadExtensionService.ts b/src/vs/workbench/api/node/mainThreadExtensionService.ts index 8689c471c76..f1f00b2f183 100644 --- a/src/vs/workbench/api/node/mainThreadExtensionService.ts +++ b/src/vs/workbench/api/node/mainThreadExtensionService.ts @@ -12,8 +12,7 @@ import {ExtensionsRegistry} from 'vs/platform/extensions/common/extensionsRegist import {IMessageService} from 'vs/platform/message/common/message'; import {IThreadService} from 'vs/workbench/services/thread/common/threadService'; import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace'; -import {ExtHostContext} from './extHostProtocol'; -import {ExtHostExtensionService} from './extHostExtensionService'; +import {ExtHostContext, ExtHostExtensionServiceShape} from './extHostProtocol'; /** * Represents a failed extension in the ext host. @@ -42,7 +41,7 @@ export class MainProcessExtensionService extends AbstractExtensionService any; private _doSetError: (error: Error) => any; diff --git a/src/vs/workbench/services/thread/common/abstractThreadService.ts b/src/vs/workbench/services/thread/common/abstractThreadService.ts index d97f492182d..c4e1bdce183 100644 --- a/src/vs/workbench/services/thread/common/abstractThreadService.ts +++ b/src/vs/workbench/services/thread/common/abstractThreadService.ts @@ -8,7 +8,7 @@ import {TPromise} from 'vs/base/common/winjs.base'; import {IManyHandler} from 'vs/base/common/remote'; import {ProxyIdentifier} from 'vs/workbench/services/thread/common/threadService'; -declare var Proxy:any; // TODO@TypeScript +// declare var Proxy:any; // TODO@TypeScript export abstract class AbstractThreadService implements IManyHandler { @@ -36,29 +36,41 @@ export abstract class AbstractThreadService implements IManyHandler { get(identifier:ProxyIdentifier): T { if (!this._proxies[identifier.id]) { - this._proxies[identifier.id] = this._createProxy(identifier.id); + this._proxies[identifier.id] = this._createProxy(identifier.id, identifier.methodNames); } return this._proxies[identifier.id]; } - private _createProxy(id:string): T { - let handler = { - get: (target, name) => { - return (...myArgs: any[]) => { - return this._callOnRemote(id, name, myArgs); - }; - } - }; + private _createProxy(id:string, methodNames:string[]): T { + // Check below how to switch to native proxies + let result:any = {}; + for (let i = 0; i < methodNames.length; i++) { + let methodName = methodNames[i]; + result[methodName] = this.createMethodProxy(id, methodName); + } + return result; - return new Proxy({}, handler); + // let handler = { + // get: (target, name) => { + // return (...myArgs: any[]) => { + // return this._callOnRemote(id, name, myArgs); + // }; + // } + // }; + // return new Proxy({}, handler); } - set(identifier:ProxyIdentifier, value:T): T { + private createMethodProxy(id: string, methodName: string): (...myArgs: any[]) => TPromise { + return (...myArgs: any[]) => { + return this._callOnRemote(id, methodName, myArgs); + }; + } + + set(identifier:ProxyIdentifier, value:T): void { if (identifier.isMain !== this._isMain) { throw new Error('Mismatch in object registration!'); } this._locals[identifier.id] = value; - return value; } protected abstract _callOnRemote(proxyId: string, path: string, args:any[]): TPromise; diff --git a/src/vs/workbench/services/thread/common/threadService.ts b/src/vs/workbench/services/thread/common/threadService.ts index c742630deb6..b336978ea8f 100644 --- a/src/vs/workbench/services/thread/common/threadService.ts +++ b/src/vs/workbench/services/thread/common/threadService.ts @@ -19,7 +19,7 @@ export interface IThreadService { /** * Register instance. */ - set(identifier:ProxyIdentifier, value:T): T; + set(identifier:ProxyIdentifier, value:T): void; } export class ProxyIdentifier { @@ -27,17 +27,25 @@ export class ProxyIdentifier { isMain: boolean; id: string; + methodNames: string[]; - constructor(isMain: boolean, id: string) { + constructor(isMain: boolean, id: string, ctor:Function) { this.isMain = isMain; this.id = id; + + this.methodNames = []; + for (let prop in ctor.prototype) { + if (typeof ctor.prototype[prop] === 'function') { + this.methodNames.push(prop); + } + } } } -export function createMainContextProxyIdentifier(identifier: number): ProxyIdentifier { - return new ProxyIdentifier(true, 'm' + identifier); +export function createMainContextProxyIdentifier(identifier:string, ctor:Function): ProxyIdentifier { + return new ProxyIdentifier(true, 'm' + identifier, ctor); } -export function createExtHostContextProxyIdentifier(identifier: number): ProxyIdentifier { - return new ProxyIdentifier(false, 'e' + identifier); +export function createExtHostContextProxyIdentifier(identifier:string, ctor:Function): ProxyIdentifier { + return new ProxyIdentifier(false, 'e' + identifier, ctor); } diff --git a/src/vs/workbench/test/node/api/extHostApiCommands.test.ts b/src/vs/workbench/test/node/api/extHostApiCommands.test.ts index caeacc935cb..77339fc8408 100644 --- a/src/vs/workbench/test/node/api/extHostApiCommands.test.ts +++ b/src/vs/workbench/test/node/api/extHostApiCommands.test.ts @@ -80,7 +80,8 @@ suite('ExtHostLanguageFeatureCommands', function() { getCreationOptions(): any { throw new Error(); } }); - const extHostDocuments = threadService.set(ExtHostContext.ExtHostDocuments, new ExtHostDocuments(threadService)); + const extHostDocuments = new ExtHostDocuments(threadService); + threadService.set(ExtHostContext.ExtHostDocuments, extHostDocuments); extHostDocuments._acceptModelAdd({ isDirty: false, versionId: model.getVersionId(), @@ -100,14 +101,17 @@ suite('ExtHostLanguageFeatureCommands', function() { }, }); - commands = threadService.set(ExtHostContext.ExtHostCommands, new ExtHostCommands(threadService, null)); + commands = new ExtHostCommands(threadService, null); + threadService.set(ExtHostContext.ExtHostCommands, commands); ExtHostTypeConverters.Command.initialize(commands); threadService.setTestInstance(MainContext.MainThreadCommands, instantiationService.createInstance(MainThreadCommands)); registerApiCommands(commands); - const diagnostics = threadService.set(ExtHostContext.ExtHostDiagnostics, new ExtHostDiagnostics(threadService)); + const diagnostics = new ExtHostDiagnostics(threadService); + threadService.set(ExtHostContext.ExtHostDiagnostics, diagnostics); - extHost = threadService.set(ExtHostContext.ExtHostLanguageFeatures, new ExtHostLanguageFeatures(threadService, extHostDocuments, commands, diagnostics)); + extHost = new ExtHostLanguageFeatures(threadService, extHostDocuments, commands, diagnostics); + threadService.set(ExtHostContext.ExtHostLanguageFeatures, extHost); mainThread = threadService.setTestInstance(MainContext.MainThreadLanguageFeatures, instantiationService.createInstance(MainThreadLanguageFeatures)); diff --git a/src/vs/workbench/test/node/api/extHostLanguageFeatures.test.ts b/src/vs/workbench/test/node/api/extHostLanguageFeatures.test.ts index 1473290214e..c929e246976 100644 --- a/src/vs/workbench/test/node/api/extHostLanguageFeatures.test.ts +++ b/src/vs/workbench/test/node/api/extHostLanguageFeatures.test.ts @@ -71,7 +71,8 @@ suite('ExtHostLanguageFeatures', function() { originalErrorHandler = errorHandler.getUnexpectedErrorHandler(); setUnexpectedErrorHandler(() => { }); - const extHostDocuments = threadService.set(ExtHostContext.ExtHostDocuments, new ExtHostDocuments(threadService)); + const extHostDocuments = new ExtHostDocuments(threadService); + threadService.set(ExtHostContext.ExtHostDocuments, extHostDocuments); extHostDocuments._acceptModelAdd({ isDirty: false, versionId: model.getVersionId(), @@ -91,12 +92,15 @@ suite('ExtHostLanguageFeatures', function() { }, }); - const commands = threadService.set(ExtHostContext.ExtHostCommands, new ExtHostCommands(threadService, null)); + const commands = new ExtHostCommands(threadService, null); + threadService.set(ExtHostContext.ExtHostCommands, commands); threadService.setTestInstance(MainContext.MainThreadCommands, instantiationService.createInstance(MainThreadCommands)); - const diagnostics = threadService.set(ExtHostContext.ExtHostDiagnostics, new ExtHostDiagnostics(threadService)); + const diagnostics = new ExtHostDiagnostics(threadService); + threadService.set(ExtHostContext.ExtHostDiagnostics, diagnostics); - extHost = threadService.set(ExtHostContext.ExtHostLanguageFeatures, new ExtHostLanguageFeatures(threadService, extHostDocuments, commands, diagnostics)); + extHost = new ExtHostLanguageFeatures(threadService, extHostDocuments, commands, diagnostics); + threadService.set(ExtHostContext.ExtHostLanguageFeatures, extHost); mainThread = threadService.setTestInstance(MainContext.MainThreadLanguageFeatures, instantiationService.createInstance(MainThreadLanguageFeatures)); });