Skip to content

Commit 5f033c8

Browse files
committed
Merge pull request microsoft#739 from Microsoft/joh/executeCommand
Joh/execute command
2 parents 8f0ec19 + e333352 commit 5f033c8

8 files changed

Lines changed: 31 additions & 21 deletions

File tree

src/vs/editor/contrib/codelens/browser/codelens.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import nls = require('vs/nls');
1111
import {format} from 'vs/base/common/strings';
1212
import lifecycle = require('vs/base/common/lifecycle');
1313
import schedulers = require('vs/base/common/async');
14+
import Severity from 'vs/base/common/severity';
1415
import dom = require('vs/base/browser/dom');
1516
import errors = require('vs/base/common/errors');
1617
import EditorBrowser = require('vs/editor/browser/editorBrowser');
@@ -21,6 +22,7 @@ import referenceSearch = require('vs/editor/contrib/referenceSearch/browser/refe
2122
import {IModelService} from 'vs/editor/common/services/modelService';
2223
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
2324
import {IKeybindingService} from 'vs/platform/keybinding/common/keybindingService';
25+
import {IMessageService} from 'vs/platform/message/common/message';
2426
import {Range} from 'vs/editor/common/core/range';
2527
import {CodeLensRegistry, ICodeLensData, getCodeLensData} from '../common/codelens';
2628

@@ -61,7 +63,7 @@ class CodeLensContentWidget implements EditorBrowser.IContentWidget {
6163
private _commands: { [id: string]: Modes.ICommand } = Object.create(null);
6264

6365
public constructor(editor: EditorBrowser.ICodeEditor, symbolRange: EditorCommon.IEditorRange,
64-
keybindingService: IKeybindingService) {
66+
keybindingService: IKeybindingService, messageService: IMessageService) {
6567

6668
this._id = 'codeLensWidget' + (++CodeLensContentWidget.ID);
6769
this._editor = editor;
@@ -79,7 +81,9 @@ class CodeLensContentWidget implements EditorBrowser.IContentWidget {
7981
let command = this._commands[element.id];
8082
if (command) {
8183
editor.focus();
82-
keybindingService.executeCommand(command.id, command.arguments);
84+
keybindingService.executeCommand(command.id, command.arguments).done(undefined, err => {
85+
messageService.show(Severity.Error, err);
86+
});
8387
}
8488
}
8589
});
@@ -226,7 +230,7 @@ class CodeLens {
226230
public constructor(data: ICodeLensData[], editor: EditorBrowser.ICodeEditor,
227231
helper: CodeLensHelper,
228232
viewZoneChangeAccessor: EditorBrowser.IViewZoneChangeAccessor,
229-
keybindingService: IKeybindingService) {
233+
keybindingService: IKeybindingService, messageService: IMessageService) {
230234

231235
this._editor = editor;
232236
this._data = data;
@@ -251,7 +255,7 @@ class CodeLens {
251255
});
252256

253257
this._viewZone = new CodeLensViewZone(range.startLineNumber - 1);
254-
this._contentWidget = new CodeLensContentWidget(editor, Range.lift(range), keybindingService);
258+
this._contentWidget = new CodeLensContentWidget(editor, Range.lift(range), keybindingService, messageService);
255259

256260
this._viewZoneId = viewZoneChangeAccessor.addZone(this._viewZone);
257261
this._editor.addContentWidget(this._contentWidget);
@@ -343,19 +347,22 @@ export class CodeLensContribution implements EditorCommon.IEditorContribution {
343347
private _modelChangeCounter: number;
344348
private _configurationService: IConfigurationService;
345349
private _keybindingService: IKeybindingService;
350+
private _messageService: IMessageService;
346351
private _codeLenseDisabledByMode: boolean;
347352

348353
private _currentFindOccPromise:TPromise<any>;
349354

350355
constructor(editor: EditorBrowser.ICodeEditor, @IModelService modelService: IModelService,
351356
@IConfigurationService configurationService: IConfigurationService,
352-
@IKeybindingService keybindingService: IKeybindingService) {
357+
@IKeybindingService keybindingService: IKeybindingService,
358+
@IMessageService messageService: IMessageService) {
353359

354360
this._instanceCount = (++CodeLensContribution.INSTANCE_COUNT);
355361
this._editor = editor;
356362
this._modelService = modelService;
357363
this._configurationService = configurationService;
358364
this._keybindingService = keybindingService;
365+
this._messageService = messageService;
359366

360367
this._globalToDispose = [];
361368
this._localToDispose = [];
@@ -553,7 +560,7 @@ export class CodeLensContribution implements EditorCommon.IEditorContribution {
553560
groupsIndex++;
554561
codeLensIndex++;
555562
} else {
556-
this._lenses.splice(codeLensIndex, 0, new CodeLens(groups[groupsIndex], this._editor, helper, accessor, this._keybindingService));
563+
this._lenses.splice(codeLensIndex, 0, new CodeLens(groups[groupsIndex], this._editor, helper, accessor, this._keybindingService, this._messageService));
557564
codeLensIndex++;
558565
groupsIndex++;
559566
}
@@ -567,7 +574,7 @@ export class CodeLensContribution implements EditorCommon.IEditorContribution {
567574

568575
// Create extra symbols
569576
while (groupsIndex < groups.length) {
570-
this._lenses.push(new CodeLens(groups[groupsIndex], this._editor, helper, accessor, this._keybindingService));
577+
this._lenses.push(new CodeLens(groups[groupsIndex], this._editor, helper, accessor, this._keybindingService, this._messageService));
571578
groupsIndex++;
572579
}
573580

src/vs/platform/actions/common/actionsService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export default class ActionsService implements IActionsService {
116116
let label = command.category ? localize('category.label', "{0}: {1}", command.category, command.title) : command.title;
117117
let action = new Action(command.command, label, undefined, true, () => {
118118
return this._pluginService.activateByEvent(activationEvent).then(() => {
119-
this._keybindingsService.executeCommand(command.command);
119+
return this._keybindingsService.executeCommand(command.command);
120120
});
121121
});
122122
this._extensionsActions.push(action);

src/vs/platform/keybinding/browser/keybindingServiceImpl.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export class AbstractKeybindingService {
142142
throw new Error('Not implemented');
143143
}
144144

145-
public executeCommand(commandId: string, args:any): void {
145+
public executeCommand(commandId: string, args:any): TPromise<any> {
146146
throw new Error('Not implemented');
147147
}
148148
}
@@ -300,7 +300,7 @@ export class KeybindingService extends AbstractKeybindingService implements IKey
300300
delete this._contexts[String(contextId)];
301301
}
302302

303-
public executeCommand(commandId: string, args:any = {}): any {
303+
public executeCommand(commandId: string, args:any = {}): TPromise<any> {
304304
if (!args.context) {
305305
var contextId = this._findContextAttr(<HTMLElement>document.activeElement);
306306
var context = this.getContext(contextId);
@@ -309,9 +309,7 @@ export class KeybindingService extends AbstractKeybindingService implements IKey
309309
args.context = contextValue;
310310
}
311311

312-
return this._invokeHandler(commandId, args).done(undefined, err => {
313-
this._messageService.show(Severity.Warning, err);
314-
});
312+
return this._invokeHandler(commandId, args);
315313
}
316314
}
317315

@@ -356,8 +354,8 @@ class ScopedKeybindingService extends AbstractKeybindingService {
356354
this._parent.disposeContext(contextId);
357355
}
358356

359-
public executeCommand(commandId: string, args:any): void {
360-
this._parent.executeCommand(commandId, args);
357+
public executeCommand(commandId: string, args:any): TPromise<any> {
358+
return this._parent.executeCommand(commandId, args);
361359
}
362360
}
363361

src/vs/platform/keybinding/common/keybindingService.ts

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

7+
import {TPromise} from 'vs/base/common/winjs.base';
78
import {createDecorator, IInstantiationService, ServiceIdentifier, ServicesAccessor} from 'vs/platform/instantiation/common/instantiation';
89
import {Keybinding} from 'vs/base/common/keyCodes';
910

@@ -82,5 +83,6 @@ export interface IKeybindingService {
8283
lookupKeybindings(commandId: string): Keybinding[];
8384
customKeybindingsCount(): number;
8485

85-
executeCommand(commandId: string, args?: any): any;
86+
executeCommand<T>(commandId: string, args?: any): TPromise<T>;
87+
executeCommand(commandId: string, args?: any): TPromise<any>;
8688
}

src/vs/workbench/api/common/pluginHostCommands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export class MainThreadCommands {
148148
}
149149

150150
_executeCommand<T>(id: string, args: any[]): Thenable<T> {
151-
return TPromise.as(this._keybindingService.executeCommand(id, args));
151+
return this._keybindingService.executeCommand(id, args);
152152
}
153153

154154
_getCommands(): Thenable<string[]> {

src/vs/workbench/browser/parts/statusbar/statusbarPart.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ class StatusBarEntryItem implements IStatusbarItem {
285285

286286
// Fallback to the keybinding service for any other case
287287
else {
288-
this.keybindingService.executeCommand(id);
288+
this.keybindingService.executeCommand(id).done(undefined, err => this.messageService.show(Severity.Error, toErrorMessage(err)));
289289
}
290290
}
291291
}

src/vs/workbench/electron-browser/integration.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
import {TPromise} from 'vs/base/common/winjs.base';
99
import errors = require('vs/base/common/errors');
1010
import arrays = require('vs/base/common/arrays');
11+
import Severity from 'vs/base/common/severity';
1112
import {IPartService} from 'vs/workbench/services/part/common/partService';
1213
import {IStorageService, StorageScope} from 'vs/platform/storage/common/storage';
14+
import {IMessageService} from 'vs/platform/message/common/message';
1315
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
1416
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
1517
import {IKeybindingService} from 'vs/platform/keybinding/common/keybindingService';
@@ -30,7 +32,8 @@ export class ElectronIntegration {
3032
@IWorkspaceContextService private contextService: IWorkspaceContextService,
3133
@ITelemetryService private telemetryService: ITelemetryService,
3234
@IKeybindingService private keybindingService: IKeybindingService,
33-
@IStorageService private storageService: IStorageService
35+
@IStorageService private storageService: IStorageService,
36+
@IMessageService private messageService: IMessageService
3437
) {
3538
}
3639

@@ -42,7 +45,7 @@ export class ElectronIntegration {
4245

4346
// Support runAction event
4447
ipc.on('vscode:runAction', (actionId: string) => {
45-
this.keybindingService.executeCommand(actionId, { from: 'menu' });
48+
this.keybindingService.executeCommand(actionId, { from: 'menu' }).done(undefined, err => this.messageService.show(Severity.Error, err));
4649
});
4750

4851
// Support options change

src/vs/workbench/test/browser/servicesTestUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export class TestKeybindingService implements IKeybindingService {
153153
public setInstantiationService(instantiationService: IInstantiationService): void { }
154154
public setContext(key: string, value: any): void { }
155155
public removeContext(key: string): void { }
156-
public executeCommand(commandId: string, args: any): void { }
156+
public executeCommand(commandId: string, args: any): TPromise<any> { return; }
157157

158158
public createKey<T>(key: string, defaultValue: T): IKeybindingContextKey<T> {
159159
return null;

0 commit comments

Comments
 (0)