mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 10:38:59 +01:00
Merge branch 'master' into ben/debt
This commit is contained in:
@@ -466,7 +466,7 @@ function createExtensionPathIndex(extensionService: ExtHostExtensionService): TP
|
||||
function defineAPI(factory: IExtensionApiFactory, extensionPaths: TrieMap<IExtensionDescription>): void {
|
||||
|
||||
// each extension is meant to get its own api implementation
|
||||
const extApiImpl: { [id: string]: typeof vscode } = Object.create(null);
|
||||
const extApiImpl = new Map<string, typeof vscode>();
|
||||
let defaultApiImpl: typeof vscode;
|
||||
|
||||
const node_module = <any>require.__$__nodeRequire('module');
|
||||
@@ -479,9 +479,10 @@ function defineAPI(factory: IExtensionApiFactory, extensionPaths: TrieMap<IExten
|
||||
// get extension id from filename and api for extension
|
||||
const ext = extensionPaths.findSubstr(parent.filename);
|
||||
if (ext) {
|
||||
let apiImpl = extApiImpl[ext.id];
|
||||
let apiImpl = extApiImpl.get(ext.id);
|
||||
if (!apiImpl) {
|
||||
apiImpl = extApiImpl[ext.id] = factory(ext);
|
||||
apiImpl = factory(ext);
|
||||
extApiImpl.set(ext.id, apiImpl);
|
||||
}
|
||||
return apiImpl;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ interface CommandHandler {
|
||||
|
||||
export class ExtHostCommands extends ExtHostCommandsShape {
|
||||
|
||||
private _commands: { [n: string]: CommandHandler } = Object.create(null);
|
||||
private _commands = new Map<string, CommandHandler>();
|
||||
private _proxy: MainThreadCommandsShape;
|
||||
private _extHostEditors: ExtHostEditors;
|
||||
private _converter: CommandsConverter;
|
||||
@@ -52,15 +52,15 @@ export class ExtHostCommands extends ExtHostCommandsShape {
|
||||
throw new Error('invalid id');
|
||||
}
|
||||
|
||||
if (this._commands[id]) {
|
||||
if (this._commands.has(id)) {
|
||||
throw new Error('command with id already exists');
|
||||
}
|
||||
|
||||
this._commands[id] = { callback, thisArg, description };
|
||||
this._commands.set(id, { callback, thisArg, description });
|
||||
this._proxy.$registerCommand(id);
|
||||
|
||||
return new extHostTypes.Disposable(() => {
|
||||
if (delete this._commands[id]) {
|
||||
if (this._commands.delete(id)) {
|
||||
this._proxy.$unregisterCommand(id);
|
||||
}
|
||||
});
|
||||
@@ -68,7 +68,7 @@ export class ExtHostCommands extends ExtHostCommandsShape {
|
||||
|
||||
executeCommand<T>(id: string, ...args: any[]): Thenable<T> {
|
||||
|
||||
if (this._commands[id]) {
|
||||
if (this._commands.has(id)) {
|
||||
// we stay inside the extension host and support
|
||||
// to pass any kind of parameters around
|
||||
return this.$executeContributedCommand(id, ...args);
|
||||
@@ -97,7 +97,7 @@ export class ExtHostCommands extends ExtHostCommandsShape {
|
||||
}
|
||||
|
||||
$executeContributedCommand<T>(id: string, ...args: any[]): Thenable<T> {
|
||||
let command = this._commands[id];
|
||||
let command = this._commands.get(id);
|
||||
if (!command) {
|
||||
return TPromise.wrapError<T>(`Contributed command '${id}' does not exist.`);
|
||||
}
|
||||
@@ -139,12 +139,12 @@ export class ExtHostCommands extends ExtHostCommandsShape {
|
||||
|
||||
$getContributedCommandHandlerDescriptions(): TPromise<{ [id: string]: string | ICommandHandlerDescription }> {
|
||||
const result: { [id: string]: string | ICommandHandlerDescription } = Object.create(null);
|
||||
for (let id in this._commands) {
|
||||
let {description} = this._commands[id];
|
||||
this._commands.forEach((command, id) => {
|
||||
let {description} = command;
|
||||
if (description) {
|
||||
result[id] = description;
|
||||
}
|
||||
}
|
||||
});
|
||||
return TPromise.as(result);
|
||||
}
|
||||
}
|
||||
@@ -212,4 +212,4 @@ export class CommandsConverter {
|
||||
return this._commands.executeCommand(actualCmd.command, ...actualCmd.arguments);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,13 @@ import { DiagnosticSeverity } from './extHostTypes';
|
||||
|
||||
export class DiagnosticCollection implements vscode.DiagnosticCollection {
|
||||
|
||||
private static _maxDiagnosticsPerFile: number = 250;
|
||||
private static readonly _maxDiagnosticsPerFile: number = 250;
|
||||
|
||||
private readonly _name: string;
|
||||
|
||||
private _name: string;
|
||||
private _proxy: MainThreadDiagnosticsShape;
|
||||
|
||||
private _isDisposed = false;
|
||||
private _data: { [uri: string]: vscode.Diagnostic[] } = Object.create(null);
|
||||
private _data = new Map<string, vscode.Diagnostic[]>();
|
||||
|
||||
constructor(name: string, proxy: MainThreadDiagnosticsShape) {
|
||||
this._name = name;
|
||||
@@ -66,7 +66,7 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection {
|
||||
}
|
||||
|
||||
// update single row
|
||||
this._data[first.toString()] = diagnostics;
|
||||
this._data.set(first.toString(), diagnostics);
|
||||
toSync = [first];
|
||||
|
||||
} else if (Array.isArray(first)) {
|
||||
@@ -83,19 +83,19 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection {
|
||||
for (const {tuple} of sortedTuples) {
|
||||
const [uri, diagnostics] = tuple;
|
||||
if (!lastUri || uri.toString() !== lastUri.toString()) {
|
||||
if (lastUri && this._data[lastUri.toString()].length === 0) {
|
||||
delete this._data[lastUri.toString()];
|
||||
if (lastUri && this._data.get(lastUri.toString()).length === 0) {
|
||||
this._data.delete(lastUri.toString());
|
||||
}
|
||||
lastUri = uri;
|
||||
toSync.push(uri);
|
||||
this._data[uri.toString()] = [];
|
||||
this._data.set(uri.toString(), []);
|
||||
}
|
||||
|
||||
if (!diagnostics) {
|
||||
// [Uri, undefined] means clear this
|
||||
this._data[uri.toString()].length = 0;
|
||||
this._data.get(uri.toString()).length = 0;
|
||||
} else {
|
||||
this._data[uri.toString()].push(...diagnostics);
|
||||
this._data.get(uri.toString()).push(...diagnostics);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,7 +104,7 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection {
|
||||
const entries: [URI, IMarkerData[]][] = [];
|
||||
for (let uri of toSync) {
|
||||
let marker: IMarkerData[];
|
||||
let diagnostics = this._data[uri.toString()];
|
||||
let diagnostics = this._data.get(uri.toString());
|
||||
if (diagnostics) {
|
||||
|
||||
// no more than 250 diagnostics per file
|
||||
@@ -144,27 +144,27 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection {
|
||||
|
||||
delete(uri: vscode.Uri): void {
|
||||
this._checkDisposed();
|
||||
delete this._data[uri.toString()];
|
||||
this._data.delete(uri.toString());
|
||||
this._proxy.$changeMany(this.name, [[<URI>uri, undefined]]);
|
||||
}
|
||||
|
||||
clear(): void {
|
||||
this._checkDisposed();
|
||||
this._data = Object.create(null);
|
||||
this._data.clear();
|
||||
this._proxy.$clear(this.name);
|
||||
}
|
||||
|
||||
forEach(callback: (uri: URI, diagnostics: vscode.Diagnostic[], collection: DiagnosticCollection) => any, thisArg?: any): void {
|
||||
this._checkDisposed();
|
||||
for (let key in this._data) {
|
||||
this._data.forEach((value, key) => {
|
||||
let uri = URI.parse(key);
|
||||
callback.apply(thisArg, [uri, this.get(uri), this]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get(uri: URI): vscode.Diagnostic[] {
|
||||
this._checkDisposed();
|
||||
let result = this._data[uri.toString()];
|
||||
let result = this._data.get(uri.toString());
|
||||
if (Array.isArray(result)) {
|
||||
return <vscode.Diagnostic[]>Object.freeze(result.slice(0));
|
||||
}
|
||||
@@ -172,7 +172,7 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection {
|
||||
|
||||
has(uri: URI): boolean {
|
||||
this._checkDisposed();
|
||||
return Array.isArray(this._data[uri.toString()]);
|
||||
return Array.isArray(this._data.get(uri.toString()));
|
||||
}
|
||||
|
||||
private _checkDisposed() {
|
||||
|
||||
@@ -20,16 +20,14 @@ import { asWinJsPromise } from 'vs/base/common/async';
|
||||
import { getWordAtText, ensureValidWordDefinition } from 'vs/editor/common/model/wordHelper';
|
||||
import { MainContext, MainThreadDocumentsShape, ExtHostDocumentsShape, IModelAddedData } from './extHost.protocol';
|
||||
|
||||
const _modeId2WordDefinition: {
|
||||
[modeId: string]: RegExp;
|
||||
} = Object.create(null);
|
||||
const _modeId2WordDefinition = new Map<string, RegExp>();
|
||||
|
||||
function setWordDefinitionFor(modeId: string, wordDefinition: RegExp): void {
|
||||
_modeId2WordDefinition[modeId] = wordDefinition;
|
||||
_modeId2WordDefinition.set(modeId, wordDefinition);
|
||||
}
|
||||
|
||||
function getWordDefinitionFor(modeId: string): RegExp {
|
||||
return _modeId2WordDefinition[modeId];
|
||||
return _modeId2WordDefinition.get(modeId);
|
||||
}
|
||||
|
||||
export class ExtHostDocuments extends ExtHostDocumentsShape {
|
||||
@@ -48,9 +46,9 @@ export class ExtHostDocuments extends ExtHostDocumentsShape {
|
||||
private _onDidSaveDocumentEventEmitter: Emitter<vscode.TextDocument>;
|
||||
public onDidSaveDocument: Event<vscode.TextDocument>;
|
||||
|
||||
private _documentData: { [modelUri: string]: ExtHostDocumentData; };
|
||||
private _documentLoader: { [modelUri: string]: TPromise<ExtHostDocumentData> };
|
||||
private _documentContentProviders: { [handle: number]: vscode.TextDocumentContentProvider; };
|
||||
private _documentData = new Map<string, ExtHostDocumentData>();
|
||||
private _documentLoader = new Map<string, TPromise<ExtHostDocumentData>>();
|
||||
private _documentContentProviders = new Map<number, vscode.TextDocumentContentProvider>();
|
||||
|
||||
private _proxy: MainThreadDocumentsShape;
|
||||
|
||||
@@ -69,17 +67,11 @@ export class ExtHostDocuments extends ExtHostDocumentsShape {
|
||||
|
||||
this._onDidSaveDocumentEventEmitter = new Emitter<vscode.TextDocument>();
|
||||
this.onDidSaveDocument = this._onDidSaveDocumentEventEmitter.event;
|
||||
|
||||
this._documentData = Object.create(null);
|
||||
this._documentLoader = Object.create(null);
|
||||
this._documentContentProviders = Object.create(null);
|
||||
}
|
||||
|
||||
public getAllDocumentData(): ExtHostDocumentData[] {
|
||||
const result: ExtHostDocumentData[] = [];
|
||||
for (let key in this._documentData) {
|
||||
result.push(this._documentData[key]);
|
||||
}
|
||||
this._documentData.forEach(data => result.push(data));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -87,7 +79,7 @@ export class ExtHostDocuments extends ExtHostDocumentsShape {
|
||||
if (!resource) {
|
||||
return;
|
||||
}
|
||||
const data = this._documentData[resource.toString()];
|
||||
const data = this._documentData.get(resource.toString());
|
||||
if (data) {
|
||||
return data;
|
||||
}
|
||||
@@ -95,21 +87,21 @@ export class ExtHostDocuments extends ExtHostDocumentsShape {
|
||||
|
||||
public ensureDocumentData(uri: URI): TPromise<ExtHostDocumentData> {
|
||||
|
||||
let cached = this._documentData[uri.toString()];
|
||||
let cached = this._documentData.get(uri.toString());
|
||||
if (cached) {
|
||||
return TPromise.as(cached);
|
||||
}
|
||||
|
||||
let promise = this._documentLoader[uri.toString()];
|
||||
let promise = this._documentLoader.get(uri.toString());
|
||||
if (!promise) {
|
||||
promise = this._proxy.$tryOpenDocument(uri).then(() => {
|
||||
delete this._documentLoader[uri.toString()];
|
||||
return this._documentData[uri.toString()];
|
||||
this._documentLoader.delete(uri.toString());
|
||||
return this._documentData.get(uri.toString());
|
||||
}, err => {
|
||||
delete this._documentLoader[uri.toString()];
|
||||
this._documentLoader.delete(uri.toString());
|
||||
return TPromise.wrapError(err);
|
||||
});
|
||||
this._documentLoader[uri.toString()] = promise;
|
||||
this._documentLoader.set(uri.toString(), promise);
|
||||
}
|
||||
|
||||
return promise;
|
||||
@@ -122,13 +114,13 @@ export class ExtHostDocuments extends ExtHostDocumentsShape {
|
||||
|
||||
const handle = ExtHostDocuments._handlePool++;
|
||||
|
||||
this._documentContentProviders[handle] = provider;
|
||||
this._documentContentProviders.set(handle, provider);
|
||||
this._proxy.$registerTextContentProvider(handle, scheme);
|
||||
|
||||
let subscription: IDisposable;
|
||||
if (typeof provider.onDidChange === 'function') {
|
||||
subscription = provider.onDidChange(uri => {
|
||||
if (this._documentData[uri.toString()]) {
|
||||
if (this._documentData.has(uri.toString())) {
|
||||
this.$provideTextDocumentContent(handle, <URI>uri).then(value => {
|
||||
return this._proxy.$onVirtualDocumentChange(<URI>uri, value);
|
||||
}, onUnexpectedError);
|
||||
@@ -136,7 +128,7 @@ export class ExtHostDocuments extends ExtHostDocumentsShape {
|
||||
});
|
||||
}
|
||||
return new Disposable(() => {
|
||||
if (delete this._documentContentProviders[handle]) {
|
||||
if (this._documentContentProviders.delete(handle)) {
|
||||
this._proxy.$unregisterTextContentProvider(handle);
|
||||
}
|
||||
if (subscription) {
|
||||
@@ -147,7 +139,7 @@ export class ExtHostDocuments extends ExtHostDocumentsShape {
|
||||
}
|
||||
|
||||
$provideTextDocumentContent(handle: number, uri: URI): TPromise<string> {
|
||||
const provider = this._documentContentProviders[handle];
|
||||
const provider = this._documentContentProviders.get(handle);
|
||||
if (!provider) {
|
||||
return TPromise.wrapError<string>(`unsupported uri-scheme: ${uri.scheme}`);
|
||||
}
|
||||
@@ -157,15 +149,15 @@ export class ExtHostDocuments extends ExtHostDocumentsShape {
|
||||
public $acceptModelAdd(initData: IModelAddedData): void {
|
||||
let data = new ExtHostDocumentData(this._proxy, initData.url, initData.value.lines, initData.value.EOL, initData.modeId, initData.versionId, initData.isDirty);
|
||||
let key = data.document.uri.toString();
|
||||
if (this._documentData[key]) {
|
||||
if (this._documentData.has(key)) {
|
||||
throw new Error('Document `' + key + '` already exists.');
|
||||
}
|
||||
this._documentData[key] = data;
|
||||
this._documentData.set(key, data);
|
||||
this._onDidAddDocumentEventEmitter.fire(data.document);
|
||||
}
|
||||
|
||||
public $acceptModelModeChanged(strURL: string, oldModeId: string, newModeId: string): void {
|
||||
let data = this._documentData[strURL];
|
||||
let data = this._documentData.get(strURL);
|
||||
|
||||
// Treat a mode change as a remove + add
|
||||
|
||||
@@ -175,33 +167,33 @@ export class ExtHostDocuments extends ExtHostDocumentsShape {
|
||||
}
|
||||
|
||||
public $acceptModelSaved(strURL: string): void {
|
||||
let data = this._documentData[strURL];
|
||||
let data = this._documentData.get(strURL);
|
||||
data._acceptIsDirty(false);
|
||||
this._onDidSaveDocumentEventEmitter.fire(data.document);
|
||||
}
|
||||
|
||||
public $acceptModelDirty(strURL: string): void {
|
||||
let document = this._documentData[strURL];
|
||||
let document = this._documentData.get(strURL);
|
||||
document._acceptIsDirty(true);
|
||||
}
|
||||
|
||||
public $acceptModelReverted(strURL: string): void {
|
||||
let document = this._documentData[strURL];
|
||||
let document = this._documentData.get(strURL);
|
||||
document._acceptIsDirty(false);
|
||||
}
|
||||
|
||||
public $acceptModelRemoved(strURL: string): void {
|
||||
if (!this._documentData[strURL]) {
|
||||
if (!this._documentData.has(strURL)) {
|
||||
throw new Error('Document `' + strURL + '` does not exist.');
|
||||
}
|
||||
let data = this._documentData[strURL];
|
||||
delete this._documentData[strURL];
|
||||
let data = this._documentData.get(strURL);
|
||||
this._documentData.delete(strURL);
|
||||
this._onDidRemoveDocumentEventEmitter.fire(data.document);
|
||||
data.dispose();
|
||||
}
|
||||
|
||||
public $acceptModelChanged(strURL: string, events: editorCommon.IModelContentChangedEvent2[], isDirty: boolean): void {
|
||||
let data = this._documentData[strURL];
|
||||
let data = this._documentData.get(strURL);
|
||||
data._acceptIsDirty(isDirty);
|
||||
data.onEvents(events);
|
||||
this._onDidChangeDocumentEventEmitter.fire({
|
||||
|
||||
@@ -30,7 +30,7 @@ export class ExtHostEditors extends ExtHostEditorsShape {
|
||||
public onDidChangeTextEditorViewColumn: Event<vscode.TextEditorViewColumnChangeEvent>;
|
||||
private _onDidChangeTextEditorViewColumn: Emitter<vscode.TextEditorViewColumnChangeEvent>;
|
||||
|
||||
private _editors: { [id: string]: ExtHostTextEditor };
|
||||
private _editors: Map<string, ExtHostTextEditor>;
|
||||
private _proxy: MainThreadEditorsShape;
|
||||
private _onDidChangeActiveTextEditor: Emitter<vscode.TextEditor>;
|
||||
private _onDidChangeVisibleTextEditors: Emitter<vscode.TextEditor[]>;
|
||||
@@ -56,17 +56,17 @@ export class ExtHostEditors extends ExtHostEditorsShape {
|
||||
this._proxy = threadService.get(MainContext.MainThreadEditors);
|
||||
this._onDidChangeActiveTextEditor = new Emitter<vscode.TextEditor>();
|
||||
this._onDidChangeVisibleTextEditors = new Emitter<vscode.TextEditor[]>();
|
||||
this._editors = Object.create(null);
|
||||
this._editors = new Map<string, ExtHostTextEditor>();
|
||||
|
||||
this._visibleEditorIds = [];
|
||||
}
|
||||
|
||||
getActiveTextEditor(): vscode.TextEditor {
|
||||
return this._editors[this._activeEditorId];
|
||||
return this._editors.get(this._activeEditorId);
|
||||
}
|
||||
|
||||
getVisibleTextEditors(): vscode.TextEditor[] {
|
||||
return this._visibleEditorIds.map(id => this._editors[id]);
|
||||
return this._visibleEditorIds.map(id => this._editors.get(id));
|
||||
}
|
||||
|
||||
get onDidChangeActiveTextEditor(): Event<vscode.TextEditor> {
|
||||
@@ -79,7 +79,7 @@ export class ExtHostEditors extends ExtHostEditorsShape {
|
||||
|
||||
showTextDocument(document: vscode.TextDocument, column: vscode.ViewColumn, preserveFocus: boolean): TPromise<vscode.TextEditor> {
|
||||
return this._proxy.$tryShowTextDocument(<URI>document.uri, TypeConverters.fromViewColumn(column), preserveFocus).then(id => {
|
||||
let editor = this._editors[id];
|
||||
let editor = this._editors.get(id);
|
||||
if (editor) {
|
||||
return editor;
|
||||
} else {
|
||||
@@ -97,11 +97,11 @@ export class ExtHostEditors extends ExtHostEditorsShape {
|
||||
$acceptTextEditorAdd(data: ITextEditorAddData): void {
|
||||
let document = this._extHostDocuments.getDocumentData(data.document);
|
||||
let newEditor = new ExtHostTextEditor(this._proxy, data.id, document, data.selections.map(TypeConverters.toSelection), data.options, TypeConverters.toViewColumn(data.editorPosition));
|
||||
this._editors[data.id] = newEditor;
|
||||
this._editors.set(data.id, newEditor);
|
||||
}
|
||||
|
||||
$acceptOptionsChanged(id: string, opts: IResolvedTextEditorConfiguration): void {
|
||||
let editor = this._editors[id];
|
||||
let editor = this._editors.get(id);
|
||||
editor._acceptOptions(opts);
|
||||
this._onDidChangeTextEditorOptions.fire({
|
||||
textEditor: editor,
|
||||
@@ -112,7 +112,7 @@ export class ExtHostEditors extends ExtHostEditorsShape {
|
||||
$acceptSelectionsChanged(id: string, event: ISelectionChangeEvent): void {
|
||||
const kind = TextEditorSelectionChangeKind.fromValue(event.source);
|
||||
const selections = event.selections.map(TypeConverters.toSelection);
|
||||
const textEditor = this._editors[id];
|
||||
const textEditor = this._editors.get(id);
|
||||
textEditor._acceptSelections(selections);
|
||||
this._onDidChangeTextEditorSelection.fire({
|
||||
textEditor,
|
||||
@@ -145,7 +145,7 @@ export class ExtHostEditors extends ExtHostEditorsShape {
|
||||
|
||||
$acceptEditorPositionData(data: ITextEditorPositionData): void {
|
||||
for (let id in data) {
|
||||
let textEditor = this._editors[id];
|
||||
let textEditor = this._editors.get(id);
|
||||
let viewColumn = TypeConverters.toViewColumn(data[id]);
|
||||
if (textEditor.viewColumn !== viewColumn) {
|
||||
textEditor._acceptViewColumn(viewColumn);
|
||||
@@ -165,9 +165,9 @@ export class ExtHostEditors extends ExtHostEditorsShape {
|
||||
this.$acceptActiveEditorAndVisibleEditors(this._activeEditorId, newVisibleEditors);
|
||||
}
|
||||
|
||||
let editor = this._editors[id];
|
||||
let editor = this._editors.get(id);
|
||||
editor.dispose();
|
||||
delete this._editors[id];
|
||||
this._editors.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,20 +10,20 @@ export class ExtHostHeapService extends ExtHostHeapServiceShape {
|
||||
|
||||
private static _idPool = 0;
|
||||
|
||||
private _data: { [n: number]: any } = Object.create(null);
|
||||
private _data = new Map<number, any>();
|
||||
|
||||
keep(obj: any): number {
|
||||
const id = ExtHostHeapService._idPool++;
|
||||
this._data[id] = obj;
|
||||
this._data.set(id, obj);
|
||||
return id;
|
||||
}
|
||||
|
||||
delete(id: number): boolean {
|
||||
return this._data[id];
|
||||
return this._data.delete(id);
|
||||
}
|
||||
|
||||
get<T>(id: number): T {
|
||||
return this._data[id];
|
||||
return this._data.get(id);
|
||||
}
|
||||
|
||||
$onGarbageCollection(ids: number[]): void {
|
||||
@@ -31,4 +31,4 @@ export class ExtHostHeapService extends ExtHostHeapServiceShape {
|
||||
this.delete(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -624,7 +624,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
|
||||
private _commands: ExtHostCommands;
|
||||
private _heapService: ExtHostHeapService;
|
||||
private _diagnostics: ExtHostDiagnostics;
|
||||
private _adapter: { [handle: number]: Adapter } = Object.create(null);
|
||||
private _adapter = new Map<number, Adapter>();
|
||||
|
||||
constructor(
|
||||
threadService: IThreadService,
|
||||
@@ -643,7 +643,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
|
||||
|
||||
private _createDisposable(handle: number): Disposable {
|
||||
return new Disposable(() => {
|
||||
delete this._adapter[handle];
|
||||
this._adapter.delete(handle);
|
||||
this._proxy.$unregister(handle);
|
||||
});
|
||||
}
|
||||
@@ -653,7 +653,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
|
||||
}
|
||||
|
||||
private _withAdapter<A, R>(handle: number, ctor: { new (...args: any[]): A }, callback: (adapter: A) => TPromise<R>): TPromise<R> {
|
||||
let adapter = this._adapter[handle];
|
||||
let adapter = this._adapter.get(handle);
|
||||
if (!(adapter instanceof ctor)) {
|
||||
return TPromise.wrapError(new Error('no adapter found'));
|
||||
}
|
||||
@@ -664,7 +664,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
|
||||
|
||||
registerDocumentSymbolProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentSymbolProvider): vscode.Disposable {
|
||||
const handle = this._nextHandle();
|
||||
this._adapter[handle] = new OutlineAdapter(this._documents, provider);
|
||||
this._adapter.set(handle, new OutlineAdapter(this._documents, provider));
|
||||
this._proxy.$registerOutlineSupport(handle, selector);
|
||||
return this._createDisposable(handle);
|
||||
}
|
||||
@@ -679,7 +679,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
|
||||
const handle = this._nextHandle();
|
||||
const eventHandle = typeof provider.onDidChangeCodeLenses === 'function' ? this._nextHandle() : undefined;
|
||||
|
||||
this._adapter[handle] = new CodeLensAdapter(this._documents, this._commands.converter, this._heapService, provider);
|
||||
this._adapter.set(handle, new CodeLensAdapter(this._documents, this._commands.converter, this._heapService, provider));
|
||||
this._proxy.$registerCodeLensSupport(handle, selector, eventHandle);
|
||||
let result = this._createDisposable(handle);
|
||||
|
||||
@@ -703,7 +703,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
|
||||
|
||||
registerDefinitionProvider(selector: vscode.DocumentSelector, provider: vscode.DefinitionProvider): vscode.Disposable {
|
||||
const handle = this._nextHandle();
|
||||
this._adapter[handle] = new DefinitionAdapter(this._documents, provider);
|
||||
this._adapter.set(handle, new DefinitionAdapter(this._documents, provider));
|
||||
this._proxy.$registerDeclaractionSupport(handle, selector);
|
||||
return this._createDisposable(handle);
|
||||
}
|
||||
@@ -716,7 +716,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
|
||||
|
||||
registerHoverProvider(selector: vscode.DocumentSelector, provider: vscode.HoverProvider): vscode.Disposable {
|
||||
const handle = this._nextHandle();
|
||||
this._adapter[handle] = new HoverAdapter(this._documents, provider);
|
||||
this._adapter.set(handle, new HoverAdapter(this._documents, provider));
|
||||
this._proxy.$registerHoverProvider(handle, selector);
|
||||
return this._createDisposable(handle);
|
||||
}
|
||||
@@ -729,7 +729,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
|
||||
|
||||
registerDocumentHighlightProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentHighlightProvider): vscode.Disposable {
|
||||
const handle = this._nextHandle();
|
||||
this._adapter[handle] = new DocumentHighlightAdapter(this._documents, provider);
|
||||
this._adapter.set(handle, new DocumentHighlightAdapter(this._documents, provider));
|
||||
this._proxy.$registerDocumentHighlightProvider(handle, selector);
|
||||
return this._createDisposable(handle);
|
||||
}
|
||||
@@ -742,7 +742,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
|
||||
|
||||
registerReferenceProvider(selector: vscode.DocumentSelector, provider: vscode.ReferenceProvider): vscode.Disposable {
|
||||
const handle = this._nextHandle();
|
||||
this._adapter[handle] = new ReferenceAdapter(this._documents, provider);
|
||||
this._adapter.set(handle, new ReferenceAdapter(this._documents, provider));
|
||||
this._proxy.$registerReferenceSupport(handle, selector);
|
||||
return this._createDisposable(handle);
|
||||
}
|
||||
@@ -755,7 +755,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
|
||||
|
||||
registerCodeActionProvider(selector: vscode.DocumentSelector, provider: vscode.CodeActionProvider): vscode.Disposable {
|
||||
const handle = this._nextHandle();
|
||||
this._adapter[handle] = new QuickFixAdapter(this._documents, this._commands.converter, this._diagnostics, this._heapService, provider);
|
||||
this._adapter.set(handle, new QuickFixAdapter(this._documents, this._commands.converter, this._diagnostics, this._heapService, provider));
|
||||
this._proxy.$registerQuickFixSupport(handle, selector);
|
||||
return this._createDisposable(handle);
|
||||
}
|
||||
@@ -768,7 +768,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
|
||||
|
||||
registerDocumentFormattingEditProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentFormattingEditProvider): vscode.Disposable {
|
||||
const handle = this._nextHandle();
|
||||
this._adapter[handle] = new DocumentFormattingAdapter(this._documents, provider);
|
||||
this._adapter.set(handle, new DocumentFormattingAdapter(this._documents, provider));
|
||||
this._proxy.$registerDocumentFormattingSupport(handle, selector);
|
||||
return this._createDisposable(handle);
|
||||
}
|
||||
@@ -779,7 +779,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
|
||||
|
||||
registerDocumentRangeFormattingEditProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentRangeFormattingEditProvider): vscode.Disposable {
|
||||
const handle = this._nextHandle();
|
||||
this._adapter[handle] = new RangeFormattingAdapter(this._documents, provider);
|
||||
this._adapter.set(handle, new RangeFormattingAdapter(this._documents, provider));
|
||||
this._proxy.$registerRangeFormattingSupport(handle, selector);
|
||||
return this._createDisposable(handle);
|
||||
}
|
||||
@@ -790,7 +790,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
|
||||
|
||||
registerOnTypeFormattingEditProvider(selector: vscode.DocumentSelector, provider: vscode.OnTypeFormattingEditProvider, triggerCharacters: string[]): vscode.Disposable {
|
||||
const handle = this._nextHandle();
|
||||
this._adapter[handle] = new OnTypeFormattingAdapter(this._documents, provider);
|
||||
this._adapter.set(handle, new OnTypeFormattingAdapter(this._documents, provider));
|
||||
this._proxy.$registerOnTypeFormattingSupport(handle, selector, triggerCharacters);
|
||||
return this._createDisposable(handle);
|
||||
}
|
||||
@@ -803,7 +803,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
|
||||
|
||||
registerWorkspaceSymbolProvider(provider: vscode.WorkspaceSymbolProvider): vscode.Disposable {
|
||||
const handle = this._nextHandle();
|
||||
this._adapter[handle] = new NavigateTypeAdapter(provider, this._heapService);
|
||||
this._adapter.set(handle, new NavigateTypeAdapter(provider, this._heapService));
|
||||
this._proxy.$registerNavigateTypeSupport(handle);
|
||||
return this._createDisposable(handle);
|
||||
}
|
||||
@@ -820,7 +820,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
|
||||
|
||||
registerRenameProvider(selector: vscode.DocumentSelector, provider: vscode.RenameProvider): vscode.Disposable {
|
||||
const handle = this._nextHandle();
|
||||
this._adapter[handle] = new RenameAdapter(this._documents, provider);
|
||||
this._adapter.set(handle, new RenameAdapter(this._documents, provider));
|
||||
this._proxy.$registerRenameSupport(handle, selector);
|
||||
return this._createDisposable(handle);
|
||||
}
|
||||
@@ -833,7 +833,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
|
||||
|
||||
registerCompletionItemProvider(selector: vscode.DocumentSelector, provider: vscode.CompletionItemProvider, triggerCharacters: string[]): vscode.Disposable {
|
||||
const handle = this._nextHandle();
|
||||
this._adapter[handle] = new SuggestAdapter(this._documents, this._commands.converter, this._heapService, provider);
|
||||
this._adapter.set(handle, new SuggestAdapter(this._documents, this._commands.converter, this._heapService, provider));
|
||||
this._proxy.$registerSuggestSupport(handle, selector, triggerCharacters);
|
||||
return this._createDisposable(handle);
|
||||
}
|
||||
@@ -850,7 +850,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
|
||||
|
||||
registerSignatureHelpProvider(selector: vscode.DocumentSelector, provider: vscode.SignatureHelpProvider, triggerCharacters: string[]): vscode.Disposable {
|
||||
const handle = this._nextHandle();
|
||||
this._adapter[handle] = new SignatureHelpAdapter(this._documents, provider);
|
||||
this._adapter.set(handle, new SignatureHelpAdapter(this._documents, provider));
|
||||
this._proxy.$registerSignatureHelpProvider(handle, selector, triggerCharacters);
|
||||
return this._createDisposable(handle);
|
||||
}
|
||||
@@ -863,7 +863,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
|
||||
|
||||
registerDocumentLinkProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentLinkProvider): vscode.Disposable {
|
||||
const handle = this._nextHandle();
|
||||
this._adapter[handle] = new LinkProviderAdapter(this._documents, provider);
|
||||
this._adapter.set(handle, new LinkProviderAdapter(this._documents, provider));
|
||||
this._proxy.$registerDocumentLinkProvider(handle, selector);
|
||||
return this._createDisposable(handle);
|
||||
}
|
||||
|
||||
@@ -465,7 +465,7 @@ export class Uri extends URI { }
|
||||
export class WorkspaceEdit {
|
||||
|
||||
private _values: [Uri, TextEdit[]][] = [];
|
||||
private _index: { [uri: string]: number } = Object.create(null);
|
||||
private _index = new Map<string, number>();
|
||||
|
||||
replace(uri: Uri, range: Range, newText: string): void {
|
||||
let edit = new TextEdit(range, newText);
|
||||
@@ -486,21 +486,21 @@ export class WorkspaceEdit {
|
||||
}
|
||||
|
||||
has(uri: Uri): boolean {
|
||||
return typeof this._index[uri.toString()] !== 'undefined';
|
||||
return this._index.has(uri.toString());
|
||||
}
|
||||
|
||||
set(uri: Uri, edits: TextEdit[]): void {
|
||||
let idx = this._index[uri.toString()];
|
||||
const idx = this._index.get(uri.toString());
|
||||
if (typeof idx === 'undefined') {
|
||||
let newLen = this._values.push([uri, edits]);
|
||||
this._index[uri.toString()] = newLen - 1;
|
||||
this._index.set(uri.toString(), newLen - 1);
|
||||
} else {
|
||||
this._values[idx][1] = edits;
|
||||
}
|
||||
}
|
||||
|
||||
get(uri: Uri): TextEdit[] {
|
||||
let idx = this._index[uri.toString()];
|
||||
let idx = this._index.get(uri.toString());
|
||||
return typeof idx !== 'undefined' && this._values[idx][1];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user