diff --git a/src/vs/workbench/parts/preferences/browser/keybindingsEditor.ts b/src/vs/workbench/parts/preferences/browser/keybindingsEditor.ts index d6dc44341ec..c06fb76f736 100644 --- a/src/vs/workbench/parts/preferences/browser/keybindingsEditor.ts +++ b/src/vs/workbench/parts/preferences/browser/keybindingsEditor.ts @@ -5,7 +5,6 @@ import 'vs/css!./media/keybindingsEditor'; import { localize } from 'vs/nls'; -import { TPromise } from 'vs/base/common/winjs.base'; import { Delayer } from 'vs/base/common/async'; import * as DOM from 'vs/base/browser/dom'; import { OS } from 'vs/base/common/platform'; @@ -154,7 +153,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor return focusedElement && focusedElement.templateId === KEYBINDING_ENTRY_TEMPLATE_ID ? focusedElement : null; } - defineKeybinding(keybindingEntry: IKeybindingItemEntry): TPromise { + defineKeybinding(keybindingEntry: IKeybindingItemEntry): Thenable { this.selectEntry(keybindingEntry); this.showOverlayContainer(); return this.defineKeybindingWidget.define().then(key => { @@ -182,7 +181,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor }); } - removeKeybinding(keybindingEntry: IKeybindingItemEntry): TPromise { + removeKeybinding(keybindingEntry: IKeybindingItemEntry): Thenable { this.selectEntry(keybindingEntry); if (keybindingEntry.keybindingItem.keybinding) { // This should be a pre-condition this.reportKeybindingAction(KEYBINDINGS_EDITOR_COMMAND_REMOVE, keybindingEntry.keybindingItem.command, keybindingEntry.keybindingItem.keybinding); @@ -193,10 +192,10 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor this.selectEntry(keybindingEntry); }); } - return TPromise.as(null); + return Promise.resolve(null); } - resetKeybinding(keybindingEntry: IKeybindingItemEntry): TPromise { + resetKeybinding(keybindingEntry: IKeybindingItemEntry): Thenable { this.selectEntry(keybindingEntry); this.reportKeybindingAction(KEYBINDINGS_EDITOR_COMMAND_RESET, keybindingEntry.keybindingItem.command, keybindingEntry.keybindingItem.keybinding); return this.keybindingEditingService.resetKeybinding(keybindingEntry.keybindingItem.keybindingItem) @@ -212,7 +211,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor }); } - copyKeybinding(keybinding: IKeybindingItemEntry): TPromise { + copyKeybinding(keybinding: IKeybindingItemEntry): void { this.selectEntry(keybinding); this.reportKeybindingAction(KEYBINDINGS_EDITOR_COMMAND_COPY, keybinding.keybindingItem.command, keybinding.keybindingItem.keybinding); const userFriendlyKeybinding: IUserFriendlyKeybinding = { @@ -223,14 +222,12 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor userFriendlyKeybinding.when = keybinding.keybindingItem.when; } this.clipboardService.writeText(JSON.stringify(userFriendlyKeybinding, null, ' ')); - return TPromise.as(null); } - copyKeybindingCommand(keybinding: IKeybindingItemEntry): TPromise { + copyKeybindingCommand(keybinding: IKeybindingItemEntry): void { this.selectEntry(keybinding); this.reportKeybindingAction(KEYBINDINGS_EDITOR_COMMAND_COPY_COMMAND, keybinding.keybindingItem.command, keybinding.keybindingItem.keybinding); this.clipboardService.writeText(keybinding.keybindingItem.command); - return TPromise.as(null); } focusSearch(): void { @@ -246,12 +243,11 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor this.searchWidget.clear(); } - showSimilarKeybindings(keybindingEntry: IKeybindingItemEntry): TPromise { + showSimilarKeybindings(keybindingEntry: IKeybindingItemEntry): void { const value = `"${keybindingEntry.keybindingItem.keybinding.getAriaLabel()}"`; if (value !== this.searchWidget.getValue()) { this.searchWidget.setValue(value); } - return TPromise.as(null); } private createAriaLabelElement(parent: HTMLElement): void { @@ -425,7 +421,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor })); } - private render(preserveFocus: boolean, token: CancellationToken): TPromise { + private render(preserveFocus: boolean, token: CancellationToken): Thenable { if (this.input) { return this.input.resolve() .then((keybindingsModel: KeybindingsEditorModel) => { @@ -450,7 +446,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor this.renderKeybindingsEntries(false, preserveFocus); }); } - return TPromise.as(null); + return Promise.resolve(); } private filterKeybindings(): void { diff --git a/src/vs/workbench/parts/preferences/common/preferences.ts b/src/vs/workbench/parts/preferences/common/preferences.ts index 10a020ce49f..ac13278f91d 100644 --- a/src/vs/workbench/parts/preferences/common/preferences.ts +++ b/src/vs/workbench/parts/preferences/common/preferences.ts @@ -3,7 +3,6 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { TPromise } from 'vs/base/common/winjs.base'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { RawContextKey } from 'vs/platform/contextkey/common/contextkey'; import { join } from 'vs/base/common/paths'; @@ -54,12 +53,12 @@ export interface IKeybindingsEditor extends IEditor { focusKeybindings(): void; recordSearchKeys(): void; toggleSortByPrecedence(): void; - defineKeybinding(keybindingEntry: IKeybindingItemEntry): TPromise; - removeKeybinding(keybindingEntry: IKeybindingItemEntry): TPromise; - resetKeybinding(keybindingEntry: IKeybindingItemEntry): TPromise; - copyKeybinding(keybindingEntry: IKeybindingItemEntry): TPromise; - copyKeybindingCommand(keybindingEntry: IKeybindingItemEntry): TPromise; - showSimilarKeybindings(keybindingEntry: IKeybindingItemEntry): TPromise; + defineKeybinding(keybindingEntry: IKeybindingItemEntry): Thenable; + removeKeybinding(keybindingEntry: IKeybindingItemEntry): Thenable; + resetKeybinding(keybindingEntry: IKeybindingItemEntry): Thenable; + copyKeybinding(keybindingEntry: IKeybindingItemEntry): void; + copyKeybindingCommand(keybindingEntry: IKeybindingItemEntry): void; + showSimilarKeybindings(keybindingEntry: IKeybindingItemEntry): void; } export const CONTEXT_SETTINGS_EDITOR = new RawContextKey('inSettingsEditor', false); diff --git a/src/vs/workbench/services/configuration/test/electron-browser/configurationEditingService.test.ts b/src/vs/workbench/services/configuration/test/electron-browser/configurationEditingService.test.ts index 629b122882d..8bd6c1af4f6 100644 --- a/src/vs/workbench/services/configuration/test/electron-browser/configurationEditingService.test.ts +++ b/src/vs/workbench/services/configuration/test/electron-browser/configurationEditingService.test.ts @@ -35,7 +35,6 @@ import { INotificationService } from 'vs/platform/notification/common/notificati import { ICommandService } from 'vs/platform/commands/common/commands'; import { CommandService } from 'vs/workbench/services/commands/common/commandService'; import { URI } from 'vs/base/common/uri'; -import { TPromise } from 'vs/base/common/winjs.base'; import { createHash } from 'crypto'; class SettingsTestEnvironmentService extends EnvironmentService { @@ -83,14 +82,14 @@ suite('ConfigurationEditingService', () => { .then(() => setUpServices()); }); - function setUpWorkspace(): TPromise { + async function setUpWorkspace(): Promise { const id = uuid.generateUuid(); parentDir = path.join(os.tmpdir(), 'vsctests', id); workspaceDir = path.join(parentDir, 'workspaceconfig', id); globalSettingsFile = path.join(workspaceDir, 'config.json'); workspaceSettingsDir = path.join(workspaceDir, '.vscode'); - return mkdirp(workspaceSettingsDir, 493); + return await mkdirp(workspaceSettingsDir, 493); } function setUpServices(noWorkspace: boolean = false): Promise { diff --git a/src/vs/workbench/services/keybinding/common/keybindingEditing.ts b/src/vs/workbench/services/keybinding/common/keybindingEditing.ts index d7276583746..c88ed827ba1 100644 --- a/src/vs/workbench/services/keybinding/common/keybindingEditing.ts +++ b/src/vs/workbench/services/keybinding/common/keybindingEditing.ts @@ -11,7 +11,6 @@ import { Edit } from 'vs/base/common/jsonFormatter'; import { Disposable, IReference } from 'vs/base/common/lifecycle'; import { isArray } from 'vs/base/common/types'; import { URI } from 'vs/base/common/uri'; -import { TPromise } from 'vs/base/common/winjs.base'; import { EditOperation } from 'vs/editor/common/core/editOperation'; import { Range } from 'vs/editor/common/core/range'; import { Selection } from 'vs/editor/common/core/selection'; @@ -33,11 +32,11 @@ export interface IKeybindingEditingService { _serviceBrand: ServiceIdentifier; - editKeybinding(key: string, keybindingItem: ResolvedKeybindingItem): TPromise; + editKeybinding(key: string, keybindingItem: ResolvedKeybindingItem): Thenable; - removeKeybinding(keybindingItem: ResolvedKeybindingItem): TPromise; + removeKeybinding(keybindingItem: ResolvedKeybindingItem): Thenable; - resetKeybinding(keybindingItem: ResolvedKeybindingItem): TPromise; + resetKeybinding(keybindingItem: ResolvedKeybindingItem): Thenable; } export class KeybindingsEditingService extends Disposable implements IKeybindingEditingService { @@ -58,19 +57,19 @@ export class KeybindingsEditingService extends Disposable implements IKeybinding this.queue = new Queue(); } - editKeybinding(key: string, keybindingItem: ResolvedKeybindingItem): TPromise { + editKeybinding(key: string, keybindingItem: ResolvedKeybindingItem): Thenable { return this.queue.queue(() => this.doEditKeybinding(key, keybindingItem)); // queue up writes to prevent race conditions } - resetKeybinding(keybindingItem: ResolvedKeybindingItem): TPromise { + resetKeybinding(keybindingItem: ResolvedKeybindingItem): Thenable { return this.queue.queue(() => this.doResetKeybinding(keybindingItem)); // queue up writes to prevent race conditions } - removeKeybinding(keybindingItem: ResolvedKeybindingItem): TPromise { + removeKeybinding(keybindingItem: ResolvedKeybindingItem): Thenable { return this.queue.queue(() => this.doRemoveKeybinding(keybindingItem)); // queue up writes to prevent race conditions } - private doEditKeybinding(key: string, keybindingItem: ResolvedKeybindingItem): TPromise { + private doEditKeybinding(key: string, keybindingItem: ResolvedKeybindingItem): Thenable { return this.resolveAndValidate() .then(reference => { const model = reference.object.textEditorModel; @@ -84,7 +83,7 @@ export class KeybindingsEditingService extends Disposable implements IKeybinding }); } - private doRemoveKeybinding(keybindingItem: ResolvedKeybindingItem): TPromise { + private doRemoveKeybinding(keybindingItem: ResolvedKeybindingItem): Thenable { return this.resolveAndValidate() .then(reference => { const model = reference.object.textEditorModel; @@ -97,7 +96,7 @@ export class KeybindingsEditingService extends Disposable implements IKeybinding }); } - private doResetKeybinding(keybindingItem: ResolvedKeybindingItem): TPromise { + private doResetKeybinding(keybindingItem: ResolvedKeybindingItem): Thenable { return this.resolveAndValidate() .then(reference => { const model = reference.object.textEditorModel; @@ -109,7 +108,7 @@ export class KeybindingsEditingService extends Disposable implements IKeybinding }); } - private save(): TPromise { + private save(): Thenable { return this.textFileService.save(this.resource); } @@ -198,20 +197,20 @@ export class KeybindingsEditingService extends Disposable implements IKeybinding } - private resolveModelReference(): TPromise> { + private resolveModelReference(): Thenable> { return this.fileService.existsFile(this.resource) .then(exists => { const EOL = this.configurationService.getValue('files', { overrideIdentifier: 'json' })['eol']; - const result = exists ? TPromise.as(null) : this.fileService.updateContent(this.resource, this.getEmptyContent(EOL), { encoding: 'utf8' }); + const result: Thenable = exists ? Promise.resolve(null) : this.fileService.updateContent(this.resource, this.getEmptyContent(EOL), { encoding: 'utf8' }); return result.then(() => this.textModelResolverService.createModelReference(this.resource)); }); } - private resolveAndValidate(): TPromise> { + private resolveAndValidate(): Thenable> { // Target cannot be dirty if not writing into buffer if (this.textFileService.isDirty(this.resource)) { - return TPromise.wrapError>(new Error(localize('errorKeybindingsFileDirty', "Unable to write because the keybindings configuration file is dirty. Please save it first and then try again."))); + return Promise.reject(new Error(localize('errorKeybindingsFileDirty', "Unable to write because the keybindings configuration file is dirty. Please save it first and then try again."))); } return this.resolveModelReference() @@ -221,11 +220,11 @@ export class KeybindingsEditingService extends Disposable implements IKeybinding if (model.getValue()) { const parsed = this.parse(model); if (parsed.parseErrors.length) { - return TPromise.wrapError>(new Error(localize('parseErrors', "Unable to write to the keybindings configuration file. Please open it to correct errors/warnings in the file and try again."))); + return Promise.reject(new Error(localize('parseErrors', "Unable to write to the keybindings configuration file. Please open it to correct errors/warnings in the file and try again."))); } if (parsed.result) { if (!isArray(parsed.result)) { - return TPromise.wrapError>(new Error(localize('errorInvalidConfiguration', "Unable to write to the keybindings configuration file. It has an object which is not of type Array. Please open the file to clean up and try again."))); + return Promise.reject(new Error(localize('errorInvalidConfiguration', "Unable to write to the keybindings configuration file. It has an object which is not of type Array. Please open the file to clean up and try again."))); } } else { const content = EOL + '[]'; diff --git a/src/vs/workbench/services/keybinding/test/electron-browser/keybindingEditing.test.ts b/src/vs/workbench/services/keybinding/test/electron-browser/keybindingEditing.test.ts index 534d2387698..7ea35c1411f 100644 --- a/src/vs/workbench/services/keybinding/test/electron-browser/keybindingEditing.test.ts +++ b/src/vs/workbench/services/keybinding/test/electron-browser/keybindingEditing.test.ts @@ -11,7 +11,6 @@ import * as json from 'vs/base/common/json'; import { ChordKeybinding, KeyCode, SimpleKeybinding } from 'vs/base/common/keyCodes'; import { OS } from 'vs/base/common/platform'; import * as uuid from 'vs/base/common/uuid'; -import { TPromise } from 'vs/base/common/winjs.base'; import * as extfs from 'vs/base/node/extfs'; import { mkdirp } from 'vs/base/node/pfs'; import { IModeService } from 'vs/editor/common/services/modeService'; @@ -104,9 +103,9 @@ suite('KeybindingsEditing', () => { }); }); - function setUpWorkspace(): TPromise { + async function setUpWorkspace(): Promise { testDir = path.join(os.tmpdir(), 'vsctests', uuid.generateUuid()); - return mkdirp(testDir, 493); + return await mkdirp(testDir, 493); } teardown(() => {