Merge from vscode 7eaf220cafb9d9e901370ffce02229171cbf3ea6

This commit is contained in:
ADS Merger
2020-09-03 02:34:56 +00:00
committed by Anthony Dresser
parent 39d9eed585
commit a63578e6f7
519 changed files with 14338 additions and 6670 deletions

View File

@@ -9,7 +9,6 @@ import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IContext, IContextKey, IContextKeyChangeEvent, IContextKeyService, IContextKeyServiceTarget, IReadableSet, SET_CONTEXT_COMMAND_ID, ContextKeyExpression } from 'vs/platform/contextkey/common/contextkey';
import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingResolver';
import { toArray } from 'vs/base/common/arrays';
const KEYBINDING_CONTEXT_ATTR = 'data-keybinding-context';
@@ -102,7 +101,7 @@ class ConfigAwareContextValuesContainer extends Context {
this._listener = this._configurationService.onDidChangeConfiguration(event => {
if (event.source === ConfigurationTarget.DEFAULT) {
// new setting, reset everything
const allKeys = toArray(this._values.keys());
const allKeys = Array.from(this._values.keys());
this._values.clear();
emitter.fire(new ArrayContextKeyChangeEvent(allKeys));
} else {

View File

@@ -17,6 +17,8 @@ STATIC_VALUES.set('isWindows', isWindows);
STATIC_VALUES.set('isWeb', isWeb);
STATIC_VALUES.set('isMacNative', isMacintosh && !isWeb);
const hasOwnProperty = Object.prototype.hasOwnProperty;
export const enum ContextKeyExprType {
False = 0,
True = 1,
@@ -28,8 +30,10 @@ export const enum ContextKeyExprType {
Regex = 7,
NotRegex = 8,
Or = 9,
GreaterThanEquals = 10, // {{SQL CARBON EDIT}} add value
LessThanEquals = 11 // {{SQL CARBON EDIT}} add value
In = 10,
NotIn = 11,
GreaterThanEquals = 12, // {{SQL CARBON EDIT}} add value
LessThanEquals = 13 // {{SQL CARBON EDIT}} add value
}
export interface IContextKeyExprMapper {
@@ -38,6 +42,7 @@ export interface IContextKeyExprMapper {
mapEquals(key: string, value: any): ContextKeyExpression;
mapNotEquals(key: string, value: any): ContextKeyExpression;
mapRegex(key: string, regexp: RegExp | null): ContextKeyRegexExpr;
mapIn(key: string, valueKey: string): ContextKeyInExpr;
}
export interface IContextKeyExpression {
@@ -54,7 +59,7 @@ export interface IContextKeyExpression {
export type ContextKeyExpression = (
ContextKeyFalseExpr | ContextKeyTrueExpr | ContextKeyDefinedExpr | ContextKeyNotExpr
| ContextKeyEqualsExpr | ContextKeyNotEqualsExpr | ContextKeyRegexExpr
| ContextKeyNotRegexExpr | ContextKeyAndExpr | ContextKeyOrExpr | ContextKeyGreaterThanEqualsExpr | ContextKeyLessThanEqualsExpr
| ContextKeyNotRegexExpr | ContextKeyAndExpr | ContextKeyOrExpr | ContextKeyInExpr | ContextKeyNotInExpr | ContextKeyGreaterThanEqualsExpr | ContextKeyLessThanEqualsExpr // {{ SQL CARBON EDIT }}
);
export abstract class ContextKeyExpr {
@@ -83,6 +88,10 @@ export abstract class ContextKeyExpr {
return ContextKeyRegexExpr.create(key, value);
}
public static in(key: string, value: string): ContextKeyExpression {
return ContextKeyInExpr.create(key, value);
}
public static not(key: string): ContextKeyExpression {
return ContextKeyNotExpr.create(key);
}
@@ -151,6 +160,10 @@ export abstract class ContextKeyExpr {
return ContextKeyLessThanEqualsExpr.create(pieces[0].trim(), this._deserializeValue(pieces[1], strict));
}
//
if (serializedOne.indexOf(' in ') >= 0) {
let pieces = serializedOne.split(' in ');
return ContextKeyInExpr.create(pieces[0].trim(), pieces[1].trim());
}
if (/^\!\s*/.test(serializedOne)) {
return ContextKeyNotExpr.create(serializedOne.substr(1).trim());
@@ -416,6 +429,122 @@ export class ContextKeyEqualsExpr implements IContextKeyExpression {
}
}
export class ContextKeyInExpr implements IContextKeyExpression {
public static create(key: string, valueKey: string): ContextKeyInExpr {
return new ContextKeyInExpr(key, valueKey);
}
public readonly type = ContextKeyExprType.In;
private constructor(private readonly key: string, private readonly valueKey: string) {
}
public cmp(other: ContextKeyExpression): number {
if (other.type !== this.type) {
return this.type - other.type;
}
if (this.key < other.key) {
return -1;
}
if (this.key > other.key) {
return 1;
}
if (this.valueKey < other.valueKey) {
return -1;
}
if (this.valueKey > other.valueKey) {
return 1;
}
return 0;
}
public equals(other: ContextKeyExpression): boolean {
if (other.type === this.type) {
return (this.key === other.key && this.valueKey === other.valueKey);
}
return false;
}
public evaluate(context: IContext): boolean {
const source = context.getValue(this.valueKey);
const item = context.getValue(this.key);
if (Array.isArray(source)) {
return (source.indexOf(item) >= 0);
}
if (typeof item === 'string' && typeof source === 'object' && source !== null) {
return hasOwnProperty.call(source, item);
}
return false;
}
public serialize(): string {
return this.key + ' in \'' + this.valueKey + '\'';
}
public keys(): string[] {
return [this.key, this.valueKey];
}
public map(mapFnc: IContextKeyExprMapper): ContextKeyInExpr {
return mapFnc.mapIn(this.key, this.valueKey);
}
public negate(): ContextKeyExpression {
return ContextKeyNotInExpr.create(this);
}
}
export class ContextKeyNotInExpr implements IContextKeyExpression {
public static create(actual: ContextKeyInExpr): ContextKeyNotInExpr {
return new ContextKeyNotInExpr(actual);
}
public readonly type = ContextKeyExprType.NotIn;
private constructor(private readonly _actual: ContextKeyInExpr) {
//
}
public cmp(other: ContextKeyExpression): number {
if (other.type !== this.type) {
return this.type - other.type;
}
return this._actual.cmp(other._actual);
}
public equals(other: ContextKeyExpression): boolean {
if (other.type === this.type) {
return this._actual.equals(other._actual);
}
return false;
}
public evaluate(context: IContext): boolean {
return !this._actual.evaluate(context);
}
public serialize(): string {
throw new Error('Method not implemented.');
}
public keys(): string[] {
return this._actual.keys();
}
public map(mapFnc: IContextKeyExprMapper): ContextKeyExpression {
return new ContextKeyNotInExpr(this._actual.map(mapFnc));
}
public negate(): ContextKeyExpression {
return this._actual;
}
}
export class ContextKeyNotEqualsExpr implements IContextKeyExpression {
public static create(key: string, value: any): ContextKeyExpression {

View File

@@ -162,4 +162,19 @@ suite('ContextKeyExpr', () => {
t('a || b', 'c && d', 'a && c && d || b && c && d');
t('a || b', 'c && d || e', 'a && e || b && e || a && c && d || b && c && d');
});
test('ContextKeyInExpr', () => {
const ainb = ContextKeyExpr.deserialize('a in b')!;
assert.equal(ainb.evaluate(createContext({ 'a': 3, 'b': [3, 2, 1] })), true);
assert.equal(ainb.evaluate(createContext({ 'a': 3, 'b': [1, 2, 3] })), true);
assert.equal(ainb.evaluate(createContext({ 'a': 3, 'b': [1, 2] })), false);
assert.equal(ainb.evaluate(createContext({ 'a': 3 })), false);
assert.equal(ainb.evaluate(createContext({ 'a': 3, 'b': null })), false);
assert.equal(ainb.evaluate(createContext({ 'a': 'x', 'b': ['x'] })), true);
assert.equal(ainb.evaluate(createContext({ 'a': 'x', 'b': ['y'] })), false);
assert.equal(ainb.evaluate(createContext({ 'a': 'x', 'b': {} })), false);
assert.equal(ainb.evaluate(createContext({ 'a': 'x', 'b': { 'x': false } })), true);
assert.equal(ainb.evaluate(createContext({ 'a': 'x', 'b': { 'x': true } })), true);
assert.equal(ainb.evaluate(createContext({ 'a': 'prototype', 'b': {} })), false);
});
});