Skip to content

Commit 08c67e4

Browse files
committed
context keys: use old context key parser as default
1 parent e7a81d0 commit 08c67e4

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

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

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -126,30 +126,21 @@ export abstract class ContextKeyExpr {
126126
return ContextKeySmallerEqualsExpr.create(key, value);
127127
}
128128

129-
public static deserializeNew(serialized: string | null | undefined): ContextKeyExpression | undefined {
129+
/**
130+
* Warning: experimental; the API might change.
131+
*/
132+
public static deserializeOrErrorNew(serialized: string | null | undefined): { type: 'ok'; expr: ContextKeyExpr } | { type: 'error'; readonly lexingErrors: string[]; readonly parsingErrors: readonly string[] } {
130133
if (!serialized) {
131-
return undefined;
134+
return { type: 'error', lexingErrors: [], parsingErrors: [] };
132135
}
133136

134137
const parser = new Parser();
135138
const expr = parser.parse(serialized);
136-
if (expr === undefined) { // print a console warning
137-
const warning = [];
138-
warning.push(`Failed to parse context key expression ("when clause"): ${serialized}\n`);
139-
if (parser.lexingErrors.length > 0) {
140-
warning.push('Lexing errors:\n\n');
141-
parser.lexingErrors.forEach(token => warning.push(Scanner.reportError(token), '\n'));
142-
}
143-
144-
if (parser.parsingErrors.length > 0) {
145-
if (parser.lexingErrors.length > 0) { warning.push('\n\n'); } // separate lexing errors from parsing errors
146-
warning.push('Parsing errors:\n\n');
147-
parser.parsingErrors.forEach(message => warning.push(`${message}`, '\n'));
148-
}
149-
console.warn(warning.join(''));
139+
if (expr === undefined) {
140+
return { type: 'error', lexingErrors: parser.lexingErrors.map(token => Scanner.reportError(token)), parsingErrors: parser.parsingErrors };
141+
} else {
142+
return { type: 'ok', expr };
150143
}
151-
152-
return expr;
153144
}
154145

155146
public static deserialize(serialized: string | null | undefined): ContextKeyExpression | undefined {
@@ -1488,8 +1479,7 @@ export class ContextKeyRegexExpr implements IContextKeyExpression {
14881479

14891480
public serialize(): string {
14901481
const value = this.regexp
1491-
// ? `/${this.regexp.source}/${this.regexp.flags}`
1492-
? `/${this.regexp.source}/`
1482+
? `/${this.regexp.source}/${this.regexp.flags}`
14931483
: '/invalid/';
14941484
return `${this.key} =~ ${value}`;
14951485
}

0 commit comments

Comments
 (0)