Skip to content

Commit ef33a6a

Browse files
committed
Ability to edit when expression
1 parent 08a4504 commit ef33a6a

7 files changed

Lines changed: 304 additions & 103 deletions

File tree

src/vs/platform/contextkey/common/contextkey.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,32 @@ export abstract class ContextKeyExpr {
4242
return new ContextKeyAndExpr(expr);
4343
}
4444

45-
public static deserialize(serialized: string | null | undefined): ContextKeyExpr | null {
45+
public static deserialize(serialized: string | null | undefined, strict: boolean = false): ContextKeyExpr | null {
4646
if (!serialized) {
4747
return null;
4848
}
4949

5050
let pieces = serialized.split('&&');
51-
let result = new ContextKeyAndExpr(pieces.map(p => this._deserializeOne(p)));
51+
let result = new ContextKeyAndExpr(pieces.map(p => this._deserializeOne(p, strict)));
5252
return result.normalize();
5353
}
5454

55-
private static _deserializeOne(serializedOne: string): ContextKeyExpr {
55+
private static _deserializeOne(serializedOne: string, strict: boolean): ContextKeyExpr {
5656
serializedOne = serializedOne.trim();
5757

5858
if (serializedOne.indexOf('!=') >= 0) {
5959
let pieces = serializedOne.split('!=');
60-
return new ContextKeyNotEqualsExpr(pieces[0].trim(), this._deserializeValue(pieces[1]));
60+
return new ContextKeyNotEqualsExpr(pieces[0].trim(), this._deserializeValue(pieces[1], strict));
6161
}
6262

6363
if (serializedOne.indexOf('==') >= 0) {
6464
let pieces = serializedOne.split('==');
65-
return new ContextKeyEqualsExpr(pieces[0].trim(), this._deserializeValue(pieces[1]));
65+
return new ContextKeyEqualsExpr(pieces[0].trim(), this._deserializeValue(pieces[1], strict));
6666
}
6767

6868
if (serializedOne.indexOf('=~') >= 0) {
6969
let pieces = serializedOne.split('=~');
70-
return new ContextKeyRegexExpr(pieces[0].trim(), this._deserializeRegexValue(pieces[1]));
70+
return new ContextKeyRegexExpr(pieces[0].trim(), this._deserializeRegexValue(pieces[1], strict));
7171
}
7272

7373
if (/^\!\s*/.test(serializedOne)) {
@@ -77,7 +77,7 @@ export abstract class ContextKeyExpr {
7777
return new ContextKeyDefinedExpr(serializedOne);
7878
}
7979

80-
private static _deserializeValue(serializedValue: string): any {
80+
private static _deserializeValue(serializedValue: string, strict: boolean): any {
8181
serializedValue = serializedValue.trim();
8282

8383
if (serializedValue === 'true') {
@@ -96,17 +96,25 @@ export abstract class ContextKeyExpr {
9696
return serializedValue;
9797
}
9898

99-
private static _deserializeRegexValue(serializedValue: string): RegExp | null {
99+
private static _deserializeRegexValue(serializedValue: string, strict: boolean): RegExp | null {
100100

101101
if (isFalsyOrWhitespace(serializedValue)) {
102-
console.warn('missing regexp-value for =~-expression');
102+
if (strict) {
103+
throw new Error('missing regexp-value for =~-expression');
104+
} else {
105+
console.warn('missing regexp-value for =~-expression');
106+
}
103107
return null;
104108
}
105109

106110
let start = serializedValue.indexOf('/');
107111
let end = serializedValue.lastIndexOf('/');
108112
if (start === end || start < 0 /* || to < 0 */) {
109-
console.warn(`bad regexp-value '${serializedValue}', missing /-enclosure`);
113+
if (strict) {
114+
throw new Error(`bad regexp-value '${serializedValue}', missing /-enclosure`);
115+
} else {
116+
console.warn(`bad regexp-value '${serializedValue}', missing /-enclosure`);
117+
}
110118
return null;
111119
}
112120

@@ -115,7 +123,11 @@ export abstract class ContextKeyExpr {
115123
try {
116124
return new RegExp(value, caseIgnoreFlag);
117125
} catch (e) {
118-
console.warn(`bad regexp-value '${serializedValue}', parse error: ${e}`);
126+
if (strict) {
127+
throw new Error(`bad regexp-value '${serializedValue}', parse error: ${e}`);
128+
} else {
129+
console.warn(`bad regexp-value '${serializedValue}', parse error: ${e}`);
130+
}
119131
return null;
120132
}
121133
}

0 commit comments

Comments
 (0)