diff --git a/src/vs/workbench/api/browser/pluginHost.api.impl.ts b/src/vs/workbench/api/browser/pluginHost.api.impl.ts index 606d5ccfb5c..eacd47d1fa8 100644 --- a/src/vs/workbench/api/browser/pluginHost.api.impl.ts +++ b/src/vs/workbench/api/browser/pluginHost.api.impl.ts @@ -17,7 +17,6 @@ import {PluginHostQuickOpen} from 'vs/workbench/api/browser/pluginHostQuickOpen' import {PluginHostStatusBar} from 'vs/workbench/api/browser/pluginHostStatusBar'; import {PluginHostCommands} from 'vs/workbench/api/common/pluginHostCommands'; import {ExtHostOutputService} from 'vs/workbench/api/browser/extHostOutputService'; -import {LanguageFeatures} from 'vs/workbench/api/common/languageFeatures'; import {PluginHostMessageService} from 'vs/workbench/api/common/pluginHostMessageService'; import {PluginHostTelemetryService} from 'vs/workbench/api/common/pluginHostTelemetry'; import {PluginHostEditors} from 'vs/workbench/api/common/pluginHostEditors'; @@ -251,7 +250,6 @@ export class PluginHostAPIImplementation { // const languages = new ExtHostLanguages(this._threadService); const pluginHostDiagnostics = new PluginHostDiagnostics(this._threadService); - const features = LanguageFeatures.createExtensionHostInstances(this._threadService); const languageFeatures = threadService.getRemotable(ExtHostLanguageFeatures); this.languages = { diff --git a/src/vs/workbench/api/common/languageFeatures.ts b/src/vs/workbench/api/common/languageFeatures.ts deleted file mode 100644 index fa22152bcc6..00000000000 --- a/src/vs/workbench/api/common/languageFeatures.ts +++ /dev/null @@ -1,295 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * 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 URI from 'vs/base/common/uri'; -import Event, {Emitter} from 'vs/base/common/event'; -import Severity from 'vs/base/common/severity'; -import {TPromise} from 'vs/base/common/winjs.base'; -import {sequence} from 'vs/base/common/async'; -import {Range as EditorRange} from 'vs/editor/common/core/range'; -import {IDisposable} from 'vs/base/common/lifecycle'; -import {IKeybindingService} from 'vs/platform/keybinding/common/keybindingService'; -import {Remotable, IThreadService} from 'vs/platform/thread/common/thread'; -import * as vscode from 'vscode'; -import * as TypeConverters from 'vs/workbench/api/common/pluginHostTypeConverters'; -import {Position, Range, SymbolKind, DocumentHighlightKind, Disposable, Diagnostic, DiagnosticSeverity, Location, SignatureHelp, CompletionItemKind} from 'vs/workbench/api/common/pluginHostTypes'; -import {IPosition, IRange, ISingleEditOperation} from 'vs/editor/common/editorCommon'; -import * as modes from 'vs/editor/common/modes'; -import {CancellationTokenSource} from 'vs/base/common/cancellation'; -import {PluginHostModelService} from 'vs/workbench/api/common/pluginHostDocuments'; -import {IMarkerService, IMarker} from 'vs/platform/markers/common/markers'; -import {PluginHostCommands, MainThreadCommands} from 'vs/workbench/api/common/pluginHostCommands'; -import LanguageFeatureRegistry from 'vs/editor/common/modes/languageFeatureRegistry'; -import {NavigateTypesSupportRegistry, INavigateTypesSupport, ITypeBearing} from 'vs/workbench/parts/search/common/search' -import {RenameRegistry} from 'vs/editor/contrib/rename/common/rename'; -import {FormatRegistry, FormatOnTypeRegistry} from 'vs/editor/contrib/format/common/format'; -import {ParameterHintsRegistry} from 'vs/editor/contrib/parameterHints/common/parameterHints'; -import {SuggestRegistry} from 'vs/editor/contrib/suggest/common/suggest'; - -function isThenable(obj: any): obj is Thenable { - return obj && typeof obj['then'] === 'function'; -} - -function asWinJsPromise(callback: (token: vscode.CancellationToken) => T | Thenable): TPromise { - let source = new CancellationTokenSource(); - return new TPromise((resolve, reject) => { - let item = callback(source.token); - if (isThenable(item)) { - item.then(resolve, reject); - } else { - resolve(item); - } - }, () => { - source.cancel(); - }); -} - -export abstract class AbstractMainThreadFeature { - - private _id: string; - protected _commands: PluginHostCommands; - protected _refCount = 0; - protected _disposable: IDisposable; - protected _registry: LanguageFeatureRegistry; - - constructor(id: string, registry: LanguageFeatureRegistry, @IThreadService threadService: IThreadService) { - this._id = id; - this._registry = registry; - this._commands = threadService.getRemotable(PluginHostCommands); - } - - _getId(): TPromise { - return TPromise.as(this._id); - } - - _register(selector: vscode.DocumentSelector): TPromise { - if (this._refCount++ === 0) { - this._disposable = this._registry.register(selector, this); - } - return undefined; - } - - _unregister(): TPromise { - if (--this._refCount === 0) { - this._disposable.dispose(); - } - return undefined; - } - - _executeCommand(...args:any[]):TPromise { - let result = this._commands.executeCommand(this._id, ...args); - return new TPromise((c, e) => { - result.then(c, e); - }); - } -} - -export abstract class AbstractExtensionHostFeature> { - - protected _commands: PluginHostCommands; - protected _proxy: P; - protected _registry = new LanguageFeatureRegistry(); - protected _models: PluginHostModelService; - - constructor(proxy: P, @IThreadService threadService: IThreadService) { - this._proxy = proxy; - this._models = threadService.getRemotable(PluginHostModelService); - this._commands = threadService.getRemotable(PluginHostCommands); - - proxy._getId().then(value => this._commands.registerCommand(value, this._runAsCommand, this)); - } - - register(selector: vscode.DocumentSelector, provider: T): vscode.Disposable { - - let disposable = this._registry.register(selector, provider); - let registered = this._proxy._register(selector); - - return new Disposable(() => { - disposable.dispose(); // remove locally - registered.then(() => this._proxy._unregister()); - }); - } - - protected abstract _runAsCommand(...args: any[]): any; - - protected _getAllFor(document: vscode.TextDocument): T[] { - return this._registry.all({ - language: document.languageId, - uri: document.uri - }); - } - - protected _getOrderedFor(document: vscode.TextDocument): T[] { - return this._registry.ordered({ - language: document.languageId, - uri: document.uri - }); - } -} - - -// --- format - -export class ExtHostFormatDocument extends AbstractExtensionHostFeature { - - constructor( @IThreadService threadService: IThreadService) { - super(threadService.getRemotable(MainThreadFormatDocument), threadService); - } - - _runAsCommand(resource: URI, options: modes.IFormattingOptions): TPromise { - - let document = this._models.getDocument(resource); - let provider = this._getOrderedFor(document)[0]; - - return asWinJsPromise(token => provider.provideDocumentFormattingEdits(document, options, token)).then(result => { - if (Array.isArray(result)) { - return result.map(ExtHostFormatDocument.convertTextEdit); - } - }); - } - - static convertTextEdit(edit: vscode.TextEdit): ISingleEditOperation { - return { - text: edit.newText, - range: TypeConverters.fromRange(edit.range) - } - } -} - -@Remotable.MainContext('MainThreadFormatDocument') -export class MainThreadFormatDocument extends AbstractMainThreadFeature implements modes.IFormattingSupport { - - constructor( @IThreadService threadService: IThreadService) { - super('vscode.executeFormatDocumentProvider', FormatRegistry, threadService); - } - - formatDocument(resource: URI, options: modes.IFormattingOptions):TPromise { - return this._executeCommand(resource, options); - } -} - -export class ExtHostFormatRange extends AbstractExtensionHostFeature { - - constructor( @IThreadService threadService: IThreadService) { - super(threadService.getRemotable(MainThreadFormatRange), threadService); - } - - _runAsCommand(resource: URI, range: IRange, options: modes.IFormattingOptions): TPromise { - - let document = this._models.getDocument(resource); - let provider = this._getOrderedFor(document)[0]; - let ran: Range; - - if (range) { - ran = TypeConverters.toRange(range); - } else { - let lastLine = document.lineAt(document.lineCount - 1); - let {line, character} = lastLine.range.end; - ran = new Range(0, 0, line, character); - } - - return asWinJsPromise(token => provider.provideDocumentRangeFormattingEdits(document, ran, options, token)).then(result => { - if (Array.isArray(result)) { - return result.map(ExtHostFormatDocument.convertTextEdit); - } - }); - } -} - -@Remotable.MainContext('MainThreadFormatRange') -export class MainThreadFormatRange extends AbstractMainThreadFeature implements modes.IFormattingSupport { - - constructor( @IThreadService threadService: IThreadService) { - super('vscode.executeFormatRangeProvider', FormatRegistry, threadService); - } - - formatRange(resource: URI, range:IRange, options: modes.IFormattingOptions):TPromise { - return this._executeCommand(resource, range, options); - } -} - -// --- format on type - -export interface FormatOnTypeEntry { - triggerCharacters: string[]; - provider: vscode.OnTypeFormattingEditProvider; -} - -export class ExtHostFormatOnType extends AbstractExtensionHostFeature { - - constructor( @IThreadService threadService: IThreadService) { - super(threadService.getRemotable(MainThreadFormatOnType), threadService); - } - - register(selector: vscode.DocumentSelector, provider: FormatOnTypeEntry): vscode.Disposable { - - let disposable = this._registry.register(selector, provider); - let registered = this._proxy._register(selector, provider.triggerCharacters); - - return new Disposable(() => { - disposable.dispose(); - registered.then(() => this._proxy._unregister()); - }); - } - - _runAsCommand(resource: URI, position: IPosition, ch: string, options: modes.IFormattingOptions): TPromise { - - let document = this._models.getDocument(resource); - let pos = TypeConverters.toPosition(position); - - let ordered = this._getOrderedFor(document); - let provider: vscode.OnTypeFormattingEditProvider; - for (let entry of ordered) { - if (entry.triggerCharacters.indexOf(ch) >= 0) { - provider = entry.provider; - break; - } - } - - if (provider) { - return asWinJsPromise(token => provider.provideOnTypeFormattingEdits(document, pos, ch, options, token)).then(result => { - if (Array.isArray(result)) { - return result.map(ExtHostFormatDocument.convertTextEdit); - } - }); - } - } -} - -@Remotable.MainContext('MainThreadFormatOnType') -export class MainThreadFormatOnType extends AbstractMainThreadFeature implements modes.IFormattingSupport { - - autoFormatTriggerCharacters: string[] = []; - - constructor( @IThreadService threadService: IThreadService) { - super('vscode.executeFormatOnTypeProvider', FormatOnTypeRegistry, threadService); - } - - _register(selector: vscode.DocumentSelector, triggerCharacters: string[] = []): TPromise { - this.autoFormatTriggerCharacters.push(...triggerCharacters); - return super._register(selector); - } - - formatDocument(resource: URI, options: modes.IFormattingOptions):TPromise { - throw new Error('format on type only'); - } - - formatAfterKeystroke(resource: URI, position: IPosition, ch: string, options: modes.IFormattingOptions): TPromise { - return this._executeCommand(resource, position, ch, options); - } -} - - -export namespace LanguageFeatures { - - export function createMainThreadInstances(threadService: IThreadService): void { - } - - export function createExtensionHostInstances(threadService: IThreadService) { - return { - }; - } -} \ No newline at end of file diff --git a/src/vs/workbench/electron-browser/shell.ts b/src/vs/workbench/electron-browser/shell.ts index d463ad5bb6f..6046a64f19c 100644 --- a/src/vs/workbench/electron-browser/shell.ts +++ b/src/vs/workbench/electron-browser/shell.ts @@ -67,7 +67,6 @@ import {MainThreadLanguages} from 'vs/workbench/api/common/extHostLanguages'; import {MainThreadEditors} from 'vs/workbench/api/common/pluginHostEditors'; import {MainThreadWorkspace} from 'vs/workbench/api/browser/pluginHostWorkspace'; import {MainThreadConfiguration} from 'vs/workbench/api/common/pluginHostConfiguration'; -import {LanguageFeatures} from 'vs/workbench/api/common/languageFeatures'; import {MainThreadLanguageFeatures} from 'vs/workbench/api/common/extHostLanguageFeatures'; import {EventService} from 'vs/platform/event/common/eventService'; import {IOptions} from 'vs/workbench/common/options'; @@ -338,7 +337,6 @@ export class WorkbenchShell { this.threadServiceInstance.getRemotable(MainThreadEditors); this.threadServiceInstance.getRemotable(MainThreadStorage); this.threadServiceInstance.getRemotable(MainThreadLanguageFeatures); - LanguageFeatures.createMainThreadInstances(this.threadServiceInstance); } public open(): void {