Skip to content

Commit 3698d32

Browse files
committed
remove ICommand#precondition, microsoft#41103
1 parent a17bdc1 commit 3698d32

4 files changed

Lines changed: 4 additions & 63 deletions

File tree

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { ICommandService, ICommandEvent, CommandsRegistry } from 'vs/platform/co
1010
import { IExtensionService } from 'vs/platform/extensions/common/extensions';
1111
import Event, { Emitter } from 'vs/base/common/event';
1212
import { Disposable } from 'vs/base/common/lifecycle';
13-
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
1413
import { ILogService } from 'vs/platform/log/common/log';
1514

1615
export class CommandService extends Disposable implements ICommandService {
@@ -25,7 +24,6 @@ export class CommandService extends Disposable implements ICommandService {
2524
constructor(
2625
@IInstantiationService private _instantiationService: IInstantiationService,
2726
@IExtensionService private _extensionService: IExtensionService,
28-
@IContextKeyService private _contextKeyService: IContextKeyService,
2927
@ILogService private _logService: ILogService
3028
) {
3129
super();
@@ -53,12 +51,6 @@ export class CommandService extends Disposable implements ICommandService {
5351
if (!command) {
5452
return TPromise.wrapError(new Error(`command '${id}' not found`));
5553
}
56-
57-
if (command.precondition && !this._contextKeyService.contextMatchesRules(command.precondition)) {
58-
// not enabled
59-
return TPromise.wrapError(new Error('NOT_ENABLED'));
60-
}
61-
6254
try {
6355
this._onWillExecuteCommand.fire({ commandId: id });
6456
const result = this._instantiationService.invokeFunction.apply(this._instantiationService, [command.handler].concat(args));

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { IDisposable } from 'vs/base/common/lifecycle';
99
import { TypeConstraint, validateConstraints } from 'vs/base/common/types';
1010
import { ServicesAccessor, createDecorator } from 'vs/platform/instantiation/common/instantiation';
1111
import Event from 'vs/base/common/event';
12-
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
1312
import { LinkedList } from 'vs/base/common/linkedList';
1413

1514
export const ICommandService = createDecorator<ICommandService>('commandService');
@@ -35,7 +34,6 @@ export interface ICommandHandler {
3534
export interface ICommand {
3635
id: string;
3736
handler: ICommandHandler;
38-
precondition?: ContextKeyExpr;
3937
description?: ICommandHandlerDescription;
4038
}
4139

src/vs/platform/commands/test/commandService.test.ts

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ import { CommandService } from 'vs/platform/commands/common/commandService';
1212
import { IExtensionService, ExtensionPointContribution, IExtensionDescription, IExtensionHostInformation, ProfileSession } from 'vs/platform/extensions/common/extensions';
1313
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
1414
import { IExtensionPoint } from 'vs/platform/extensions/common/extensionsRegistry';
15-
import { ContextKeyService } from 'vs/platform/contextkey/browser/contextKeyService';
16-
import { SimpleConfigurationService } from 'vs/editor/standalone/browser/simpleServices';
17-
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
1815
import Event, { Emitter } from 'vs/base/common/event';
1916
import { NullLogService } from 'vs/platform/log/common/log';
2017

@@ -75,7 +72,7 @@ suite('CommandService', function () {
7572
lastEvent = activationEvent;
7673
return super.activateByEvent(activationEvent);
7774
}
78-
}, new ContextKeyService(new SimpleConfigurationService()), new NullLogService());
75+
}, new NullLogService());
7976

8077
return service.executeCommand('foo').then(() => {
8178
assert.ok(lastEvent, 'onCommand:foo');
@@ -93,7 +90,7 @@ suite('CommandService', function () {
9390
activateByEvent(activationEvent: string): TPromise<void> {
9491
return TPromise.wrapError<void>(new Error('bad_activate'));
9592
}
96-
}, new ContextKeyService(new SimpleConfigurationService()), new NullLogService());
93+
}, new NullLogService());
9794

9895
return service.executeCommand('foo').then(() => assert.ok(false), err => {
9996
assert.equal(err.message, 'bad_activate');
@@ -109,7 +106,7 @@ suite('CommandService', function () {
109106
whenInstalledExtensionsRegistered() {
110107
return new TPromise<boolean>(_resolve => { /*ignore*/ });
111108
}
112-
}, new ContextKeyService(new SimpleConfigurationService()), new NullLogService());
109+
}, new NullLogService());
113110

114111
service.executeCommand('bar');
115112
assert.equal(callCounter, 1);
@@ -126,7 +123,7 @@ suite('CommandService', function () {
126123
whenInstalledExtensionsRegistered() {
127124
return new TPromise<boolean>(_resolve => { resolveFunc = _resolve; });
128125
}
129-
}, new ContextKeyService(new SimpleConfigurationService()), new NullLogService());
126+
}, new NullLogService());
130127

131128
let r = service.executeCommand('bar');
132129
assert.equal(callCounter, 0);
@@ -139,32 +136,4 @@ suite('CommandService', function () {
139136
assert.equal(callCounter, 1);
140137
});
141138
});
142-
143-
test('honor command-precondition', function () {
144-
let contextKeyService = new ContextKeyService(new SimpleConfigurationService());
145-
let commandService = new CommandService(
146-
new InstantiationService(),
147-
new SimpleExtensionService(),
148-
contextKeyService,
149-
new NullLogService()
150-
);
151-
152-
let counter = 0;
153-
let reg = CommandsRegistry.registerCommand({
154-
id: 'bar',
155-
handler: () => { counter += 1; },
156-
precondition: ContextKeyExpr.has('foocontext')
157-
});
158-
159-
return commandService.executeCommand('bar').then(() => {
160-
assert.throws(() => { });
161-
}, () => {
162-
contextKeyService.setContext('foocontext', true);
163-
return commandService.executeCommand('bar');
164-
}).then(() => {
165-
assert.equal(counter, 1);
166-
reg.dispose();
167-
});
168-
169-
});
170139
});

src/vs/platform/commands/test/commands.test.ts

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

77
import * as assert from 'assert';
88
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
9-
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
109

1110
suite('Command Tests', function () {
1211

@@ -77,21 +76,4 @@ suite('Command Tests', function () {
7776
assert.equal(CommandsRegistry.getCommands()['test3'].handler.apply(undefined, [undefined, 1]), true);
7877

7978
});
80-
81-
test('CommandsRegistry with precondition', function () {
82-
let r1 = CommandsRegistry.registerCommand('foo', () => { });
83-
84-
const precondition = new RawContextKey<boolean>('ddd', false);
85-
let r2 = CommandsRegistry.registerCommand({
86-
id: 'bar',
87-
handler: () => { },
88-
precondition
89-
});
90-
91-
assert.ok(CommandsRegistry.getCommand('bar').precondition === precondition);
92-
assert.equal(CommandsRegistry.getCommand('foo').precondition, undefined);
93-
94-
r1.dispose();
95-
r2.dispose();
96-
});
9779
});

0 commit comments

Comments
 (0)