/*--------------------------------------------------------------------------------------------- * 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 { createMainContextProxyIdentifier as createMainId, createExtHostContextProxyIdentifier as createExtId, ProxyIdentifier, IThreadService } from 'vs/workbench/services/thread/common/threadService'; import * as vscode from 'vscode'; import URI from 'vs/base/common/uri'; import Severity from 'vs/base/common/severity'; import { TPromise } from 'vs/base/common/winjs.base'; 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/commands/common/commands'; 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 { ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing'; import { IPickOpenEntry, IPickOptions } from 'vs/workbench/services/quickopen/common/quickOpenService'; import { SaveReason } from 'vs/workbench/services/textfile/common/textfiles'; import { IWorkspaceSymbol } from 'vs/workbench/parts/search/common/search'; import { IApplyEditsOptions, TextEditorRevealType, ITextEditorConfigurationUpdate, IResolvedTextEditorConfiguration, ISelectionChangeEvent } from './mainThreadEditorsTracker'; export interface InstanceSetter { set(instance: T): R; } export class InstanceCollection { private _items: { [id: string]: any; }; constructor() { this._items = Object.create(null); } public define(id: ProxyIdentifier): InstanceSetter { let that = this; return new class { set(value: T) { that._set(id, value); return value; } }; } _set(id: ProxyIdentifier, value: T): void { this._items[id.id] = value; } public finish(isMain: boolean, threadService: IThreadService): void { let expected = (isMain ? MainContext : ExtHostContext); Object.keys(expected).forEach((key) => { let id = expected[key]; let value = this._items[id.id]; if (!value) { throw new Error(`Missing actor ${key} (isMain: ${id.isMain}, id: ${id.id})`); } threadService.set(id, value); }); } } function ni() { return new Error('Not implemented'); } // --- main thread export abstract class MainThreadCommandsShape { $registerCommand(id: string): TPromise { throw ni(); } $unregisterCommand(id: string): TPromise { throw ni(); } $executeCommand(id: string, args: any[]): Thenable { throw ni(); } $getCommands(): Thenable { throw ni(); } } export abstract class MainThreadConfigurationShape { $updateConfigurationOption(target: ConfigurationTarget, key: string, value: any): TPromise { throw ni(); } $removeConfigurationOption(target: ConfigurationTarget, key: string): TPromise { throw ni(); } } 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[], opts: IApplyEditsOptions): 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(); } $registerDocumentLinkProvider(handle: number, selector: vscode.DocumentSelector): 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 abstract class MainThreadTerminalServiceShape { $createTerminal(name?: string, shellPath?: string, shellArgs?: string[]): TPromise { 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; } 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): TPromise { 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 { $onExtensionHostReady(extensionDescriptions: IExtensionDescription[], messages: IMessage[]): TPromise { throw ni(); } $localShowMessage(severity: Severity, msg: string): void { throw ni(); } $onExtensionActivated(extensionId: string): void { throw ni(); } $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[], isDirty: boolean): void { throw ni(); } } export abstract class ExtHostDocumentSaveParticipantShape { $participateInSave(resource: URI, reason: SaveReason): TPromise { 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, event: ISelectionChangeEvent): 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 interface ObjectIdentifier { $ident: number; } export namespace ObjectIdentifier { export const name = '$ident'; export function mixin(obj: T, id: number): T & ObjectIdentifier { Object.defineProperty(obj, name, { value: id, enumerable: true }); return obj; } export function of(obj: any): number { return obj[name]; } } export abstract class ExtHostHeapServiceShape { $onGarbageCollection(ids: number[]): void { 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(); } $provideWorkspaceSymbols(handle: number, search: string): TPromise { throw ni(); } $resolveWorkspaceSymbol(handle: number, symbol: IWorkspaceSymbol): 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(); } $provideDocumentLinks(handle: number, resource: URI): TPromise { throw ni(); } $resolveDocumentLink(handle: number, link: modes.ILink): TPromise { throw ni(); } } export abstract class ExtHostQuickOpenShape { $onItemSelected(handle: number): void { throw ni(); } $validateInput(input: string): TPromise { throw ni(); } } export abstract class ExtHostTerminalServiceShape { $acceptTerminalClosed(id: number): void { throw ni(); } $acceptTerminalProcessId(id: number, processId: number): void { 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), MainThreadTerminalService: createMainId('MainThreadTerminalService', MainThreadTerminalServiceShape), 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), ExtHostDocumentSaveParticipant: createExtId('ExtHostDocumentSaveParticipant', ExtHostDocumentSaveParticipantShape), ExtHostEditors: createExtId('ExtHostEditors', ExtHostEditorsShape), ExtHostFileSystemEventService: createExtId('ExtHostFileSystemEventService', ExtHostFileSystemEventServiceShape), ExtHostHeapService: createExtId('ExtHostHeapMonitor', ExtHostHeapServiceShape), ExtHostLanguageFeatures: createExtId('ExtHostLanguageFeatures', ExtHostLanguageFeaturesShape), ExtHostQuickOpen: createExtId('ExtHostQuickOpen', ExtHostQuickOpenShape), ExtHostExtensionService: createExtId('ExtHostExtensionService', ExtHostExtensionServiceShape), ExtHostTerminalService: createExtId('ExtHostTerminalService', ExtHostTerminalServiceShape) };