mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 03:29:00 +01:00
debt - less TPromise usage
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
'use strict';
|
||||
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import * as vscode from 'vscode';
|
||||
import * as typeConverters from 'vs/workbench/api/node/extHostTypeConverters';
|
||||
@@ -350,7 +349,7 @@ export class ExtHostApiCommands {
|
||||
return undefined;
|
||||
}
|
||||
if (value.rejectReason) {
|
||||
return TPromise.wrapError<types.WorkspaceEdit>(new Error(value.rejectReason));
|
||||
return Promise.reject(new Error(value.rejectReason));
|
||||
}
|
||||
return typeConverters.WorkspaceEdit.to(value);
|
||||
});
|
||||
|
||||
@@ -12,7 +12,6 @@ import { Range, Position, EndOfLine } from 'vs/workbench/api/node/extHostTypes';
|
||||
import * as vscode from 'vscode';
|
||||
import { getWordAtText, ensureValidWordDefinition } from 'vs/editor/common/model/wordHelper';
|
||||
import { MainThreadDocumentsShape } from './extHost.protocol';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
|
||||
const _modeId2WordDefinition = new Map<string, RegExp>();
|
||||
@@ -101,7 +100,7 @@ export class ExtHostDocumentData extends MirrorTextModel {
|
||||
|
||||
private _save(): Thenable<boolean> {
|
||||
if (this._isDisposed) {
|
||||
return TPromise.wrapError<boolean>(new Error('Document has been closed'));
|
||||
return Promise.reject(new Error('Document has been closed'));
|
||||
}
|
||||
return this._proxy.$trySaveDocument(this._uri);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { URI, UriComponents } from 'vs/base/common/uri';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import * as TypeConverters from './extHostTypeConverters';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import * as vscode from 'vscode';
|
||||
import { MainContext, MainThreadDocumentsShape, ExtHostDocumentsShape, IMainContext } from './extHost.protocol';
|
||||
import { ExtHostDocumentData, setWordDefinitionFor } from './extHostDocumentData';
|
||||
@@ -73,7 +72,7 @@ export class ExtHostDocuments implements ExtHostDocumentsShape {
|
||||
|
||||
let cached = this._documentsAndEditors.getDocument(uri.toString());
|
||||
if (cached) {
|
||||
return TPromise.as(cached);
|
||||
return Promise.resolve(cached);
|
||||
}
|
||||
|
||||
let promise = this._documentLoader.get(uri.toString());
|
||||
@@ -83,7 +82,7 @@ export class ExtHostDocuments implements ExtHostDocumentsShape {
|
||||
return this._documentsAndEditors.getDocument(uri.toString());
|
||||
}, err => {
|
||||
this._documentLoader.delete(uri.toString());
|
||||
return TPromise.wrapError<ExtHostDocumentData>(err);
|
||||
return Promise.reject(err);
|
||||
});
|
||||
this._documentLoader.set(uri.toString(), promise);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
'use strict';
|
||||
|
||||
import { URI, UriComponents } from 'vs/base/common/uri';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { mixin } from 'vs/base/common/objects';
|
||||
import * as vscode from 'vscode';
|
||||
import * as typeConvert from 'vs/workbench/api/node/extHostTypeConverters';
|
||||
@@ -132,7 +131,7 @@ class CodeLensAdapter {
|
||||
|
||||
let resolve: Thenable<vscode.CodeLens>;
|
||||
if (typeof this._provider.resolveCodeLens !== 'function' || lens.isResolved) {
|
||||
resolve = TPromise.as(lens);
|
||||
resolve = Promise.resolve(lens);
|
||||
} else {
|
||||
resolve = asThenable(() => this._provider.resolveCodeLens(lens, token));
|
||||
}
|
||||
@@ -447,7 +446,7 @@ class NavigateTypeAdapter {
|
||||
resolveWorkspaceSymbol(symbol: WorkspaceSymbolDto, token: CancellationToken): Thenable<WorkspaceSymbolDto> {
|
||||
|
||||
if (typeof this._provider.resolveWorkspaceSymbol !== 'function') {
|
||||
return TPromise.as(symbol);
|
||||
return Promise.resolve(symbol);
|
||||
}
|
||||
|
||||
const item = this._symbolCache[symbol._id];
|
||||
@@ -504,7 +503,7 @@ class RenameAdapter {
|
||||
|
||||
resolveRenameLocation(resource: URI, position: IPosition, token: CancellationToken): Thenable<modes.RenameLocation & modes.Rejection> {
|
||||
if (typeof this._provider.prepareRename !== 'function') {
|
||||
return TPromise.as(undefined);
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
let doc = this._documents.getDocumentData(resource).document;
|
||||
@@ -622,13 +621,13 @@ class SuggestAdapter {
|
||||
resolveCompletionItem(resource: URI, position: IPosition, suggestion: modes.ISuggestion, token: CancellationToken): Thenable<modes.ISuggestion> {
|
||||
|
||||
if (typeof this._provider.resolveCompletionItem !== 'function') {
|
||||
return TPromise.as(suggestion);
|
||||
return Promise.resolve(suggestion);
|
||||
}
|
||||
|
||||
const { _parentId, _id } = (<SuggestionDto>suggestion);
|
||||
const item = this._cache.has(_parentId) && this._cache.get(_parentId)[_id];
|
||||
if (!item) {
|
||||
return TPromise.as(suggestion);
|
||||
return Promise.resolve(suggestion);
|
||||
}
|
||||
|
||||
return asThenable(() => this._provider.resolveCompletionItem(item, token)).then(resolvedItem => {
|
||||
@@ -928,7 +927,7 @@ export class ExtHostLanguageFeatures implements ExtHostLanguageFeaturesShape {
|
||||
private _withAdapter<A, R>(handle: number, ctor: { new(...args: any[]): A }, callback: (adapter: A) => Thenable<R>): Thenable<R> {
|
||||
let adapter = this._adapter.get(handle);
|
||||
if (!(adapter instanceof ctor)) {
|
||||
return TPromise.wrapError<R>(new Error('no adapter found'));
|
||||
return Promise.reject(new Error('no adapter found'));
|
||||
}
|
||||
return callback(<any>adapter);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
import { ok } from 'vs/base/common/assert';
|
||||
import { readonly, illegalArgument } from 'vs/base/common/errors';
|
||||
import { IdGenerator } from 'vs/base/common/idGenerator';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { ExtHostDocumentData } from 'vs/workbench/api/node/extHostDocumentData';
|
||||
import { Selection, Range, Position, EndOfLine, TextEditorRevealType, TextEditorLineNumbersStyle, SnippetString } from './extHostTypes';
|
||||
import { ISingleEditOperation } from 'vs/editor/common/model';
|
||||
@@ -499,7 +498,7 @@ export class ExtHostTextEditor implements vscode.TextEditor {
|
||||
|
||||
edit(callback: (edit: TextEditorEdit) => void, options: { undoStopBefore: boolean; undoStopAfter: boolean; } = { undoStopBefore: true, undoStopAfter: true }): Thenable<boolean> {
|
||||
if (this._disposed) {
|
||||
return TPromise.wrapError<boolean>(new Error('TextEditor#edit not possible on closed editors'));
|
||||
return Promise.reject(new Error('TextEditor#edit not possible on closed editors'));
|
||||
}
|
||||
let edit = new TextEditorEdit(this._documentData.document, options);
|
||||
callback(edit);
|
||||
@@ -511,7 +510,7 @@ export class ExtHostTextEditor implements vscode.TextEditor {
|
||||
|
||||
// return when there is nothing to do
|
||||
if (editData.edits.length === 0 && !editData.setEndOfLine) {
|
||||
return TPromise.wrap(true);
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
// check that the edits are not overlapping (i.e. illegal)
|
||||
@@ -538,7 +537,7 @@ export class ExtHostTextEditor implements vscode.TextEditor {
|
||||
|
||||
if (nextRangeStart.isBefore(rangeEnd)) {
|
||||
// overlapping ranges
|
||||
return TPromise.wrapError<boolean>(
|
||||
return Promise.reject(
|
||||
new Error('Overlapping ranges are not allowed!')
|
||||
);
|
||||
}
|
||||
@@ -562,7 +561,7 @@ export class ExtHostTextEditor implements vscode.TextEditor {
|
||||
|
||||
insertSnippet(snippet: SnippetString, where?: Position | Position[] | Range | Range[], options: { undoStopBefore: boolean; undoStopAfter: boolean; } = { undoStopBefore: true, undoStopAfter: true }): Thenable<boolean> {
|
||||
if (this._disposed) {
|
||||
return TPromise.wrapError<boolean>(new Error('TextEditor#insertSnippet not possible on closed editors'));
|
||||
return Promise.reject(new Error('TextEditor#insertSnippet not possible on closed editors'));
|
||||
}
|
||||
let ranges: IRange[];
|
||||
|
||||
@@ -595,7 +594,7 @@ export class ExtHostTextEditor implements vscode.TextEditor {
|
||||
private _runOnProxy(callback: () => Thenable<any>): Thenable<ExtHostTextEditor> {
|
||||
if (this._disposed) {
|
||||
console.warn('TextEditor is closed/disposed');
|
||||
return TPromise.as(undefined);
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
return callback().then(() => this, err => {
|
||||
if (!(err instanceof Error && err.name === 'DISPOSED')) {
|
||||
|
||||
Reference in New Issue
Block a user