Skip to content

Commit e333352

Browse files
committed
adopt executeCommand returning a promise
1 parent bedec88 commit e333352

4 files changed

Lines changed: 21 additions & 11 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/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

0 commit comments

Comments
 (0)