Replacing null with undefined around ContextKeyExpr

This commit is contained in:
Matt Bierner
2019-03-21 10:56:00 -07:00
parent 91570a012a
commit d58dcf2e40
19 changed files with 34 additions and 35 deletions

View File

@@ -8,7 +8,6 @@ import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { IMenu, IMenuActionOptions, IMenuItem, IMenuService, isIMenuItem, ISubmenuItem, MenuId, MenuItemAction, MenuRegistry, SubmenuItemAction } from 'vs/platform/actions/common/actions';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { withUndefinedAsNull } from 'vs/base/common/types';
export class MenuService implements IMenuService {
@@ -111,7 +110,7 @@ class Menu implements IMenu {
const [id, items] = group;
const activeActions: Array<MenuItemAction | SubmenuItemAction> = [];
for (const item of items) {
if (this._contextKeyService.contextMatchesRules(withUndefinedAsNull(item.when))) {
if (this._contextKeyService.contextMatchesRules(item.when)) {
const action = isIMenuItem(item) ? new MenuItemAction(item.command, item.alt, options, this._contextKeyService, this._commandService) : new SubmenuItemAction(item);
activeActions.push(action);
}

View File

@@ -252,7 +252,7 @@ export abstract class AbstractContextKeyService implements IContextKeyService {
return new ScopedContextKeyService(this, this._onDidChangeContextKey, domNode);
}
public contextMatchesRules(rules: ContextKeyExpr | null): boolean {
public contextMatchesRules(rules: ContextKeyExpr | undefined): boolean {
if (this._isDisposed) {
throw new Error(`AbstractContextKeyService has been disposed`);
}

View File

@@ -50,9 +50,9 @@ export abstract class ContextKeyExpr {
return new ContextKeyAndExpr(expr);
}
public static deserialize(serialized: string | null | undefined, strict: boolean = false): ContextKeyExpr | null {
public static deserialize(serialized: string | null | undefined, strict: boolean = false): ContextKeyExpr | undefined {
if (!serialized) {
return null;
return undefined;
}
let pieces = serialized.split('&&');
@@ -143,7 +143,7 @@ export abstract class ContextKeyExpr {
public abstract getType(): ContextKeyExprType;
public abstract equals(other: ContextKeyExpr): boolean;
public abstract evaluate(context: IContext): boolean;
public abstract normalize(): ContextKeyExpr | null;
public abstract normalize(): ContextKeyExpr | undefined;
public abstract serialize(): string;
public abstract keys(): string[];
public abstract map(mapFnc: IContextKeyExprMapper): ContextKeyExpr;
@@ -519,9 +519,9 @@ export class ContextKeyAndExpr implements ContextKeyExpr {
return expr;
}
public normalize(): ContextKeyExpr | null {
public normalize(): ContextKeyExpr | undefined {
if (this.expr.length === 0) {
return null;
return undefined;
}
if (this.expr.length === 1) {
@@ -622,7 +622,7 @@ export interface IContextKeyService {
onDidChangeContext: Event<IContextKeyChangeEvent>;
createKey<T>(key: string, defaultValue: T | undefined): IContextKey<T>;
contextMatchesRules(rules: ContextKeyExpr | null): boolean;
contextMatchesRules(rules: ContextKeyExpr | undefined): boolean;
getContextKeyValue<T>(key: string): T | undefined;
createScoped(target?: IContextKeyServiceTarget): IContextKeyService;

View File

@@ -50,7 +50,7 @@ export class KeybindingResolver {
}
}
private static _isTargetedForRemoval(defaultKb: ResolvedKeybindingItem, keypressFirstPart: string | null, keypressChordPart: string | null, command: string, when: ContextKeyExpr | null): boolean {
private static _isTargetedForRemoval(defaultKb: ResolvedKeybindingItem, keypressFirstPart: string | null, keypressChordPart: string | null, command: string, when: ContextKeyExpr | undefined): boolean {
if (defaultKb.command !== command) {
return false;
}
@@ -172,7 +172,7 @@ export class KeybindingResolver {
* Returns true if it is provable `a` implies `b`.
* **Precondition**: Assumes `a` and `b` are normalized!
*/
public static whenIsEntirelyIncluded(a: ContextKeyExpr | null, b: ContextKeyExpr | null): boolean {
public static whenIsEntirelyIncluded(a: ContextKeyExpr | null | undefined, b: ContextKeyExpr | null | undefined): boolean {
if (!b) {
return true;
}
@@ -304,7 +304,7 @@ export class KeybindingResolver {
return null;
}
public static contextMatchesRules(context: IContext, rules: ContextKeyExpr | null): boolean {
public static contextMatchesRules(context: IContext, rules: ContextKeyExpr | null | undefined): boolean {
if (!rules) {
return true;
}

View File

@@ -49,7 +49,7 @@ export interface IKeybindingRule2 {
id: string;
args?: any;
weight: number;
when: ContextKeyExpr | null;
when: ContextKeyExpr | undefined;
}
export const enum KeybindingWeight {

View File

@@ -15,10 +15,10 @@ export class ResolvedKeybindingItem {
public readonly bubble: boolean;
public readonly command: string | null;
public readonly commandArgs: any;
public readonly when: ContextKeyExpr | null;
public readonly when: ContextKeyExpr | undefined;
public readonly isDefault: boolean;
constructor(resolvedKeybinding: ResolvedKeybinding | null, command: string | null, commandArgs: any, when: ContextKeyExpr | null, isDefault: boolean) {
constructor(resolvedKeybinding: ResolvedKeybinding | null, command: string | null, commandArgs: any, when: ContextKeyExpr | undefined, isDefault: boolean) {
this.resolvedKeybinding = resolvedKeybinding;
this.keypressParts = resolvedKeybinding ? removeElementsAfterNulls(resolvedKeybinding.getDispatchParts()) : [];
this.bubble = (command ? command.charCodeAt(0) === CharCode.Caret : false);

View File

@@ -178,7 +178,7 @@ suite('AbstractKeybindingService', () => {
statusMessageCallsDisposed = null;
});
function kbItem(keybinding: number, command: string, when: ContextKeyExpr | null = null): ResolvedKeybindingItem {
function kbItem(keybinding: number, command: string, when?: ContextKeyExpr): ResolvedKeybindingItem {
const resolvedKeybinding = (keybinding !== 0 ? new USLayoutResolvedKeybinding(createKeybinding(keybinding, OS)!, OS) : null);
return new ResolvedKeybindingItem(
resolvedKeybinding,

View File

@@ -26,7 +26,7 @@ suite('KeybindingResolver', () => {
resolvedKeybinding,
command,
commandArgs,
when ? when.normalize() : null,
when ? when.normalize() : undefined,
isDefault
);
}