Skip to content

Commit 00702d3

Browse files
committed
debt - command service uses real promise
1 parent 87e5717 commit 00702d3

9 files changed

Lines changed: 31 additions & 35 deletions

File tree

src/vs/editor/standalone/browser/simpleServices.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,18 +240,18 @@ export class StandaloneCommandService implements ICommandService {
240240
});
241241
}
242242

243-
public executeCommand<T>(id: string, ...args: any[]): TPromise<T> {
243+
public executeCommand<T>(id: string, ...args: any[]): Promise<T> {
244244
const command = (CommandsRegistry.getCommand(id) || this._dynamicCommands[id]);
245245
if (!command) {
246-
return TPromise.wrapError<T>(new Error(`command '${id}' not found`));
246+
return Promise.reject(new Error(`command '${id}' not found`));
247247
}
248248

249249
try {
250250
this._onWillExecuteCommand.fire({ commandId: id });
251251
const result = this._instantiationService.invokeFunction.apply(this._instantiationService, [command.handler].concat(args));
252-
return TPromise.as(result);
252+
return Promise.resolve(result);
253253
} catch (err) {
254-
return TPromise.wrapError<T>(err);
254+
return Promise.reject(err);
255255
}
256256
}
257257
}

src/vs/editor/test/browser/editorTestServices.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,18 @@ export class TestCommandService implements ICommandService {
3838
this._instantiationService = instantiationService;
3939
}
4040

41-
public executeCommand<T>(id: string, ...args: any[]): TPromise<T> {
41+
public executeCommand<T>(id: string, ...args: any[]): Promise<T> {
4242
const command = CommandsRegistry.getCommand(id);
4343
if (!command) {
44-
return TPromise.wrapError<T>(new Error(`command '${id}' not found`));
44+
return Promise.reject(new Error(`command '${id}' not found`));
4545
}
4646

4747
try {
4848
this._onWillExecuteCommand.fire({ commandId: id });
4949
const result = this._instantiationService.invokeFunction.apply(this._instantiationService, [command.handler].concat(args));
50-
return TPromise.as(result);
50+
return Promise.resolve(result);
5151
} catch (err) {
52-
return TPromise.wrapError<T>(err);
52+
return Promise.reject(err);
5353
}
5454
}
5555
}

