Hello Code

This commit is contained in:
Erich Gamma
2015-11-13 14:39:38 +01:00
commit 8f35cc4768
1897 changed files with 704173 additions and 0 deletions

View File

@@ -0,0 +1,111 @@
/*---------------------------------------------------------------------------------------------
* 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 {Remotable, IThreadService} from 'vs/platform/thread/common/thread';
import {IOutputService, OUTPUT_MODE_ID} from 'vs/workbench/parts/output/common/output';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {Position} from 'vs/platform/editor/common/editor';
import * as TypeConverters from 'vs/workbench/api/common/pluginHostTypeConverters';
export class ExtHostOutputChannel implements vscode.OutputChannel {
private _proxy: MainThreadOutputService;
private _name: string;
private _disposed: boolean;
constructor(name: string, proxy: MainThreadOutputService) {
this._name = name;
this._proxy = proxy;
}
get name(): string {
return this._name;
}
dispose(): void {
if (!this._disposed) {
this._proxy.clear(this._name).then(() => {
this._disposed = true;
});
}
}
append(value: string): void {
this._proxy.append(this._name, value);
}
appendLine(value: string): void {
this.append(value + '\n');
}
clear(): void {
this._proxy.clear(this._name);
}
show(column?: vscode.ViewColumn): void {
this._proxy.reveal(this._name, TypeConverters.fromViewColumn(column));
}
hide(): void {
this._proxy.close(this._name);
}
}
export class ExtHostOutputService {
private _proxy: MainThreadOutputService;
constructor(threadService: IThreadService) {
this._proxy = threadService.getRemotable(MainThreadOutputService);
}
createOutputChannel(name: string): vscode.OutputChannel {
name = name.trim();
if (!name) {
throw new Error('illegal argument `name`. must not be falsy');
} else {
return new ExtHostOutputChannel(name, this._proxy);
}
}
}
@Remotable.MainContext('MainThreadOutputService')
export class MainThreadOutputService {
private _outputService: IOutputService;
private _editorService: IWorkbenchEditorService;
constructor(@IOutputService outputService: IOutputService, editorService: IWorkbenchEditorService) {
this._outputService = outputService;
this._editorService = editorService;
}
public append(channel: string, value: string): TPromise<void> {
this._outputService.append(channel, value);
return undefined;
}
public clear(channel: string): TPromise<void> {
this._outputService.clearOutput(channel);
return undefined;
}
public reveal(channel: string, position: Position): TPromise<void> {
this._outputService.showOutput(channel, position);
return undefined;
}
public close(channel: string): TPromise<void> {
let editors = this._editorService.getVisibleEditors();
for (let editor of editors) {
if (editor.input.getId() === OUTPUT_MODE_ID) {
this._editorService.closeEditor(editor);
return;
}
}
}
}

View File

@@ -0,0 +1,526 @@
/*---------------------------------------------------------------------------------------------
* 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 {MainInplaceReplaceSupport, ReplaceSupport, IBracketElectricCharacterContribution} from 'vs/editor/common/modes/supports';
import {score} from 'vs/editor/common/modes/languageSelector';
import {Remotable, IThreadService} from 'vs/platform/thread/common/thread';
import * as errors from 'vs/base/common/errors';
import {PluginHostFileSystemEventService} from 'vs/workbench/api/common/pluginHostFileSystemEventService';
import {PluginHostModelService, setWordDefinitionFor} from 'vs/workbench/api/common/pluginHostDocuments';
import {PluginHostConfiguration} from 'vs/workbench/api/common/pluginHostConfiguration';
import {PluginHostDiagnostics} from 'vs/workbench/api/common/pluginHostDiagnostics';
import {PluginHostWorkspace} from 'vs/workbench/api/browser/pluginHostWorkspace';
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';
import {ExtHostLanguages} from 'vs/workbench/api/common/extHostLanguages';
import * as extHostTypes from 'vs/workbench/api/common/pluginHostTypes';
import 'vs/workbench/api/common/pluginHostTypes.marshalling';
import {wrapAsWinJSPromise} from 'vs/base/common/async';
import Modes = require('vs/editor/common/modes');
import {IModelService} from 'vs/editor/common/services/modelService';
import {IModeService} from 'vs/editor/common/services/modeService';
import {IDeclarationContribution, ISuggestContribution, IReferenceContribution, ICommentsSupportContribution, ITokenTypeClassificationSupportContribution} from 'vs/editor/common/modes/supports';
import {IOnEnterSupportOptions} from 'vs/editor/common/modes/supports/onEnter';
import URI from 'vs/base/common/uri';
import Severity from 'vs/base/common/severity';
import {IDisposable} from 'vs/base/common/lifecycle';
import EditorCommon = require('vs/editor/common/editorCommon');
import {IPluginService, IPluginDescription} from 'vs/platform/plugins/common/plugins';
import {PluginsRegistry} from 'vs/platform/plugins/common/pluginsRegistry';
import {relative} from 'path';
import {TPromise} from 'vs/base/common/winjs.base';
import * as TypeConverters from 'vs/workbench/api/common/pluginHostTypeConverters';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {CancellationTokenSource} from 'vs/base/common/cancellation';
import vscode = require('vscode');
import {TextEditorRevealType} from 'vs/workbench/api/common/mainThreadEditors';
import * as paths from 'vs/base/common/paths';
/**
* This class implements the API described in vscode.d.ts,
* for the case of the extensionHost host process
*/
export class PluginHostAPIImplementation {
private static _LAST_REGISTER_TOKEN = 0;
private static generateDisposeToken(): string {
return String(++PluginHostAPIImplementation._LAST_REGISTER_TOKEN);
}
private _threadService: IThreadService;
private _proxy: MainProcessVSCodeAPIHelper;
private _pluginService: IPluginService;
version: typeof vscode.version;
Uri: typeof vscode.Uri;
Location: typeof vscode.Location;
Diagnostic: typeof vscode.Diagnostic;
DiagnosticSeverity: typeof vscode.DiagnosticSeverity;
Disposable: typeof vscode.Disposable;
TextEdit: typeof vscode.TextEdit;
WorkspaceEdit: typeof vscode.WorkspaceEdit;
ViewColumn: typeof vscode.ViewColumn;
StatusBarAlignment: typeof vscode.StatusBarAlignment;
Position: typeof vscode.Position;
Range: typeof vscode.Range;
Selection: typeof vscode.Selection;
CancellationTokenSource: typeof vscode.CancellationTokenSource;
Hover: typeof vscode.Hover;
DocumentHighlightKind: typeof vscode.DocumentHighlightKind;
DocumentHighlight: typeof vscode.DocumentHighlight;
SymbolKind: typeof vscode.SymbolKind;
SymbolInformation: typeof vscode.SymbolInformation;
CodeLens: typeof vscode.CodeLens;
ParameterInformation: typeof vscode.ParameterInformation;
SignatureInformation: typeof vscode.SignatureInformation;
SignatureHelp: typeof vscode.SignatureHelp;
CompletionItem: typeof vscode.CompletionItem;
CompletionItemKind: typeof vscode.CompletionItemKind;
IndentAction: typeof vscode.IndentAction;
OverviewRulerLane: typeof vscode.OverviewRulerLane;
TextEditorRevealType: typeof vscode.TextEditorRevealType;
commands: typeof vscode.commands;
window: typeof vscode.window;
workspace: typeof vscode.workspace;
languages: typeof vscode.languages;
extensions: typeof vscode.extensions;
constructor(
@IThreadService threadService: IThreadService,
@IPluginService pluginService: IPluginService,
@IWorkspaceContextService contextService: IWorkspaceContextService
) {
this._pluginService = pluginService;
this._threadService = threadService;
this._proxy = threadService.getRemotable(MainProcessVSCodeAPIHelper);
this.version = contextService.getConfiguration().env.version;
this.commands = this._threadService.getRemotable(PluginHostCommands);
this.Uri = URI;
this.Location = extHostTypes.Location;
this.Diagnostic = <any> extHostTypes.Diagnostic;
this.DiagnosticSeverity = <any> extHostTypes.DiagnosticSeverity;
this.Disposable = extHostTypes.Disposable;
this.TextEdit = extHostTypes.TextEdit;
this.WorkspaceEdit = extHostTypes.WorkspaceEdit;
this.Position = extHostTypes.Position;
this.Range = extHostTypes.Range;
this.Selection = extHostTypes.Selection;
this.CancellationTokenSource = CancellationTokenSource;
this.Hover = extHostTypes.Hover;
this.SymbolKind = <any>extHostTypes.SymbolKind;
this.SymbolInformation = <any>extHostTypes.SymbolInformation;
this.DocumentHighlightKind = <any>extHostTypes.DocumentHighlightKind;
this.DocumentHighlight = <any>extHostTypes.DocumentHighlight;
this.CodeLens = extHostTypes.CodeLens;
this.ParameterInformation = extHostTypes.ParameterInformation;
this.SignatureInformation = extHostTypes.SignatureInformation;
this.SignatureHelp = extHostTypes.SignatureHelp;
this.CompletionItem = <any>extHostTypes.CompletionItem;
this.CompletionItemKind = <any>extHostTypes.CompletionItemKind;
this.ViewColumn = <any>extHostTypes.ViewColumn;
this.StatusBarAlignment = <any>extHostTypes.StatusBarAlignment;
this.IndentAction = <any>Modes.IndentAction;
this.OverviewRulerLane = <any>EditorCommon.OverviewRulerLane;
this.TextEditorRevealType = <any>TextEditorRevealType;
errors.setUnexpectedErrorHandler((err) => {
this._proxy.onUnexpectedPluginHostError(errors.transformErrorForSerialization(err));
});
const pluginHostEditors = this._threadService.getRemotable(PluginHostEditors);
const pluginHostMessageService = new PluginHostMessageService(this._threadService, this.commands);
const pluginHostQuickOpen = new PluginHostQuickOpen(this._threadService);
const pluginHostStatusBar = new PluginHostStatusBar(this._threadService);
const pluginHostTelemetryService = new PluginHostTelemetryService(threadService);
const extHostOutputService = new ExtHostOutputService(this._threadService);
this.window = {
get activeTextEditor() {
return pluginHostEditors.getActiveTextEditor();
},
get visibleTextEditors() {
return pluginHostEditors.getVisibleTextEditors();
},
showTextDocument(document: vscode.TextDocument, column: vscode.ViewColumn): TPromise<vscode.TextEditor> {
return pluginHostEditors.showTextDocument(document, column);
},
createTextEditorDecorationType(options:vscode.DecorationRenderOptions): vscode.TextEditorDecorationType {
return pluginHostEditors.createTextEditorDecorationType(options);
},
onDidChangeActiveTextEditor: pluginHostEditors.onDidChangeActiveTextEditor.bind(pluginHostEditors),
onDidChangeTextEditorSelection: (listener: (e: vscode.TextEditorSelectionChangeEvent) => any, thisArgs?: any, disposables?: extHostTypes.Disposable[]) => {
return pluginHostEditors.onDidChangeTextEditorSelection(listener, thisArgs, disposables);
},
onDidChangeTextEditorOptions: (listener: (e: vscode.TextEditorOptionsChangeEvent) => any, thisArgs?: any, disposables?: extHostTypes.Disposable[]) => {
return pluginHostEditors.onDidChangeTextEditorOptions(listener, thisArgs, disposables);
},
showInformationMessage: (message, ...items) => {
return pluginHostMessageService.showMessage(Severity.Info, message, items);
},
showWarningMessage: (message, ...items) => {
return pluginHostMessageService.showMessage(Severity.Warning, message, items);
},
showErrorMessage: (message, ...items) => {
return pluginHostMessageService.showMessage(Severity.Error, message, items);
},
showQuickPick: (items: any, options: vscode.QuickPickOptions) => {
return pluginHostQuickOpen.show(items, options);
},
showInputBox: pluginHostQuickOpen.input.bind(pluginHostQuickOpen),
createStatusBarItem(position?: vscode.StatusBarAlignment, priority?: number): vscode.StatusBarItem {
return pluginHostStatusBar.createStatusBarEntry(<number>position, priority);
},
setStatusBarMessage(text: string, timeoutOrThenable?: number | Thenable<any>): vscode.Disposable {
return pluginHostStatusBar.setStatusBarMessage(text, timeoutOrThenable);
},
createOutputChannel(name: string): vscode.OutputChannel {
return extHostOutputService.createOutputChannel(name);
}
};
//
const workspacePath = contextService.getWorkspace() && contextService.getWorkspace().resource.fsPath;
const pluginHostFileSystemEvent = threadService.getRemotable(PluginHostFileSystemEventService);
const pluginHostWorkspace = new PluginHostWorkspace(this._threadService, workspacePath);
const pluginHostDocuments = this._threadService.getRemotable(PluginHostModelService);
this.workspace = Object.freeze({
get rootPath() {
return pluginHostWorkspace.getPath();
},
set rootPath(value) {
throw errors.readonly();
},
asRelativePath: (pathOrUri) => {
return pluginHostWorkspace.getRelativePath(pathOrUri);
},
findFiles: (include, exclude, maxResults?) => {
return pluginHostWorkspace.findFiles(include, exclude, maxResults);
},
saveAll: (includeUntitled?) => {
return pluginHostWorkspace.saveAll(includeUntitled);
},
applyEdit(edit: vscode.WorkspaceEdit): TPromise<boolean> {
return pluginHostWorkspace.appyEdit(edit);
},
createFileSystemWatcher: (pattern, ignoreCreate, ignoreChange, ignoreDelete): vscode.FileSystemWatcher => {
return pluginHostFileSystemEvent.createFileSystemWatcher(pattern, ignoreCreate, ignoreChange, ignoreDelete);
},
get textDocuments() {
return pluginHostDocuments.getDocuments();
},
set textDocuments(value) {
throw errors.readonly();
},
// createTextDocument(text: string, fileName?: string, language?: string): Thenable<vscode.TextDocument> {
// return pluginHostDocuments.createDocument(text, fileName, language);
// },
openTextDocument(uriOrFileName:vscode.Uri | string) {
return pluginHostDocuments.openDocument(uriOrFileName);
},
onDidOpenTextDocument: (listener, thisArgs?, disposables?) => {
return pluginHostDocuments.onDidAddDocument(listener, thisArgs, disposables);
},
onDidCloseTextDocument: (listener, thisArgs?, disposables?) => {
return pluginHostDocuments.onDidRemoveDocument(listener, thisArgs, disposables);
},
onDidChangeTextDocument: (listener, thisArgs?, disposables?) => {
return pluginHostDocuments.onDidChangeDocument(listener, thisArgs, disposables);
},
onDidSaveTextDocument: (listener, thisArgs?, disposables?) => {
return pluginHostDocuments.onDidSaveDocument(listener, thisArgs, disposables);
},
onDidChangeConfiguration: (listener: () => any, thisArgs?: any, disposables?: extHostTypes.Disposable[]) => {
return pluginHostConfiguration.onDidChangeConfiguration(listener, thisArgs, disposables);
},
getConfiguration: (section?: string):vscode.WorkspaceConfiguration => {
return pluginHostConfiguration.getConfiguration(section);
}
});
//
const languages = new ExtHostLanguages(this._threadService);
const pluginHostDiagnostics = new PluginHostDiagnostics(this._threadService);
const features = LanguageFeatures.createExtensionHostInstances(this._threadService);
this.languages = {
createDiagnosticCollection(name?: string): vscode.DiagnosticCollection {
return pluginHostDiagnostics.createDiagnosticCollection(name);
},
getLanguages(): TPromise<string[]> {
return languages.getLanguages();
},
match(selector: vscode.DocumentSelector, document: vscode.TextDocument): number {
return score(selector, { uri: <any> document.uri, language: document.languageId });
},
registerCodeActionsProvider(selector: vscode.DocumentSelector, provider: vscode.CodeActionProvider): vscode.Disposable {
return features.codeActions.register(selector, provider);
},
registerCodeLensProvider(selector: vscode.DocumentSelector, provider: vscode.CodeLensProvider): vscode.Disposable {
return features.codeLens.register(selector, provider);
},
registerDefinitionProvider(selector: vscode.DocumentSelector, provider: vscode.DefinitionProvider): vscode.Disposable {
return features.definition.register(selector, provider);
},
registerHoverProvider(selector: vscode.DocumentSelector, provider: vscode.HoverProvider): vscode.Disposable {
return features.hover.register(selector, provider);
},
registerDocumentHighlightProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentHighlightProvider): vscode.Disposable {
return features.documentHighlight.register(selector, provider);
},
registerReferenceProvider(selector: vscode.DocumentSelector, provider: vscode.ReferenceProvider): vscode.Disposable {
return features.referenceSearch.register(selector, provider);
},
registerRenameProvider(selector: vscode.DocumentSelector, provider: vscode.RenameProvider): vscode.Disposable {
return features.rename.register(selector, provider);
},
registerDocumentSymbolProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentSymbolProvider): vscode.Disposable {
return features.documentSymbols.register(selector, provider);
},
registerWorkspaceSymbolProvider(provider: vscode.WorkspaceSymbolProvider): vscode.Disposable {
return features.workspaceSymbols.register(provider);
},
registerDocumentFormattingEditProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentFormattingEditProvider): vscode.Disposable {
return features.formatDocument.register(selector, provider);
},
registerDocumentRangeFormattingEditProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentRangeFormattingEditProvider): vscode.Disposable {
return features.formatRange.register(selector, provider);
},
registerOnTypeFormattingEditProvider(selector: vscode.DocumentSelector, provider: vscode.OnTypeFormattingEditProvider, firstTriggerCharacter: string, ...moreTriggerCharacters: string[]): vscode.Disposable {
return features.formatOnType.register(selector, { triggerCharacters: [firstTriggerCharacter].concat(moreTriggerCharacters), provider });
},
registerSignatureHelpProvider(selector: vscode.DocumentSelector, provider: vscode.SignatureHelpProvider, ...triggerCharacters: string[]): vscode.Disposable {
return features.signatureHelp.register(selector, { triggerCharacters, provider });
},
registerCompletionItemProvider(selector: vscode.DocumentSelector, provider: vscode.CompletionItemProvider, ...triggerCharacters: string[]): vscode.Disposable {
return features.completions.register(selector, { triggerCharacters, provider });
},
setLanguageConfiguration: (language: string, configuration: vscode.LanguageConfiguration):vscode.Disposable => {
return this._setLanguageConfiguration(language, configuration);
}
};
var pluginHostConfiguration = threadService.getRemotable(PluginHostConfiguration);
//
this.extensions = {
getExtension(extensionId: string):Extension<any> {
let desc = PluginsRegistry.getPluginDescription(extensionId);
if (desc) {
return new Extension(pluginService, desc);
}
},
get all():Extension<any>[] {
return PluginsRegistry.getAllPluginDescriptions().map((desc) => new Extension(pluginService, desc));
}
// getTelemetryInfo: pluginHostTelemetryService.getTelemetryInfo.bind(pluginHostTelemetryService)
}
// Intentionally calling a function for typechecking purposes
defineAPI(this);
}
private _disposableFromToken(disposeToken:string): IDisposable {
return new extHostTypes.Disposable(() => this._proxy.disposeByToken(disposeToken));
}
private _setLanguageConfiguration(modeId: string, configuration: vscode.LanguageConfiguration): vscode.Disposable {
let disposables: IDisposable[] = [];
let {comments, wordPattern} = configuration;
// comment configuration
if (comments) {
let lineCommentToken = comments.lineComment;
let contrib: ICommentsSupportContribution = { commentsConfiguration: {} };
if (comments.lineComment) {
contrib.commentsConfiguration.lineCommentTokens = [comments.lineComment];
}
if (comments.blockComment) {
let [blockStart, blockEnd] = comments.blockComment;
contrib.commentsConfiguration.blockCommentStartToken = blockStart;
contrib.commentsConfiguration.blockCommentEndToken = blockEnd;
}
let d = this.Modes_CommentsSupport_register(modeId, contrib);
disposables.push(d);
}
// word definition
if (wordPattern) {
setWordDefinitionFor(modeId, wordPattern);
let d = this.Modes_TokenTypeClassificationSupport_register(modeId, {
wordDefinition: wordPattern
});
disposables.push(d);
} else {
setWordDefinitionFor(modeId, null);
}
// on enter
let onEnter: IOnEnterSupportOptions = {};
let empty = true;
let {brackets, indentationRules, onEnterRules} = configuration;
if (brackets) {
empty = false;
onEnter.brackets = brackets.map(pair => {
let [open, close] = pair;
return { open, close };
});
}
if (indentationRules) {
empty = false;
onEnter.indentationRules = indentationRules;
}
if (onEnterRules) {
empty = false;
onEnter.regExpRules = <any>onEnterRules;
}
if (!empty) {
let d = this.Modes_OnEnterSupport_register(modeId, onEnter);
disposables.push(d);
}
if (configuration.__electricCharacterSupport) {
disposables.push(
this.Modes_ElectricCharacterSupport_register(modeId, configuration.__electricCharacterSupport)
);
}
if (configuration.__characterPairSupport) {
disposables.push(
this.Modes_CharacterPairSupport_register(modeId, configuration.__characterPairSupport)
);
}
return extHostTypes.Disposable.from(...disposables);
}
private Modes_CommentsSupport_register(modeId: string, commentsSupport: ICommentsSupportContribution): IDisposable {
let disposeToken = PluginHostAPIImplementation.generateDisposeToken();
this._proxy.Modes_CommentsSupport_register(disposeToken, modeId, commentsSupport);
return this._disposableFromToken(disposeToken);
}
private Modes_TokenTypeClassificationSupport_register(modeId: string, tokenTypeClassificationSupport:ITokenTypeClassificationSupportContribution): IDisposable {
let disposeToken = PluginHostAPIImplementation.generateDisposeToken();
this._proxy.Modes_TokenTypeClassificationSupport_register(disposeToken, modeId, tokenTypeClassificationSupport);
return this._disposableFromToken(disposeToken);
}
private Modes_ElectricCharacterSupport_register(modeId: string, electricCharacterSupport:IBracketElectricCharacterContribution): IDisposable {
let disposeToken = PluginHostAPIImplementation.generateDisposeToken();
this._proxy.Modes_ElectricCharacterSupport_register(disposeToken, modeId, electricCharacterSupport);
return this._disposableFromToken(disposeToken);
}
private Modes_CharacterPairSupport_register(modeId: string, characterPairSupport:Modes.ICharacterPairContribution): IDisposable {
let disposeToken = PluginHostAPIImplementation.generateDisposeToken();
this._proxy.Modes_CharacterPairSupport_register(disposeToken, modeId, characterPairSupport);
return this._disposableFromToken(disposeToken);
}
private Modes_OnEnterSupport_register(modeId: string, opts: IOnEnterSupportOptions): IDisposable {
let disposeToken = PluginHostAPIImplementation.generateDisposeToken();
this._proxy.Modes_OnEnterSupport_register(disposeToken, modeId, opts);
return this._disposableFromToken(disposeToken);
}
}
class Extension<T> implements vscode.Extension<T> {
private _pluginService: IPluginService;
public id: string;
public extensionPath: string;
public packageJSON: any;
constructor(pluginService:IPluginService, description:IPluginDescription) {
this._pluginService = pluginService;
this.id = description.id;
this.extensionPath = paths.normalize(description.extensionFolderPath, true);
this.packageJSON = description;
}
get isActive(): boolean {
return this._pluginService.isActivated(this.id);
}
get exports(): T {
return this._pluginService.get(this.id);
}
activate(): Thenable<T> {
return this._pluginService.activateAndGet<T>(this.id);
}
}
function defineAPI(impl: typeof vscode) {
var node_module = <any>require.__$__nodeRequire('module');
var original = node_module._load;
node_module._load = function load(request, parent, isMain) {
if (request === 'vscode') {
return impl;
}
return original.apply(this, arguments);
};
define('vscode', [], impl);
}
@Remotable.MainContext('MainProcessVSCodeAPIHelper')
export class MainProcessVSCodeAPIHelper {
protected _modeService: IModeService;
private _token2Dispose: {
[token:string]: IDisposable;
};
constructor(
@IModeService modeService: IModeService
) {
this._modeService = modeService;
this._token2Dispose = {};
}
public onUnexpectedPluginHostError(err: any): void {
errors.onUnexpectedError(err);
}
public disposeByToken(disposeToken:string): void {
if (this._token2Dispose[disposeToken]) {
this._token2Dispose[disposeToken].dispose();
delete this._token2Dispose[disposeToken];
}
}
public Modes_CommentsSupport_register(disposeToken:string, modeId: string, commentsSupport: ICommentsSupportContribution): void {
this._token2Dispose[disposeToken] = this._modeService.registerDeclarativeCommentsSupport(modeId, commentsSupport);
}
public Modes_TokenTypeClassificationSupport_register(disposeToken:string, modeId: string, tokenTypeClassificationSupport:ITokenTypeClassificationSupportContribution): void {
this._token2Dispose[disposeToken] = this._modeService.registerDeclarativeTokenTypeClassificationSupport(modeId, tokenTypeClassificationSupport);
}
public Modes_ElectricCharacterSupport_register(disposeToken:string, modeId: string, electricCharacterSupport:IBracketElectricCharacterContribution): void {
this._token2Dispose[disposeToken] = this._modeService.registerDeclarativeElectricCharacterSupport(modeId, electricCharacterSupport);
}
public Modes_CharacterPairSupport_register(disposeToken:string, modeId: string, characterPairSupport:Modes.ICharacterPairContribution): void {
this._token2Dispose[disposeToken] = this._modeService.registerDeclarativeCharacterPairSupport(modeId, characterPairSupport);
}
public Modes_OnEnterSupport_register(disposeToken:string, modeId: string, opts:IOnEnterSupportOptions): void {
this._token2Dispose[disposeToken] = this._modeService.registerDeclarativeOnEnterSupport(modeId, <any>opts);
}
}

