mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 13:46:13 +00:00
Reduce usage of WinJS Promise (#53526)
This commit is contained in:
parent
d3d3236565
commit
17d674aadf
|
@ -4,7 +4,6 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IMode, LanguageId, LanguageIdentifier } from 'vs/editor/common/modes';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
|
@ -43,7 +42,7 @@ export interface IModeService {
|
|||
|
||||
// --- instantiation
|
||||
getMode(commaSeparatedMimetypesOrCommaSeparatedIds: string): IMode;
|
||||
getOrCreateMode(commaSeparatedMimetypesOrCommaSeparatedIds: string): TPromise<IMode>;
|
||||
getOrCreateModeByLanguageName(languageName: string): TPromise<IMode>;
|
||||
getOrCreateModeByFilepathOrFirstLine(filepath: string, firstLine?: string): TPromise<IMode>;
|
||||
getOrCreateMode(commaSeparatedMimetypesOrCommaSeparatedIds: string): Promise<IMode>;
|
||||
getOrCreateModeByLanguageName(languageName: string): Promise<IMode>;
|
||||
getOrCreateModeByFilepathOrFirstLine(filepath: string, firstLine?: string): Promise<IMode>;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IMode, LanguageId, LanguageIdentifier } from 'vs/editor/common/modes';
|
||||
import { FrankensteinMode } from 'vs/editor/common/modes/abstractMode';
|
||||
import { LanguagesRegistry } from 'vs/editor/common/services/languagesRegistry';
|
||||
|
@ -27,8 +26,8 @@ export class ModeServiceImpl implements IModeService {
|
|||
this._registry = new LanguagesRegistry(true, warnOnOverwrite);
|
||||
}
|
||||
|
||||
protected _onReady(): TPromise<boolean> {
|
||||
return TPromise.as(true);
|
||||
protected _onReady(): Promise<boolean> {
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
public isRegisteredMode(mimetypeOrModeId: string): boolean {
|
||||
|
@ -115,7 +114,7 @@ export class ModeServiceImpl implements IModeService {
|
|||
return null;
|
||||
}
|
||||
|
||||
public getOrCreateMode(commaSeparatedMimetypesOrCommaSeparatedIds: string): TPromise<IMode> {
|
||||
public getOrCreateMode(commaSeparatedMimetypesOrCommaSeparatedIds: string): Promise<IMode> {
|
||||
return this._onReady().then(() => {
|
||||
const modeId = this.getModeId(commaSeparatedMimetypesOrCommaSeparatedIds);
|
||||
// Fall back to plain text if no mode was found
|
||||
|
@ -123,7 +122,7 @@ export class ModeServiceImpl implements IModeService {
|
|||
});
|
||||
}
|
||||
|
||||
public getOrCreateModeByLanguageName(languageName: string): TPromise<IMode> {
|
||||
public getOrCreateModeByLanguageName(languageName: string): Promise<IMode> {
|
||||
return this._onReady().then(() => {
|
||||
const modeId = this._getModeIdByLanguageName(languageName);
|
||||
// Fall back to plain text if no mode was found
|
||||
|
@ -141,7 +140,7 @@ export class ModeServiceImpl implements IModeService {
|
|||
return null;
|
||||
}
|
||||
|
||||
public getOrCreateModeByFilepathOrFirstLine(filepath: string, firstLine?: string): TPromise<IMode> {
|
||||
public getOrCreateModeByFilepathOrFirstLine(filepath: string, firstLine?: string): Promise<IMode> {
|
||||
return this._onReady().then(() => {
|
||||
const modeId = this.getModeIdByFilepathOrFirstLine(filepath, firstLine);
|
||||
// Fall back to plain text if no mode was found
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { ITextModel, ITextModelCreationOptions, ITextBufferFactory } from 'vs/editor/common/model';
|
||||
import { IMode } from 'vs/editor/common/modes';
|
||||
|
@ -15,11 +14,11 @@ export const IModelService = createDecorator<IModelService>('modelService');
|
|||
export interface IModelService {
|
||||
_serviceBrand: any;
|
||||
|
||||
createModel(value: string | ITextBufferFactory, modeOrPromise: TPromise<IMode> | IMode, resource: URI, isForSimpleWidget?: boolean): ITextModel;
|
||||
createModel(value: string | ITextBufferFactory, modeOrPromise: Promise<IMode> | IMode, resource: URI, isForSimpleWidget?: boolean): ITextModel;
|
||||
|
||||
updateModel(model: ITextModel, value: string | ITextBufferFactory): void;
|
||||
|
||||
setMode(model: ITextModel, modeOrPromise: TPromise<IMode> | IMode): void;
|
||||
setMode(model: ITextModel, modeOrPromise: Promise<IMode> | IMode): void;
|
||||
|
||||
destroyModel(resource: URI): void;
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ import { Event, Emitter } from 'vs/base/common/event';
|
|||
import { MarkdownString } from 'vs/base/common/htmlContent';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IMarker, IMarkerService, MarkerSeverity, MarkerTag } from 'vs/platform/markers/common/markers';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { TextModel, createTextBuffer } from 'vs/editor/common/model/textModel';
|
||||
|
@ -492,7 +491,7 @@ export class ModelServiceImpl implements IModelService {
|
|||
return [EditOperation.replaceMove(oldRange, textBuffer.getValueInRange(newRange, EndOfLinePreference.TextDefined))];
|
||||
}
|
||||
|
||||
public createModel(value: string | ITextBufferFactory, modeOrPromise: TPromise<IMode> | IMode, resource: URI, isForSimpleWidget: boolean = false): ITextModel {
|
||||
public createModel(value: string | ITextBufferFactory, modeOrPromise: Promise<IMode> | IMode, resource: URI, isForSimpleWidget: boolean = false): ITextModel {
|
||||
let modelData: ModelData;
|
||||
|
||||
if (!modeOrPromise || isThenable(modeOrPromise)) {
|
||||
|
@ -512,7 +511,7 @@ export class ModelServiceImpl implements IModelService {
|
|||
return modelData.model;
|
||||
}
|
||||
|
||||
public setMode(model: ITextModel, modeOrPromise: TPromise<IMode> | IMode): void {
|
||||
public setMode(model: ITextModel, modeOrPromise: Promise<IMode> | IMode): void {
|
||||
if (!modeOrPromise) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import { ScrollbarVisibility } from 'vs/base/common/scrollable';
|
|||
import { IEditorOverrideServices, DynamicStandaloneServices, StaticServices } from 'vs/editor/standalone/browser/standaloneServices';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { OpenerService } from 'vs/editor/browser/services/openerService';
|
||||
import { IOpenerService } from 'vs/platform/opener/common/opener';
|
||||
import { Colorizer, IColorizerElementOptions, IColorizerOptions } from 'vs/editor/standalone/browser/colorizer';
|
||||
|
@ -136,7 +135,7 @@ export function createDiffNavigator(diffEditor: IStandaloneDiffEditor, opts?: ID
|
|||
return new DiffNavigator(diffEditor, opts);
|
||||
}
|
||||
|
||||
function doCreateModel(value: string, mode: TPromise<modes.IMode>, uri?: URI): ITextModel {
|
||||
function doCreateModel(value: string, mode: Promise<modes.IMode>, uri?: URI): ITextModel {
|
||||
return StaticServices.modelService.get().createModel(value, mode, uri);
|
||||
}
|
||||
|
||||
|
|
|
@ -976,7 +976,7 @@ export class ChangeModeAction extends Action {
|
|||
}
|
||||
|
||||
// Find mode
|
||||
let mode: TPromise<IMode>;
|
||||
let mode: Promise<IMode>;
|
||||
if (pick === autoDetectMode) {
|
||||
mode = this.modeService.getOrCreateModeByFilepathOrFirstLine(toResource(activeEditor, { supportSideBySide: true }).fsPath, textModel.getLineContent(1));
|
||||
} else {
|
||||
|
|
|
@ -77,7 +77,7 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd
|
|||
return TPromise.as(this.doCreateTextEditorModel(value, mode, resource));
|
||||
}
|
||||
|
||||
private doCreateTextEditorModel(value: ITextBufferFactory, mode: TPromise<IMode>, resource: URI): EditorModel {
|
||||
private doCreateTextEditorModel(value: ITextBufferFactory, mode: Promise<IMode>, resource: URI): EditorModel {
|
||||
let model = resource && this.modelService.getModel(resource);
|
||||
if (!model) {
|
||||
model = this.modelService.createModel(value, mode, resource);
|
||||
|
@ -113,7 +113,7 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd
|
|||
*
|
||||
* @param firstLineText optional first line of the text buffer to set the mode on. This can be used to guess a mode from content.
|
||||
*/
|
||||
protected getOrCreateMode(modeService: IModeService, modeId: string, firstLineText?: string): TPromise<IMode> {
|
||||
protected getOrCreateMode(modeService: IModeService, modeId: string, firstLineText?: string): Promise<IMode> {
|
||||
return modeService.getOrCreateMode(modeId);
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ export class UntitledEditorModel extends BaseTextEditorModel implements IEncodin
|
|||
this.registerListeners();
|
||||
}
|
||||
|
||||
protected getOrCreateMode(modeService: IModeService, modeId: string, firstLineText?: string): TPromise<IMode> {
|
||||
protected getOrCreateMode(modeService: IModeService, modeId: string, firstLineText?: string): Promise<IMode> {
|
||||
if (!modeId || modeId === PLAINTEXT_MODE_ID) {
|
||||
return modeService.getOrCreateModeByFilepathOrFirstLine(this.resource.fsPath, firstLineText); // lookup mode via resource path if the provided modeId is unspecific
|
||||
}
|
||||
|
|
|
@ -189,7 +189,7 @@ export class FileOnDiskContentProvider implements ITextModelContentProvider {
|
|||
} else if (createAsNeeded) {
|
||||
const fileOnDiskModel = this.modelService.getModel(fileOnDiskResource);
|
||||
|
||||
let mode: TPromise<IMode>;
|
||||
let mode: Promise<IMode>;
|
||||
if (fileOnDiskModel) {
|
||||
mode = this.modeService.getOrCreateMode(fileOnDiskModel.getModeId());
|
||||
} else {
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
import * as nls from 'vs/nls';
|
||||
import * as resources from 'vs/base/common/resources';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import * as mime from 'vs/base/common/mime';
|
||||
import { IFilesConfiguration, FILES_ASSOCIATIONS_CONFIG } from 'vs/platform/files/common/files';
|
||||
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
|
||||
|
@ -91,7 +90,7 @@ export const languagesExtPoint: IExtensionPoint<IRawLanguageExtensionPoint[]> =
|
|||
export class WorkbenchModeServiceImpl extends ModeServiceImpl {
|
||||
private _configurationService: IConfigurationService;
|
||||
private _extensionService: IExtensionService;
|
||||
private _onReadyPromise: TPromise<boolean>;
|
||||
private _onReadyPromise: Promise<boolean>;
|
||||
|
||||
constructor(
|
||||
@IExtensionService extensionService: IExtensionService,
|
||||
|
@ -149,12 +148,14 @@ export class WorkbenchModeServiceImpl extends ModeServiceImpl {
|
|||
});
|
||||
}
|
||||
|
||||
protected _onReady(): TPromise<boolean> {
|
||||
protected _onReady(): Promise<boolean> {
|
||||
if (!this._onReadyPromise) {
|
||||
this._onReadyPromise = this._extensionService.whenInstalledExtensionsRegistered().then(() => {
|
||||
this.updateMime();
|
||||
return true;
|
||||
});
|
||||
this._onReadyPromise = Promise.resolve(
|
||||
this._extensionService.whenInstalledExtensionsRegistered().then(() => {
|
||||
this.updateMime();
|
||||
return true;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
return this._onReadyPromise;
|
||||
|
|
|
@ -492,7 +492,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
|
|||
return this.backupFileService.resolveBackupContent(backup).then(backupContent => backupContent, error => null /* ignore errors */);
|
||||
}
|
||||
|
||||
protected getOrCreateMode(modeService: IModeService, preferredModeIds: string, firstLineText?: string): TPromise<IMode> {
|
||||
protected getOrCreateMode(modeService: IModeService, preferredModeIds: string, firstLineText?: string): Promise<IMode> {
|
||||
return modeService.getOrCreateModeByFilepathOrFirstLine(this.resource.fsPath, firstLineText);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue