Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joh/execute command #739

Merged
merged 2 commits into from
Nov 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/vs/editor/contrib/codelens/browser/codelens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import nls = require('vs/nls');
import {format} from 'vs/base/common/strings';
import lifecycle = require('vs/base/common/lifecycle');
import schedulers = require('vs/base/common/async');
import Severity from 'vs/base/common/severity';
import dom = require('vs/base/browser/dom');
import errors = require('vs/base/common/errors');
import EditorBrowser = require('vs/editor/browser/editorBrowser');
Expand All @@ -21,6 +22,7 @@ import referenceSearch = require('vs/editor/contrib/referenceSearch/browser/refe
import {IModelService} from 'vs/editor/common/services/modelService';
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybindingService';
import {IMessageService} from 'vs/platform/message/common/message';
import {Range} from 'vs/editor/common/core/range';
import {CodeLensRegistry, ICodeLensData, getCodeLensData} from '../common/codelens';

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

public constructor(editor: EditorBrowser.ICodeEditor, symbolRange: EditorCommon.IEditorRange,
keybindingService: IKeybindingService) {
keybindingService: IKeybindingService, messageService: IMessageService) {

this._id = 'codeLensWidget' + (++CodeLensContentWidget.ID);
this._editor = editor;
Expand All @@ -79,7 +81,9 @@ class CodeLensContentWidget implements EditorBrowser.IContentWidget {
let command = this._commands[element.id];
if (command) {
editor.focus();
keybindingService.executeCommand(command.id, command.arguments);
keybindingService.executeCommand(command.id, command.arguments).done(undefined, err => {
messageService.show(Severity.Error, err);
});
}
}
});
Expand Down Expand Up @@ -226,7 +230,7 @@ class CodeLens {
public constructor(data: ICodeLensData[], editor: EditorBrowser.ICodeEditor,
helper: CodeLensHelper,
viewZoneChangeAccessor: EditorBrowser.IViewZoneChangeAccessor,
keybindingService: IKeybindingService) {
keybindingService: IKeybindingService, messageService: IMessageService) {

this._editor = editor;
this._data = data;
Expand All @@ -251,7 +255,7 @@ class CodeLens {
});

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

this._viewZoneId = viewZoneChangeAccessor.addZone(this._viewZone);
this._editor.addContentWidget(this._contentWidget);
Expand Down Expand Up @@ -343,19 +347,22 @@ export class CodeLensContribution implements EditorCommon.IEditorContribution {
private _modelChangeCounter: number;
private _configurationService: IConfigurationService;
private _keybindingService: IKeybindingService;
private _messageService: IMessageService;
private _codeLenseDisabledByMode: boolean;

private _currentFindOccPromise:TPromise<any>;

constructor(editor: EditorBrowser.ICodeEditor, @IModelService modelService: IModelService,
@IConfigurationService configurationService: IConfigurationService,
@IKeybindingService keybindingService: IKeybindingService) {
@IKeybindingService keybindingService: IKeybindingService,
@IMessageService messageService: IMessageService) {

this._instanceCount = (++CodeLensContribution.INSTANCE_COUNT);
this._editor = editor;
this._modelService = modelService;
this._configurationService = configurationService;
this._keybindingService = keybindingService;
this._messageService = messageService;

this._globalToDispose = [];
this._localToDispose = [];
Expand Down Expand Up @@ -553,7 +560,7 @@ export class CodeLensContribution implements EditorCommon.IEditorContribution {
groupsIndex++;
codeLensIndex++;
} else {
this._lenses.splice(codeLensIndex, 0, new CodeLens(groups[groupsIndex], this._editor, helper, accessor, this._keybindingService));
this._lenses.splice(codeLensIndex, 0, new CodeLens(groups[groupsIndex], this._editor, helper, accessor, this._keybindingService, this._messageService));
codeLensIndex++;
groupsIndex++;
}
Expand All @@ -567,7 +574,7 @@ export class CodeLensContribution implements EditorCommon.IEditorContribution {

// Create extra symbols
while (groupsIndex < groups.length) {
this._lenses.push(new CodeLens(groups[groupsIndex], this._editor, helper, accessor, this._keybindingService));
this._lenses.push(new CodeLens(groups[groupsIndex], this._editor, helper, accessor, this._keybindingService, this._messageService));
groupsIndex++;
}

Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/actions/common/actionsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default class ActionsService implements IActionsService {
let label = command.category ? localize('category.label', "{0}: {1}", command.category, command.title) : command.title;
let action = new Action(command.command, label, undefined, true, () => {
return this._pluginService.activateByEvent(activationEvent).then(() => {
this._keybindingsService.executeCommand(command.command);
return this._keybindingsService.executeCommand(command.command);
});
});
this._extensionsActions.push(action);
Expand Down
12 changes: 5 additions & 7 deletions src/vs/platform/keybinding/browser/keybindingServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class AbstractKeybindingService {
throw new Error('Not implemented');
}

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

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

return this._invokeHandler(commandId, args).done(undefined, err => {
this._messageService.show(Severity.Warning, err);
});
return this._invokeHandler(commandId, args);
}
}

Expand Down Expand Up @@ -356,8 +354,8 @@ class ScopedKeybindingService extends AbstractKeybindingService {
this._parent.disposeContext(contextId);
}

public executeCommand(commandId: string, args:any): void {
this._parent.executeCommand(commandId, args);
public executeCommand(commandId: string, args:any): TPromise<any> {
return this._parent.executeCommand(commandId, args);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/vs/platform/keybinding/common/keybindingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';

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

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

executeCommand(commandId: string, args?: any): any;
executeCommand<T>(commandId: string, args?: any): TPromise<T>;
executeCommand(commandId: string, args?: any): TPromise<any>;
}
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/pluginHostCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class MainThreadCommands {
}

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

_getCommands(): Thenable<string[]> {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/browser/parts/statusbar/statusbarPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class StatusBarEntryItem implements IStatusbarItem {

// Fallback to the keybinding service for any other case
else {
this.keybindingService.executeCommand(id);
this.keybindingService.executeCommand(id).done(undefined, err => this.messageService.show(Severity.Error, toErrorMessage(err)));
}
}
}
7 changes: 5 additions & 2 deletions src/vs/workbench/electron-browser/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import {TPromise} from 'vs/base/common/winjs.base';
import errors = require('vs/base/common/errors');
import arrays = require('vs/base/common/arrays');
import Severity from 'vs/base/common/severity';
import {IPartService} from 'vs/workbench/services/part/common/partService';
import {IStorageService, StorageScope} from 'vs/platform/storage/common/storage';
import {IMessageService} from 'vs/platform/message/common/message';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybindingService';
Expand All @@ -30,7 +32,8 @@ export class ElectronIntegration {
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@ITelemetryService private telemetryService: ITelemetryService,
@IKeybindingService private keybindingService: IKeybindingService,
@IStorageService private storageService: IStorageService
@IStorageService private storageService: IStorageService,
@IMessageService private messageService: IMessageService
) {
}

Expand All @@ -42,7 +45,7 @@ export class ElectronIntegration {

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

// Support options change
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/test/browser/servicesTestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class TestKeybindingService implements IKeybindingService {
public setInstantiationService(instantiationService: IInstantiationService): void { }
public setContext(key: string, value: any): void { }
public removeContext(key: string): void { }
public executeCommand(commandId: string, args: any): void { }
public executeCommand(commandId: string, args: any): TPromise<any> { return; }

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