From d6b26a567db43bf04175fdf69e5bc619702cf923 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Tue, 11 Dec 2018 13:04:12 +0100 Subject: [PATCH] fix #64596 --- src/vs/code/electron-main/app.ts | 41 ++++---- src/vs/code/electron-main/windows.ts | 6 +- .../windows/electron-main/windowsService.ts | 7 +- src/vs/platform/windows/node/windowsIpc.ts | 98 +++++++++---------- .../platform/workspaces/node/workspacesIpc.ts | 2 +- .../browser/parts/editor/editorControl.ts | 2 +- src/vs/workbench/common/editor.ts | 6 +- .../editor/test/browser/editorService.test.ts | 20 ++-- .../test/browser/editorGroupsService.test.ts | 8 ++ .../textfile/common/textFileService.ts | 6 +- .../electron-browser/textFileService.ts | 4 +- .../textfile/test/textFileEditorModel.test.ts | 6 +- .../textfile/test/textFileService.test.ts | 2 +- .../workbench/test/workbenchTestServices.ts | 14 +-- 14 files changed, 118 insertions(+), 104 deletions(-) diff --git a/src/vs/code/electron-main/app.ts b/src/vs/code/electron-main/app.ts index dcfbe3a9315..fffc1ed85e8 100644 --- a/src/vs/code/electron-main/app.ts +++ b/src/vs/code/electron-main/app.ts @@ -412,9 +412,7 @@ export class CodeApplication extends Disposable { // Create Electron IPC Server this.electronIpcServer = new ElectronIPCServer(); - // Resolve unique machine ID - this.logService.trace('Resolving machine identifier...'); - return this.resolveMachineId().then(machineId => { + const startupWithMachineId = (machineId: string) => { this.logService.trace(`Resolved machine identifier: ${machineId}`); // Spawn shared process @@ -447,6 +445,28 @@ export class CodeApplication extends Disposable { this.stopTracingEventually(windows); } }); + }; + + // Resolve unique machine ID + this.logService.trace('Resolving machine identifier...'); + const resolvedMachineId = this.resolveMachineId(); + if (typeof resolvedMachineId === 'string') { + return startupWithMachineId(resolvedMachineId); + } else { + return resolvedMachineId.then(machineId => startupWithMachineId(machineId)); + } + } + + private resolveMachineId(): string | TPromise { + const machineId = this.stateService.getItem(CodeApplication.MACHINE_ID_KEY); + if (machineId) { + return machineId; + } + + return getMachineId().then(machineId => { + this.stateService.setItem(CodeApplication.MACHINE_ID_KEY, machineId); + + return machineId; }); } @@ -485,21 +505,6 @@ export class CodeApplication extends Disposable { }); } - private resolveMachineId(): TPromise { - const machineId = this.stateService.getItem(CodeApplication.MACHINE_ID_KEY); - if (machineId) { - return TPromise.wrap(machineId); - } - - return getMachineId().then(machineId => { - - // Remember in global storage - this.stateService.setItem(CodeApplication.MACHINE_ID_KEY, machineId); - - return machineId; - }); - } - private initServices(machineId: string): Thenable { const services = new ServiceCollection(); diff --git a/src/vs/code/electron-main/windows.ts b/src/vs/code/electron-main/windows.ts index 24c4df7ebff..299b9727c74 100644 --- a/src/vs/code/electron-main/windows.ts +++ b/src/vs/code/electron-main/windows.ts @@ -2029,11 +2029,11 @@ class WorkspacesManager { private isValidTargetWorkspacePath(window: ICodeWindow, path?: string): TPromise { if (!path) { - return TPromise.wrap(true); + return Promise.resolve(true); } if (window.openedWorkspace && window.openedWorkspace.configPath === path) { - return TPromise.wrap(false); // window is already opened on a workspace with that path + return Promise.resolve(false); // window is already opened on a workspace with that path } // Prevent overwriting a workspace that is currently opened in another window @@ -2050,7 +2050,7 @@ class WorkspacesManager { return this.windowsMainService.showMessageBox(options, this.windowsMainService.getFocusedWindow()).then(() => false); } - return TPromise.wrap(true); // OK + return Promise.resolve(true); // OK } private doSaveAndOpenWorkspace(window: ICodeWindow, workspace: IWorkspaceIdentifier, path?: string): TPromise { diff --git a/src/vs/platform/windows/electron-main/windowsService.ts b/src/vs/platform/windows/electron-main/windowsService.ts index 673fd375f50..33ea310a064 100644 --- a/src/vs/platform/windows/electron-main/windowsService.ts +++ b/src/vs/platform/windows/electron-main/windowsService.ts @@ -551,18 +551,17 @@ export class WindowsService implements IWindowsService, IURLHandler, IDisposable // Catch file URLs if (uri.authority === Schemas.file && !!uri.path) { this.openFileForURI(URI.file(uri.fsPath)); - return TPromise.as(true); + return Promise.resolve(true); } - return TPromise.wrap(false); + return Promise.resolve(false); } - private openFileForURI(uri: URI): TPromise { + private openFileForURI(uri: URI): void { const cli = assign(Object.create(null), this.environmentService.args, { goto: true }); const urisToOpen = [uri]; this.windowsMainService.open({ context: OpenContext.API, cli, urisToOpen }); - return TPromise.wrap(true); } resolveProxy(windowId: number, url: string): Promise { diff --git a/src/vs/platform/windows/node/windowsIpc.ts b/src/vs/platform/windows/node/windowsIpc.ts index 70f26fc1d8b..5db77e820f7 100644 --- a/src/vs/platform/windows/node/windowsIpc.ts +++ b/src/vs/platform/windows/node/windowsIpc.ts @@ -137,79 +137,79 @@ export class WindowsChannelClient implements IWindowsService { get onRecentlyOpenedChange(): Event { return this.channel.listen('onRecentlyOpenedChange'); } pickFileFolderAndOpen(options: INativeOpenDialogOptions): TPromise { - return TPromise.wrap(this.channel.call('pickFileFolderAndOpen', options)); + return this.channel.call('pickFileFolderAndOpen', options); } pickFileAndOpen(options: INativeOpenDialogOptions): TPromise { - return TPromise.wrap(this.channel.call('pickFileAndOpen', options)); + return this.channel.call('pickFileAndOpen', options); } pickFolderAndOpen(options: INativeOpenDialogOptions): TPromise { - return TPromise.wrap(this.channel.call('pickFolderAndOpen', options)); + return this.channel.call('pickFolderAndOpen', options); } pickWorkspaceAndOpen(options: INativeOpenDialogOptions): TPromise { - return TPromise.wrap(this.channel.call('pickWorkspaceAndOpen', options)); + return this.channel.call('pickWorkspaceAndOpen', options); } showMessageBox(windowId: number, options: MessageBoxOptions): TPromise { - return TPromise.wrap(this.channel.call('showMessageBox', [windowId, options])); + return this.channel.call('showMessageBox', [windowId, options]); } showSaveDialog(windowId: number, options: SaveDialogOptions): TPromise { - return TPromise.wrap(this.channel.call('showSaveDialog', [windowId, options])); + return this.channel.call('showSaveDialog', [windowId, options]); } showOpenDialog(windowId: number, options: OpenDialogOptions): TPromise { - return TPromise.wrap(this.channel.call('showOpenDialog', [windowId, options])); + return this.channel.call('showOpenDialog', [windowId, options]); } reloadWindow(windowId: number, args?: ParsedArgs): TPromise { - return TPromise.wrap(this.channel.call('reloadWindow', [windowId, args])); + return this.channel.call('reloadWindow', [windowId, args]); } openDevTools(windowId: number, options?: IDevToolsOptions): TPromise { - return TPromise.wrap(this.channel.call('openDevTools', [windowId, options])); + return this.channel.call('openDevTools', [windowId, options]); } toggleDevTools(windowId: number): TPromise { - return TPromise.wrap(this.channel.call('toggleDevTools', windowId)); + return this.channel.call('toggleDevTools', windowId); } closeWorkspace(windowId: number): TPromise { - return TPromise.wrap(this.channel.call('closeWorkspace', windowId)); + return this.channel.call('closeWorkspace', windowId); } enterWorkspace(windowId: number, path: string): TPromise { - return TPromise.wrap(this.channel.call('enterWorkspace', [windowId, path])); + return this.channel.call('enterWorkspace', [windowId, path]); } createAndEnterWorkspace(windowId: number, folders?: IWorkspaceFolderCreationData[], path?: string): TPromise { - return TPromise.wrap(this.channel.call('createAndEnterWorkspace', [windowId, folders, path])); + return this.channel.call('createAndEnterWorkspace', [windowId, folders, path]); } saveAndEnterWorkspace(windowId: number, path: string): TPromise { - return TPromise.wrap(this.channel.call('saveAndEnterWorkspace', [windowId, path])); + return this.channel.call('saveAndEnterWorkspace', [windowId, path]); } toggleFullScreen(windowId: number): TPromise { - return TPromise.wrap(this.channel.call('toggleFullScreen', windowId)); + return this.channel.call('toggleFullScreen', windowId); } setRepresentedFilename(windowId: number, fileName: string): TPromise { - return TPromise.wrap(this.channel.call('setRepresentedFilename', [windowId, fileName])); + return this.channel.call('setRepresentedFilename', [windowId, fileName]); } addRecentlyOpened(files: URI[]): TPromise { - return TPromise.wrap(this.channel.call('addRecentlyOpened', files)); + return this.channel.call('addRecentlyOpened', files); } removeFromRecentlyOpened(paths: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | URI)[]): TPromise { - return TPromise.wrap(this.channel.call('removeFromRecentlyOpened', paths)); + return this.channel.call('removeFromRecentlyOpened', paths); } clearRecentlyOpened(): TPromise { - return TPromise.wrap(this.channel.call('clearRecentlyOpened')); + return this.channel.call('clearRecentlyOpened'); } getRecentlyOpened(windowId: number): TPromise { @@ -222,83 +222,83 @@ export class WindowsChannelClient implements IWindowsService { } newWindowTab(): TPromise { - return TPromise.wrap(this.channel.call('newWindowTab')); + return this.channel.call('newWindowTab'); } showPreviousWindowTab(): TPromise { - return TPromise.wrap(this.channel.call('showPreviousWindowTab')); + return this.channel.call('showPreviousWindowTab'); } showNextWindowTab(): TPromise { - return TPromise.wrap(this.channel.call('showNextWindowTab')); + return this.channel.call('showNextWindowTab'); } moveWindowTabToNewWindow(): TPromise { - return TPromise.wrap(this.channel.call('moveWindowTabToNewWindow')); + return this.channel.call('moveWindowTabToNewWindow'); } mergeAllWindowTabs(): TPromise { - return TPromise.wrap(this.channel.call('mergeAllWindowTabs')); + return this.channel.call('mergeAllWindowTabs'); } toggleWindowTabsBar(): TPromise { - return TPromise.wrap(this.channel.call('toggleWindowTabsBar')); + return this.channel.call('toggleWindowTabsBar'); } focusWindow(windowId: number): TPromise { - return TPromise.wrap(this.channel.call('focusWindow', windowId)); + return this.channel.call('focusWindow', windowId); } closeWindow(windowId: number): TPromise { - return TPromise.wrap(this.channel.call('closeWindow', windowId)); + return this.channel.call('closeWindow', windowId); } isFocused(windowId: number): TPromise { - return TPromise.wrap(this.channel.call('isFocused', windowId)); + return this.channel.call('isFocused', windowId); } isMaximized(windowId: number): TPromise { - return TPromise.wrap(this.channel.call('isMaximized', windowId)); + return this.channel.call('isMaximized', windowId); } maximizeWindow(windowId: number): TPromise { - return TPromise.wrap(this.channel.call('maximizeWindow', windowId)); + return this.channel.call('maximizeWindow', windowId); } unmaximizeWindow(windowId: number): TPromise { - return TPromise.wrap(this.channel.call('unmaximizeWindow', windowId)); + return this.channel.call('unmaximizeWindow', windowId); } minimizeWindow(windowId: number): TPromise { - return TPromise.wrap(this.channel.call('minimizeWindow', windowId)); + return this.channel.call('minimizeWindow', windowId); } onWindowTitleDoubleClick(windowId: number): TPromise { - return TPromise.wrap(this.channel.call('onWindowTitleDoubleClick', windowId)); + return this.channel.call('onWindowTitleDoubleClick', windowId); } setDocumentEdited(windowId: number, flag: boolean): TPromise { - return TPromise.wrap(this.channel.call('setDocumentEdited', [windowId, flag])); + return this.channel.call('setDocumentEdited', [windowId, flag]); } quit(): TPromise { - return TPromise.wrap(this.channel.call('quit')); + return this.channel.call('quit'); } relaunch(options: { addArgs?: string[], removeArgs?: string[] }): TPromise { - return TPromise.wrap(this.channel.call('relaunch', [options])); + return this.channel.call('relaunch', [options]); } whenSharedProcessReady(): TPromise { - return TPromise.wrap(this.channel.call('whenSharedProcessReady')); + return this.channel.call('whenSharedProcessReady'); } toggleSharedProcess(): TPromise { - return TPromise.wrap(this.channel.call('toggleSharedProcess')); + return this.channel.call('toggleSharedProcess'); } openWindow(windowId: number, paths: URI[], options?: { forceNewWindow?: boolean, forceReuseWindow?: boolean, forceOpenWorkspaceAsFile?: boolean, args?: ParsedArgs }): TPromise { - return TPromise.wrap(this.channel.call('openWindow', [windowId, paths, options])); + return this.channel.call('openWindow', [windowId, paths, options]); } openNewWindow(options?: INewWindowOptions): TPromise { @@ -306,43 +306,43 @@ export class WindowsChannelClient implements IWindowsService { } showWindow(windowId: number): TPromise { - return TPromise.wrap(this.channel.call('showWindow', windowId)); + return this.channel.call('showWindow', windowId); } getWindows(): TPromise<{ id: number; workspace?: IWorkspaceIdentifier; folderUri?: ISingleFolderWorkspaceIdentifier; title: string; filename?: string; }[]> { - return TPromise.wrap(this.channel.call<{ id: number; workspace?: IWorkspaceIdentifier; folderUri?: ISingleFolderWorkspaceIdentifier; title: string; filename?: string; }[]>('getWindows').then(result => { result.forEach(win => win.folderUri = win.folderUri ? URI.revive(win.folderUri) : win.folderUri); return result; })); + return this.channel.call<{ id: number; workspace?: IWorkspaceIdentifier; folderUri?: ISingleFolderWorkspaceIdentifier; title: string; filename?: string; }[]>('getWindows').then(result => { result.forEach(win => win.folderUri = win.folderUri ? URI.revive(win.folderUri) : win.folderUri); return result; }); } getWindowCount(): TPromise { - return TPromise.wrap(this.channel.call('getWindowCount')); + return this.channel.call('getWindowCount'); } log(severity: string, ...messages: string[]): TPromise { - return TPromise.wrap(this.channel.call('log', [severity, messages])); + return this.channel.call('log', [severity, messages]); } showItemInFolder(path: string): TPromise { - return TPromise.wrap(this.channel.call('showItemInFolder', path)); + return this.channel.call('showItemInFolder', path); } getActiveWindowId(): TPromise { - return TPromise.wrap(this.channel.call('getActiveWindowId')); + return this.channel.call('getActiveWindowId'); } openExternal(url: string): TPromise { - return TPromise.wrap(this.channel.call('openExternal', url)); + return this.channel.call('openExternal', url); } startCrashReporter(config: CrashReporterStartOptions): TPromise { - return TPromise.wrap(this.channel.call('startCrashReporter', config)); + return this.channel.call('startCrashReporter', config); } updateTouchBar(windowId: number, items: ISerializableCommandAction[][]): TPromise { - return TPromise.wrap(this.channel.call('updateTouchBar', [windowId, items])); + return this.channel.call('updateTouchBar', [windowId, items]); } openAboutDialog(): TPromise { - return TPromise.wrap(this.channel.call('openAboutDialog')); + return this.channel.call('openAboutDialog'); } resolveProxy(windowId: number, url: string): Promise { diff --git a/src/vs/platform/workspaces/node/workspacesIpc.ts b/src/vs/platform/workspaces/node/workspacesIpc.ts index 333407eff5c..f69ba502696 100644 --- a/src/vs/platform/workspaces/node/workspacesIpc.ts +++ b/src/vs/platform/workspaces/node/workspacesIpc.ts @@ -46,6 +46,6 @@ export class WorkspacesChannelClient implements IWorkspacesService { constructor(private channel: IChannel) { } createWorkspace(folders?: IWorkspaceFolderCreationData[]): TPromise { - return TPromise.wrap(this.channel.call('createWorkspace', folders)); + return this.channel.call('createWorkspace', folders); } } \ No newline at end of file diff --git a/src/vs/workbench/browser/parts/editor/editorControl.ts b/src/vs/workbench/browser/parts/editor/editorControl.ts index 573d7dccd59..056885c30c8 100644 --- a/src/vs/workbench/browser/parts/editor/editorControl.ts +++ b/src/vs/workbench/browser/parts/editor/editorControl.ts @@ -172,7 +172,7 @@ export class EditorControl extends Disposable { // Call into editor control const editorWillChange = !inputMatches; - return TPromise.wrap(control.setInput(editor, options, operation.token)).then(() => { + return control.setInput(editor, options, operation.token).then(() => { // Focus (unless prevented or another operation is running) if (operation.isCurrent()) { diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index 58687f33002..898b49f23fd 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -416,21 +416,21 @@ export abstract class EditorInput extends Disposable implements IEditorInput { * Subclasses should bring up a proper dialog for the user if the editor is dirty and return the result. */ confirmSave(): TPromise { - return TPromise.wrap(ConfirmResult.DONT_SAVE); + return Promise.resolve(ConfirmResult.DONT_SAVE); } /** * Saves the editor if it is dirty. Subclasses return a promise with a boolean indicating the success of the operation. */ save(): TPromise { - return TPromise.as(true); + return Promise.resolve(true); } /** * Reverts the editor if it is dirty. Subclasses return a promise with a boolean indicating the success of the operation. */ revert(options?: IRevertOptions): TPromise { - return TPromise.as(true); + return Promise.resolve(true); } /** diff --git a/src/vs/workbench/services/editor/test/browser/editorService.test.ts b/src/vs/workbench/services/editor/test/browser/editorService.test.ts index e32896221a3..4431a33a750 100644 --- a/src/vs/workbench/services/editor/test/browser/editorService.test.ts +++ b/src/vs/workbench/services/editor/test/browser/editorService.test.ts @@ -27,6 +27,7 @@ import { FileEditorInput } from 'vs/workbench/parts/files/common/editors/fileEdi import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput'; import { EditorServiceImpl } from 'vs/workbench/browser/parts/editor/editor'; import { CancellationToken } from 'vs/base/common/cancellation'; +import { timeout } from 'vs/base/common/async'; export class TestEditorControl extends BaseEditor { @@ -393,6 +394,11 @@ suite('Editor service', () => { visibleEditorChangeEventFired = false; } + async function closeEditorAndWaitForNextToOpen(group: IEditorGroup, input: EditorInput): Promise { + await group.closeEditor(input); + await timeout(0); // closing an editor will not immediately open the next one, so we need to wait + } + await part.whenRestored; // 1.) open, open same, open other, close @@ -409,11 +415,11 @@ suite('Editor service', () => { assertActiveEditorChangedEvent(true); assertVisibleEditorsChangedEvent(true); - await group.closeEditor(otherInput); + await closeEditorAndWaitForNextToOpen(group, otherInput); assertActiveEditorChangedEvent(true); assertVisibleEditorsChangedEvent(true); - await group.closeEditor(input); + await closeEditorAndWaitForNextToOpen(group, input); assertActiveEditorChangedEvent(true); assertVisibleEditorsChangedEvent(true); @@ -426,7 +432,7 @@ suite('Editor service', () => { assertActiveEditorChangedEvent(false); assertVisibleEditorsChangedEvent(false); - await group.closeEditor(input); + await closeEditorAndWaitForNextToOpen(group, input); // 3.) open, open inactive, close editor = await service.openEditor(input, { pinned: true }); @@ -450,7 +456,7 @@ suite('Editor service', () => { assertActiveEditorChangedEvent(false); assertVisibleEditorsChangedEvent(false); - await group.closeEditor(otherInput); + await closeEditorAndWaitForNextToOpen(group, otherInput); assertActiveEditorChangedEvent(false); assertVisibleEditorsChangedEvent(false); @@ -492,7 +498,7 @@ suite('Editor service', () => { assertActiveEditorChangedEvent(true); assertVisibleEditorsChangedEvent(true); - await rightGroup.closeEditor(otherInput); + await closeEditorAndWaitForNextToOpen(rightGroup, otherInput); assertActiveEditorChangedEvent(true); assertVisibleEditorsChangedEvent(true); @@ -517,7 +523,7 @@ suite('Editor service', () => { assertActiveEditorChangedEvent(true); assertVisibleEditorsChangedEvent(false); - await rightGroup.closeEditor(otherInput); + await closeEditorAndWaitForNextToOpen(rightGroup, otherInput); assertActiveEditorChangedEvent(false); assertVisibleEditorsChangedEvent(true); @@ -555,7 +561,7 @@ suite('Editor service', () => { assertActiveEditorChangedEvent(true); assertVisibleEditorsChangedEvent(true); - await group.closeEditor(input); + await closeEditorAndWaitForNextToOpen(group, input); assertActiveEditorChangedEvent(false); assertVisibleEditorsChangedEvent(true); diff --git a/src/vs/workbench/services/group/test/browser/editorGroupsService.test.ts b/src/vs/workbench/services/group/test/browser/editorGroupsService.test.ts index e62efab0781..15dc2897979 100644 --- a/src/vs/workbench/services/group/test/browser/editorGroupsService.test.ts +++ b/src/vs/workbench/services/group/test/browser/editorGroupsService.test.ts @@ -20,11 +20,18 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils'; import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService'; import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; +import { CancellationToken } from 'vs/base/common/cancellation'; export class TestEditorControl extends BaseEditor { constructor(@ITelemetryService telemetryService: ITelemetryService) { super('MyFileEditorForEditorGroupService', NullTelemetryService, new TestThemeService(), new TestStorageService()); } + setInput(input: EditorInput, options: EditorOptions, token: CancellationToken): Thenable { + super.setInput(input, options, token); + + return input.resolve().then(() => void 0); + } + getId(): string { return 'MyFileEditorForEditorGroupService'; } layout(): void { } createEditor(): any { } @@ -445,6 +452,7 @@ suite('Editor groups service', () => { assert.equal(activeEditorChangeCounter, 2); assert.equal(group.activeEditor, inputInactive); + await group.openEditor(input); await group.closeEditor(inputInactive); assert.equal(activeEditorChangeCounter, 3); diff --git a/src/vs/workbench/services/textfile/common/textFileService.ts b/src/vs/workbench/services/textfile/common/textFileService.ts index 60960a60a25..f68ebcd9449 100644 --- a/src/vs/workbench/services/textfile/common/textFileService.ts +++ b/src/vs/workbench/services/textfile/common/textFileService.ts @@ -537,7 +537,7 @@ export abstract class TextFileService extends Disposable implements ITextFileSer // Get to target resource let targetPromise: TPromise; if (target) { - targetPromise = TPromise.wrap(target); + targetPromise = Promise.resolve(target); } else { let dialogPath = resource; if (resource.scheme === Schemas.untitled) { @@ -728,8 +728,8 @@ export abstract class TextFileService extends Disposable implements ITextFileSer this._onWillMove.fire({ oldResource: source, newResource: target, - waitUntil(p: Thenable) { - waitForPromises.push(TPromise.wrap(p).then(undefined, errors.onUnexpectedError)); + waitUntil(promise: Thenable) { + waitForPromises.push(promise.then(void 0, errors.onUnexpectedError)); } }); diff --git a/src/vs/workbench/services/textfile/electron-browser/textFileService.ts b/src/vs/workbench/services/textfile/electron-browser/textFileService.ts index 4bbb2385769..e2be2f12bf1 100644 --- a/src/vs/workbench/services/textfile/electron-browser/textFileService.ts +++ b/src/vs/workbench/services/textfile/electron-browser/textFileService.ts @@ -75,12 +75,12 @@ export class TextFileService extends AbstractTextFileService { confirmSave(resources?: URI[]): TPromise { if (this.environmentService.isExtensionDevelopment) { - return TPromise.wrap(ConfirmResult.DONT_SAVE); // no veto when we are in extension dev mode because we cannot assum we run interactive (e.g. tests) + return Promise.resolve(ConfirmResult.DONT_SAVE); // no veto when we are in extension dev mode because we cannot assum we run interactive (e.g. tests) } const resourcesToConfirm = this.getDirty(resources); if (resourcesToConfirm.length === 0) { - return TPromise.wrap(ConfirmResult.DONT_SAVE); + return Promise.resolve(ConfirmResult.DONT_SAVE); } const message = resourcesToConfirm.length === 1 ? nls.localize('saveChangesMessage', "Do you want to save the changes you made to {0}?", paths.basename(resourcesToConfirm[0].fsPath)) diff --git a/src/vs/workbench/services/textfile/test/textFileEditorModel.test.ts b/src/vs/workbench/services/textfile/test/textFileEditorModel.test.ts index eef43c99bdd..60f53101e9a 100644 --- a/src/vs/workbench/services/textfile/test/textFileEditorModel.test.ts +++ b/src/vs/workbench/services/textfile/test/textFileEditorModel.test.ts @@ -14,11 +14,7 @@ import { toResource } from 'vs/base/test/common/utils'; import { TextFileEditorModelManager } from 'vs/workbench/services/textfile/common/textFileEditorModelManager'; import { FileOperationResult, FileOperationError, IFileService, snapshotToString } from 'vs/platform/files/common/files'; import { IModelService } from 'vs/editor/common/services/modelService'; -import { timeout as thenableTimeout } from 'vs/base/common/async'; - -function timeout(n: number) { - return TPromise.wrap(thenableTimeout(n)); -} +import { timeout } from 'vs/base/common/async'; class ServiceAccessor { constructor(@ITextFileService public textFileService: TestTextFileService, @IModelService public modelService: IModelService, @IFileService public fileService: TestFileService) { diff --git a/src/vs/workbench/services/textfile/test/textFileService.test.ts b/src/vs/workbench/services/textfile/test/textFileService.test.ts index f50f71ca6a4..e2c623480dc 100644 --- a/src/vs/workbench/services/textfile/test/textFileService.test.ts +++ b/src/vs/workbench/services/textfile/test/textFileService.test.ts @@ -206,7 +206,7 @@ suite('Files - TextFileService', () => { const mockedFileUri = untitledUncUri.with({ scheme: Schemas.file }); const mockedEditorInput = instantiationService.createInstance(TextFileEditorModel, mockedFileUri, 'utf8'); - const loadOrCreateStub = sinon.stub(accessor.textFileService.models, 'loadOrCreate', () => TPromise.wrap(mockedEditorInput)); + const loadOrCreateStub = sinon.stub(accessor.textFileService.models, 'loadOrCreate', () => Promise.resolve(mockedEditorInput)); sinon.stub(accessor.untitledEditorService, 'exists', () => true); sinon.stub(accessor.untitledEditorService, 'hasAssociatedFilePath', () => true); diff --git a/src/vs/workbench/test/workbenchTestServices.ts b/src/vs/workbench/test/workbenchTestServices.ts index be547e15fbe..38304da328d 100644 --- a/src/vs/workbench/test/workbenchTestServices.ts +++ b/src/vs/workbench/test/workbenchTestServices.ts @@ -226,11 +226,11 @@ export class TestTextFileService extends TextFileService { } public promptForPath(_resource: URI, _defaultPath: URI): TPromise { - return TPromise.wrap(this.promptPath); + return Promise.resolve(this.promptPath); } public confirmSave(_resources?: URI[]): TPromise { - return TPromise.wrap(this.confirmResult); + return Promise.resolve(this.confirmResult); } public onFilesConfigurationChange(configuration: any): void { @@ -847,14 +847,14 @@ export class TestFileService implements IFileService { } updateContent(resource: URI, _value: string | ITextSnapshot, _options?: IUpdateContentOptions): TPromise { - return TPromise.wrap(timeout(0).then(() => ({ + return timeout(0).then(() => ({ resource, etag: 'index.txt', encoding: 'utf8', mtime: Date.now(), isDirectory: false, name: paths.basename(resource.fsPath) - }))); + })); } moveFile(_source: URI, _target: URI, _overwrite?: boolean): TPromise { @@ -1113,15 +1113,15 @@ export class TestWindowService implements IWindowService { } showMessageBox(_options: Electron.MessageBoxOptions): TPromise { - return TPromise.wrap({ button: 0 }); + return Promise.resolve({ button: 0 }); } showSaveDialog(_options: Electron.SaveDialogOptions): TPromise { - return TPromise.wrap(void 0); + return Promise.resolve(void 0); } showOpenDialog(_options: Electron.OpenDialogOptions): TPromise { - return TPromise.wrap(void 0); + return Promise.resolve(void 0); } updateTouchBar(_items: ISerializableCommandAction[][]): TPromise {