src/vs/editor/test/browser/services/openerService.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import { URI } from 'vs/base/common/uri';
88
import * as assert from 'assert';
9-
import { TPromise } from 'vs/base/common/winjs.base';
109
import { TestCodeEditorService } from 'vs/editor/test/browser/editorTestServices';
1110
import { ICommandService, NullCommandService, CommandsRegistry } from 'vs/platform/commands/common/commands';
1211
import { OpenerService } from 'vs/editor/browser/services/openerService';
@@ -20,7 +19,7 @@ suite('OpenerService', function () {
2019
const commandService = new class implements ICommandService {
2120
_serviceBrand: any;
2221
onWillExecuteCommand = () => ({ dispose: () => { } });
23-
executeCommand(id: string, ...args: any[]): TPromise<any> {
22+
executeCommand(id: string, ...args: any[]): Promise<any> {
2423
lastCommand = { id, args };
2524
return Promise.resolve(undefined);
2625
}

src/vs/platform/commands/common/commands.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*--------------------------------------------------------------------------------------------*/
55
'use strict';
66

7-
import { TPromise } from 'vs/base/common/winjs.base';
87
import { IDisposable, toDisposable } from 'vs/base/common/lifecycle';
98
import { TypeConstraint, validateConstraints } from 'vs/base/common/types';
109
import { ServicesAccessor, createDecorator } from 'vs/platform/instantiation/common/instantiation';
@@ -20,7 +19,7 @@ export interface ICommandEvent {
2019
export interface ICommandService {
2120
_serviceBrand: any;
2221
onWillExecuteCommand: Event<ICommandEvent>;
23-
executeCommand<T = any>(commandId: string, ...args: any[]): TPromise<T>;
22+
executeCommand<T = any>(commandId: string, ...args: any[]): Promise<T>;
2423
}
2524

2625
export interface ICommandsMap {
@@ -127,6 +126,6 @@ export const NullCommandService: ICommandService = {
127126
_serviceBrand: undefined,
128127
onWillExecuteCommand: () => ({ dispose: () => { } }),
129128
executeCommand() {
130-
return TPromise.as(undefined);
129+
return Promise.resolve(undefined);
131130
}
132131
};

src/vs/platform/keybinding/test/common/abstractKeybindingService.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { ICommandService } from 'vs/platform/commands/common/commands';
1414
import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingResolver';
1515
import { IContext, ContextKeyExpr, IContextKeyService, IContextKeyServiceTarget } from 'vs/platform/contextkey/common/contextkey';
1616
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
17-
import { TPromise } from 'vs/base/common/winjs.base';
1817
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
1918
import { OS } from 'vs/base/common/platform';
2019
import { IKeyboardEvent } from 'vs/platform/keybinding/common/keybinding';
@@ -116,12 +115,12 @@ suite('AbstractKeybindingService', () => {
116115
let commandService: ICommandService = {
117116
_serviceBrand: undefined,
118117
onWillExecuteCommand: () => ({ dispose: () => { } }),
119-
executeCommand: (commandId: string, ...args: any[]): TPromise<any> => {
118+
executeCommand: (commandId: string, ...args: any[]): Promise<any> => {
120119
executeCommandCalls.push({
121120
commandId: commandId,
122121
args: args
123122
});
124-
return TPromise.as(void 0);
123+
return Promise.resolve(void 0);
125124
}
126125
};
127126

src/vs/workbench/parts/extensions/electron-browser/extensionsActions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,7 +1924,7 @@ export class ConfigureWorkspaceFolderRecommendedExtensionsAction extends Abstrac
19241924
public run(): TPromise<any> {
19251925
const folderCount = this.contextService.getWorkspace().folders.length;
19261926
const pickFolderPromise = folderCount === 1 ? TPromise.as(this.contextService.getWorkspace().folders[0]) : this.commandService.executeCommand<IWorkspaceFolder>(PICK_WORKSPACE_FOLDER_COMMAND_ID);
1927-
return pickFolderPromise
1927+
return TPromise.wrap(pickFolderPromise)
19281928
.then(workspaceFolder => {
19291929
if (workspaceFolder) {
19301930
return this.openExtensionsFile(workspaceFolder.toResource(paths.join('.vscode', 'extensions.json')));
@@ -1975,7 +1975,7 @@ export class AddToWorkspaceFolderRecommendationsAction extends AbstractConfigure
19751975
const pickFolderPromise = folders.length === 1
19761976
? TPromise.as(folders[0])
19771977
: this.commandService.executeCommand<IWorkspaceFolder>(PICK_WORKSPACE_FOLDER_COMMAND_ID);
1978-
return pickFolderPromise
1978+
return TPromise.wrap(pickFolderPromise)
19791979
.then(workspaceFolder => {
19801980
if (!workspaceFolder) {
19811981
return TPromise.as(null);

src/vs/workbench/services/commands/common/commandService.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*--------------------------------------------------------------------------------------------*/
55
'use strict';
66

7-
import { TPromise } from 'vs/base/common/winjs.base';
87
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
98
import { ICommandService, ICommandEvent, CommandsRegistry } from 'vs/platform/commands/common/commands';
109
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
@@ -30,38 +29,38 @@ export class CommandService extends Disposable implements ICommandService {
3029
this._extensionService.whenInstalledExtensionsRegistered().then(value => this._extensionHostIsReady = value);
3130
}
3231

33-
executeCommand<T>(id: string, ...args: any[]): TPromise<T> {
32+
executeCommand<T>(id: string, ...args: any[]): Promise<T> {
3433
this._logService.trace('CommandService#executeCommand', id);
3534

3635
// we always send an activation event, but
3736
// we don't wait for it when the extension
3837
// host didn't yet start and the command is already registered
3938

40-
const activation = this._extensionService.activateByEvent(`onCommand:${id}`);
39+
const activation = Promise.resolve(this._extensionService.activateByEvent(`onCommand:${id}`));
4140
const commandIsRegistered = !!CommandsRegistry.getCommand(id);
4241

4342
if (!this._extensionHostIsReady && commandIsRegistered) {
4443
return this._tryExecuteCommand(id, args);
4544
} else {
46-
let waitFor: TPromise<any> = activation;
45+
let waitFor: Promise<any> = activation;
4746
if (!commandIsRegistered) {
48-
waitFor = TPromise.join([activation, this._extensionService.activateByEvent(`*`)]);
47+
waitFor = Promise.all([activation, this._extensionService.activateByEvent(`*`)]);
4948
}
5049
return waitFor.then(_ => this._tryExecuteCommand(id, args));
5150
}
5251
}
5352

54-
private _tryExecuteCommand(id: string, args: any[]): TPromise<any> {
53+
private _tryExecuteCommand(id: string, args: any[]): Promise<any> {
5554
const command = CommandsRegistry.getCommand(id);
5655
if (!command) {
57-
return TPromise.wrapError(new Error(`command '${id}' not found`));
56+
return Promise.reject(new Error(`command '${id}' not found`));
5857
}
5958
try {
6059
this._onWillExecuteCommand.fire({ commandId: id });
6160
const result = this._instantiationService.invokeFunction.apply(this._instantiationService, [command.handler].concat(args));
62-
return TPromise.as(result);
61+
return Promise.resolve(result);
6362
} catch (err) {
64-
return TPromise.wrapError(err);
63+
return Promise.reject(err);
6564
}
6665
}
6766
}

src/vs/workbench/services/configurationResolver/test/electron-browser/configurationResolverService.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ class MockCommandService implements ICommandService {
393393
public callCount = 0;
394394

395395
onWillExecuteCommand = () => Disposable.None;
396-
public executeCommand(commandId: string, ...args: any[]): TPromise<any> {
396+
public executeCommand(commandId: string, ...args: any[]): Promise<any> {
397397
this.callCount++;
398398

399399
let result = `${commandId}-result`;
@@ -403,6 +403,6 @@ class MockCommandService implements ICommandService {
403403
}
404404
}
405405

406-
return TPromise.as(result);
406+
return Promise.resolve(result);
407407
}
408408
}

src/vs/workbench/test/electron-browser/api/extHostMessagerService.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import * as assert from 'assert';
99
import { MainThreadMessageService } from 'vs/workbench/api/electron-browser/mainThreadMessageService';
10-
import { TPromise as Promise, TPromise } from 'vs/base/common/winjs.base';
10+
import { TPromise } from 'vs/base/common/winjs.base';
1111
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
1212
import { INotificationService, INotification, NoOpNotification, INotificationHandle, Severity, IPromptChoice } from 'vs/platform/notification/common/notification';
1313
import { ICommandService } from 'vs/platform/commands/common/commands';
@@ -26,8 +26,8 @@ const emptyDialogService = new class implements IDialogService {
2626
const emptyCommandService: ICommandService = {
2727
_serviceBrand: undefined,
2828
onWillExecuteCommand: () => ({ dispose: () => { } }),
29-
executeCommand: (commandId: string, ...args: any[]): TPromise<any> => {
30-
return TPromise.as(void 0);
29+
executeCommand: (commandId: string, ...args: any[]): Promise<any> => {
30+
return Promise.resolve(void 0);
3131
}
3232
};
3333

@@ -98,7 +98,7 @@ suite('ExtHostMessageService', function () {
9898
assert.equal(message, 'h');
9999
assert.equal(buttons.length, 2);
100100
assert.equal(buttons[1], 'Cancel');
101-
return Promise.as(0);
101+
return TPromise.as(0);
102102
}
103103
} as IDialogService);
104104

@@ -110,7 +110,7 @@ suite('ExtHostMessageService', function () {
110110
test('returns undefined when cancelled', () => {
111111
const service = new MainThreadMessageService(null, emptyNotificationService, emptyCommandService, {
112112
show(severity, message, buttons) {
113-
return Promise.as(1);
113+
return TPromise.as(1);
114114
}
115115
} as IDialogService);
116116

@@ -123,7 +123,7 @@ suite('ExtHostMessageService', function () {
123123
const service = new MainThreadMessageService(null, emptyNotificationService, emptyCommandService, {
124124
show(severity, message, buttons) {
125125
assert.equal(buttons.length, 1);
126-
return Promise.as(0);
126+
return TPromise.as(0);
127127
}
128128
} as IDialogService);
129129

0 commit comments

Comments
 (0)