View File

@@ -0,0 +1,119 @@
/*---------------------------------------------------------------------------------------------
* 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 {Remotable, IThreadService} from 'vs/platform/thread/common/thread';
import {IQuickOpenService, IPickOpenEntryItem, IPickOptions} from 'vs/workbench/services/quickopen/browser/quickOpenService';
import {QuickPickOptions, QuickPickItem, InputBoxOptions} from 'vscode';
export interface MyQuickPickItems extends IPickOpenEntryItem {
handle: number;
}
export type Item = string | QuickPickItem;
export class PluginHostQuickOpen {
private _proxy: MainThreadQuickOpen;
constructor(@IThreadService threadService: IThreadService) {
this._proxy = threadService.getRemotable(MainThreadQuickOpen);
}
show(items: Item[] | Thenable<Item[]>, options?: QuickPickOptions): Thenable<Item> {
let itemsPromise: Thenable<Item[]>;
if (!Array.isArray(items)) {
itemsPromise = items;
} else {
itemsPromise = TPromise.as(items);
}
let quickPickWidget = this._proxy._show({
autoFocus: { autoFocusFirstEntry: true },
placeHolder: options && options.placeHolder,
matchOnDescription: options && options.matchOnDescription
});
return itemsPromise.then(items => {
let pickItems: MyQuickPickItems[] = [];
for (let handle = 0; handle < items.length; handle++) {
let item = items[handle];
let label: string;
let description: string;
if (typeof item === 'string') {
label = item;
} else {
label = item.label;
description = item.description;
}
pickItems.push({
label,
description,
handle
});
}
this._proxy._setItems(pickItems);
return quickPickWidget.then(handle => {
if (typeof handle === 'number') {
return items[handle];
}
});
});
}
input(options?: InputBoxOptions): Thenable<string> {
return this._proxy._input(options);
}
}
@Remotable.MainContext('MainThreadQuickOpen')
export class MainThreadQuickOpen {
private _quickOpenService: IQuickOpenService;
private _doSetItems: (items: MyQuickPickItems[]) => any;
private _contents: TPromise<MyQuickPickItems[]>;
private _token = 0;
constructor(@IQuickOpenService quickOpenService: IQuickOpenService) {
this._quickOpenService = quickOpenService;
}
_show(options: IPickOptions): Thenable<number> {
const myToken = ++this._token;
this._contents = new TPromise((c, e) => {
this._doSetItems = (items) => {
if (myToken === this._token) {
c(items);
}
};
});
return this._quickOpenService.pick(this._contents, options).then(item => {
if (item) {
return item.handle;
}
});
}
_setItems(items: MyQuickPickItems[]): Thenable<any> {
if (this._doSetItems) {
this._doSetItems(items);
return;
}
}
_input(options?: InputBoxOptions): Thenable<string> {
return this._quickOpenService.input(options);
}
}

View File

@@ -0,0 +1,221 @@
/*---------------------------------------------------------------------------------------------
* 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 {Remotable, IThreadService} from 'vs/platform/thread/common/thread';
import {IStatusbarService} from 'vs/workbench/services/statusbar/statusbarService';
import {IDisposable, disposeAll} from 'vs/base/common/lifecycle';
import {StatusbarAlignment as MainThreadStatusBarAlignment} from 'vs/workbench/browser/parts/statusbar/statusbar';
import {StatusBarAlignment as ExtHostStatusBarAlignment, Disposable} from '../common/pluginHostTypes';
import {StatusBarItem, StatusBarAlignment} from 'vscode';
export class PluginHostStatusBarEntry implements StatusBarItem {
private static ID_GEN = 0;
private _id: number;
private _alignment: number;
private _priority: number;
private _disposed: boolean;
private _visible: boolean;
private _text: string;
private _tooltip: string;
private _color: string;
private _command: string;
private _timeoutHandle: number;
private _proxy: MainThreadStatusBar;
constructor(proxy: MainThreadStatusBar, alignment: ExtHostStatusBarAlignment = ExtHostStatusBarAlignment.Left, priority?: number) {
this._id = PluginHostStatusBarEntry.ID_GEN++;
this._proxy = proxy;
this._alignment = alignment;
this._priority = priority;
}
public get id(): number {
return this._id;
}
public get alignment(): StatusBarAlignment {
return this._alignment;
}
public get priority(): number {
return this._priority;
}
public get text(): string {
return this._text;
}
public get tooltip(): string {
return this._tooltip;
}
public get color(): string {
return this._color;
}
public get command(): string {
return this._command;
}
public set text(text: string) {
this._text = text;
this.update();
}
public set tooltip(tooltip: string) {
this._tooltip = tooltip;
this.update();
}
public set color(color: string) {
this._color = color;
this.update();
}
public set command(command: string) {
this._command = command;
this.update();
}
public show(): void {
this._visible = true;
this.update();
}
public hide(): void {
this._visible = false;
this._proxy.dispose(this.id);
}
private update(): void {
if (this._disposed || !this._visible) {
return;
}
if (this._timeoutHandle) {
clearTimeout(this._timeoutHandle);
}
// Defer the update so that multiple changes to setters dont cause a redraw each
this._timeoutHandle = setTimeout(() => {
delete this._timeoutHandle;
// Set to status bar
this._proxy.setEntry(this.id, this.text, this.tooltip, this.command, this.color,
this._alignment === ExtHostStatusBarAlignment.Left ? MainThreadStatusBarAlignment.LEFT : MainThreadStatusBarAlignment.RIGHT,
this._priority);
}, 0);
}
public dispose(): void {
this.hide();
this._disposed = true;
}
}
class StatusBarMessage {
private _item: StatusBarItem;
private _messages: {message:string}[] = [];
constructor(statusBar: PluginHostStatusBar) {
this._item = statusBar.createStatusBarEntry(ExtHostStatusBarAlignment.Left, Number.MIN_VALUE);
}
dispose() {
this._messages.length = 0;
this._item.dispose();
}
setMessage(message: string): Disposable {
const data: { message: string } = { message }; // use object to not confuse equal strings
this._messages.unshift(data);
this._update();
return new Disposable(() => {
let idx = this._messages.indexOf(data);
if (idx >= 0) {
this._messages.splice(idx, 1);
this._update();
}
});
}
private _update() {
if (this._messages.length > 0) {
this._item.text = this._messages[0].message;
this._item.show();
} else {
this._item.hide();
}
}
}
export class PluginHostStatusBar {
private _proxy: MainThreadStatusBar;
private _statusMessage: StatusBarMessage;
constructor( @IThreadService threadService: IThreadService) {
this._proxy = threadService.getRemotable(MainThreadStatusBar);
this._statusMessage = new StatusBarMessage(this);
}
createStatusBarEntry(alignment?: ExtHostStatusBarAlignment, priority?: number): StatusBarItem {
return new PluginHostStatusBarEntry(this._proxy, alignment, priority);
}
setStatusBarMessage(text: string, timeoutOrThenable?: number | Thenable<any>): Disposable {
let d = this._statusMessage.setMessage(text);
let handle: number;
if (typeof timeoutOrThenable === 'number') {
handle = setTimeout(() => d.dispose(), timeoutOrThenable);
} else if (typeof timeoutOrThenable !== 'undefined') {
timeoutOrThenable.then(() => d.dispose(), () => d.dispose());
}
return new Disposable(() => {
d.dispose();
clearTimeout(handle);
});
}
}
@Remotable.MainContext('MainThreadStatusBar')
export class MainThreadStatusBar {
private mapIdToDisposable: { [id:number]: IDisposable };
constructor(
@IStatusbarService private statusbarService: IStatusbarService
) {
this.mapIdToDisposable = Object.create(null);
}
setEntry(id: number, text: string, tooltip: string, command: string, color: string, alignment: MainThreadStatusBarAlignment, priority: number): void {
// Dispose any old
this.dispose(id);
// Add new
let disposeable = this.statusbarService.addEntry({ text, tooltip, command, color }, alignment, priority);
this.mapIdToDisposable[id] = disposeable;
}
dispose(id: number) {
let disposeable = this.mapIdToDisposable[id];
if (disposeable) {
disposeable.dispose();
}
delete this.mapIdToDisposable[id];
}
}

View File

@@ -0,0 +1,142 @@
/*---------------------------------------------------------------------------------------------
* 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 {ISearchService, QueryType} from 'vs/platform/search/common/search';
import {IWorkspaceContextService, IWorkspace} from 'vs/platform/workspace/common/workspace';
import {Remotable, IThreadService} from 'vs/platform/thread/common/thread';
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
import {IEventService} from 'vs/platform/event/common/event';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {ITextFileService, ITextFileOperationResult} from 'vs/workbench/parts/files/common/files';
import {Uri, FileSystemWatcher} from 'vscode';
import {ICodeEditor} from 'vs/editor/browser/editorBrowser';
import {bulkEdit, IResourceEdit} from 'vs/editor/common/services/bulkEdit';
import {TPromise} from 'vs/base/common/winjs.base';
import {fromRange} from 'vs/workbench/api/common/pluginHostTypeConverters';
export class PluginHostWorkspace {
private _proxy: MainThreadWorkspace;
private _workspacePath: string;
constructor( @IThreadService threadService: IThreadService, workspacePath:string) {
this._proxy = threadService.getRemotable(MainThreadWorkspace);
this._workspacePath = workspacePath;
}
getPath(): string {
return this._workspacePath;
}
getRelativePath(pathOrUri: string|Uri): string {
let path: string;
if (typeof pathOrUri === 'string') {
path = pathOrUri;
} else {
path = pathOrUri.fsPath;
}
if (this._workspacePath && this._workspacePath.length < path.length) {
// return relative(workspacePath, path);
return path.substring(this._workspacePath.length);
}
return path
}
findFiles(include: string, exclude: string, maxResults?:number): Thenable<Uri[]> {
return this._proxy.findFiles(include, exclude, maxResults);
}
saveAll(includeUntitled?: boolean): Thenable<boolean> {
return this._proxy.saveAll(includeUntitled);
}
appyEdit(edit: vscode.WorkspaceEdit): TPromise<boolean> {
let resourceEdits: IResourceEdit[] = [];
let entries = edit.entries();
for (let entry of entries) {
let [uri, edits] = entry;
for (let edit of edits) {
resourceEdits.push({
resource: <URI>uri,
newText: edit.newText,
range: fromRange(edit.range)
});
}
}
return this._proxy.applyWorkspaceEdit(resourceEdits);
}
}
@Remotable.MainContext('MainThreadWorkspace')
export class MainThreadWorkspace {
private _searchService: ISearchService;
private _workspace: IWorkspace;
private _textFileService: ITextFileService;
private _editorService:IWorkbenchEditorService;
private _eventService:IEventService;
constructor( @ISearchService searchService: ISearchService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@ITextFileService textFileService,
@IWorkbenchEditorService editorService,
@IEventService eventService) {
this._searchService = searchService;
this._workspace = contextService.getWorkspace();
this._textFileService = textFileService;
this._editorService = editorService;
this._eventService = eventService;
}
findFiles(include: string, exclude: string, maxResults?: number): Thenable<Uri[]> {
if (!this._workspace) {
return;
}
return this._searchService.search({
rootResources: [this._workspace.resource],
type: QueryType.File,
maxResults: 100,
includePattern: { [include]: true },
excludePattern: { [exclude]: true },
}).then(result => {
return result.results.map(m => m.resource);
});
}
saveAll(includeUntitled?: boolean): Thenable<boolean> {
return this._textFileService.saveAll(includeUntitled).then(result => {
return result.results.every(each => each.success === true);;
});
}
applyWorkspaceEdit(edits: IResourceEdit[]): TPromise<boolean> {
let codeEditor: ICodeEditor;
let editor = this._editorService.getActiveEditor();
if (editor) {
let candidate = <ICodeEditor> editor.getControl();
if (typeof candidate.getEditorType === 'function') {
// enough proof
codeEditor = candidate;
}
}
return bulkEdit(this._eventService, this._editorService, codeEditor, edits)
.then(() => true);
}
}