Update to VS Code 1.52.1

This commit is contained in:
Asher
2021-02-09 16:08:37 +00:00
1351 changed files with 56560 additions and 38990 deletions

View File

@@ -4,7 +4,9 @@
*--------------------------------------------------------------------------------------------*/
import { Emitter, Event, PauseableEmitter } from 'vs/base/common/event';
import { Iterable } from 'vs/base/common/iterator';
import { IDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { TernarySearchTree } from 'vs/base/common/map';
import { distinct } from 'vs/base/common/objects';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration';
@@ -90,10 +92,9 @@ class NullContext extends Context {
}
class ConfigAwareContextValuesContainer extends Context {
private static readonly _keyPrefix = 'config.';
private readonly _values = new Map<string, any>();
private readonly _values = TernarySearchTree.forConfigKeys<any>();
private readonly _listener: IDisposable;
constructor(
@@ -106,18 +107,26 @@ class ConfigAwareContextValuesContainer extends Context {
this._listener = this._configurationService.onDidChangeConfiguration(event => {
if (event.source === ConfigurationTarget.DEFAULT) {
// new setting, reset everything
const allKeys = Array.from(this._values.keys());
const allKeys = Array.from(Iterable.map(this._values, ([k]) => k));
this._values.clear();
emitter.fire(new ArrayContextKeyChangeEvent(allKeys));
} else {
const changedKeys: string[] = [];
for (const configKey of event.affectedKeys) {
const contextKey = `config.${configKey}`;
const cachedItems = this._values.findSuperstr(contextKey);
if (cachedItems !== undefined) {
changedKeys.push(...Iterable.map(cachedItems, ([key]) => key));
this._values.deleteSuperstr(contextKey);
}
if (this._values.has(contextKey)) {
this._values.delete(contextKey);
changedKeys.push(contextKey);
this._values.delete(contextKey);
}
}
emitter.fire(new ArrayContextKeyChangeEvent(changedKeys));
}
});
@@ -149,6 +158,8 @@ class ConfigAwareContextValuesContainer extends Context {
default:
if (Array.isArray(configValue)) {
value = JSON.stringify(configValue);
} else {
value = configValue;
}
}
@@ -405,6 +416,9 @@ class ScopedContextKeyService extends AbstractContextKeyService {
if (domNode) {
this._domNode = domNode;
if (this._domNode.hasAttribute(KEYBINDING_CONTEXT_ATTR)) {
console.error('Element already has context attribute');
}
this._domNode.setAttribute(KEYBINDING_CONTEXT_ATTR, String(this._myContextId));
}
}

View File

@@ -6,8 +6,9 @@
import { Event } from 'vs/base/common/event';
import { isFalsyOrWhitespace } from 'vs/base/common/strings';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { isMacintosh, isLinux, isWindows, isWeb } from 'vs/base/common/platform';
import { userAgent, isMacintosh, isLinux, isWindows, isWeb } from 'vs/base/common/platform';
let _userAgent = userAgent || '';
const STATIC_VALUES = new Map<string, boolean>();
STATIC_VALUES.set('false', false);
STATIC_VALUES.set('true', true);
@@ -16,6 +17,11 @@ STATIC_VALUES.set('isLinux', isLinux);
STATIC_VALUES.set('isWindows', isWindows);
STATIC_VALUES.set('isWeb', isWeb);
STATIC_VALUES.set('isMacNative', isMacintosh && !isWeb);
STATIC_VALUES.set('isEdge', _userAgent.indexOf('Edg/') >= 0);
STATIC_VALUES.set('isFirefox', _userAgent.indexOf('Firefox') >= 0);
STATIC_VALUES.set('isChrome', _userAgent.indexOf('Chrome') >= 0);
STATIC_VALUES.set('isSafari', _userAgent.indexOf('Safari') >= 0);
STATIC_VALUES.set('isIPad', _userAgent.indexOf('iPad') >= 0);
const hasOwnProperty = Object.prototype.hasOwnProperty;
@@ -32,6 +38,10 @@ export const enum ContextKeyExprType {
Or = 9,
In = 10,
NotIn = 11,
Greater = 12,
GreaterEquals = 13,
Smaller = 14,
SmallerEquals = 15,
}
export interface IContextKeyExprMapper {
@@ -39,6 +49,10 @@ export interface IContextKeyExprMapper {
mapNot(key: string): ContextKeyExpression;
mapEquals(key: string, value: any): ContextKeyExpression;
mapNotEquals(key: string, value: any): ContextKeyExpression;
mapGreater(key: string, value: any): ContextKeyExpression;
mapGreaterEquals(key: string, value: any): ContextKeyExpression;
mapSmaller(key: string, value: any): ContextKeyExpression;
mapSmallerEquals(key: string, value: any): ContextKeyExpression;
mapRegex(key: string, regexp: RegExp | null): ContextKeyRegexExpr;
mapIn(key: string, valueKey: string): ContextKeyInExpr;
}
@@ -57,7 +71,9 @@ export interface IContextKeyExpression {
export type ContextKeyExpression = (
ContextKeyFalseExpr | ContextKeyTrueExpr | ContextKeyDefinedExpr | ContextKeyNotExpr
| ContextKeyEqualsExpr | ContextKeyNotEqualsExpr | ContextKeyRegexExpr
| ContextKeyNotRegexExpr | ContextKeyAndExpr | ContextKeyOrExpr | ContextKeyInExpr | ContextKeyNotInExpr
| ContextKeyNotRegexExpr | ContextKeyAndExpr | ContextKeyOrExpr | ContextKeyInExpr
| ContextKeyNotInExpr | ContextKeyGreaterExpr | ContextKeyGreaterEqualsExpr
| ContextKeySmallerExpr | ContextKeySmallerEqualsExpr
);
export abstract class ContextKeyExpr {
@@ -102,6 +118,14 @@ export abstract class ContextKeyExpr {
return ContextKeyOrExpr.create(expr);
}
public static greater(key: string, value: any): ContextKeyExpression {
return ContextKeyGreaterExpr.create(key, value);
}
public static less(key: string, value: any): ContextKeyExpression {
return ContextKeySmallerExpr.create(key, value);
}
public static deserialize(serialized: string | null | undefined, strict: boolean = false): ContextKeyExpression | undefined {
if (!serialized) {
return undefined;
@@ -143,6 +167,26 @@ export abstract class ContextKeyExpr {
return ContextKeyInExpr.create(pieces[0].trim(), pieces[1].trim());
}
if (/^[^<=>]+>=[^<=>]+$/.test(serializedOne)) {
const pieces = serializedOne.split('>=');
return ContextKeyGreaterEqualsExpr.create(pieces[0].trim(), pieces[1].trim());
}
if (/^[^<=>]+>[^<=>]+$/.test(serializedOne)) {
const pieces = serializedOne.split('>');
return ContextKeyGreaterExpr.create(pieces[0].trim(), pieces[1].trim());
}
if (/^[^<=>]+<=[^<=>]+$/.test(serializedOne)) {
const pieces = serializedOne.split('<=');
return ContextKeySmallerEqualsExpr.create(pieces[0].trim(), pieces[1].trim());
}
if (/^[^<=>]+<[^<=>]+$/.test(serializedOne)) {
const pieces = serializedOne.split('<');
return ContextKeySmallerExpr.create(pieces[0].trim(), pieces[1].trim());
}
if (/^\!\s*/.test(serializedOne)) {
return ContextKeyNotExpr.create(serializedOne.substr(1).trim());
}
@@ -302,13 +346,7 @@ export class ContextKeyDefinedExpr implements IContextKeyExpression {
if (other.type !== this.type) {
return this.type - other.type;
}
if (this.key < other.key) {
return -1;
}
if (this.key > other.key) {
return 1;
}
return 0;
return cmp1(this.key, other.key);
}
public equals(other: ContextKeyExpression): boolean {
@@ -362,19 +400,7 @@ export class ContextKeyEqualsExpr implements IContextKeyExpression {
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.value < other.value) {
return -1;
}
if (this.value > other.value) {
return 1;
}
return 0;
return cmp2(this.key, this.value, other.key, other.value);
}
public equals(other: ContextKeyExpression): boolean {
@@ -391,7 +417,7 @@ export class ContextKeyEqualsExpr implements IContextKeyExpression {
}
public serialize(): string {
return this.key + ' == \'' + this.value + '\'';
return `${this.key} == '${this.value}'`;
}
public keys(): string[] {
@@ -422,19 +448,7 @@ export class ContextKeyInExpr implements IContextKeyExpression {
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;
return cmp2(this.key, this.valueKey, other.key, other.valueKey);
}
public equals(other: ContextKeyExpression): boolean {
@@ -460,7 +474,7 @@ export class ContextKeyInExpr implements IContextKeyExpression {
}
public serialize(): string {
return this.key + ' in \'' + this.valueKey + '\'';
return `${this.key} in '${this.valueKey}'`;
}
public keys(): string[] {
@@ -549,19 +563,7 @@ export class ContextKeyNotEqualsExpr implements IContextKeyExpression {
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.value < other.value) {
return -1;
}
if (this.value > other.value) {
return 1;
}
return 0;
return cmp2(this.key, this.value, other.key, other.value);
}
public equals(other: ContextKeyExpression): boolean {
@@ -578,7 +580,7 @@ export class ContextKeyNotEqualsExpr implements IContextKeyExpression {
}
public serialize(): string {
return this.key + ' != \'' + this.value + '\'';
return `${this.key} != '${this.value}'`;
}
public keys(): string[] {
@@ -613,13 +615,7 @@ export class ContextKeyNotExpr implements IContextKeyExpression {
if (other.type !== this.type) {
return this.type - other.type;
}
if (this.key < other.key) {
return -1;
}
if (this.key > other.key) {
return 1;
}
return 0;
return cmp1(this.key, other.key);
}
public equals(other: ContextKeyExpression): boolean {
@@ -634,7 +630,7 @@ export class ContextKeyNotExpr implements IContextKeyExpression {
}
public serialize(): string {
return '!' + this.key;
return `!${this.key}`;
}
public keys(): string[] {
@@ -650,6 +646,200 @@ export class ContextKeyNotExpr implements IContextKeyExpression {
}
}
export class ContextKeyGreaterExpr implements IContextKeyExpression {
public static create(key: string, value: any): ContextKeyExpression {
return new ContextKeyGreaterExpr(key, value);
}
public readonly type = ContextKeyExprType.Greater;
private constructor(
private readonly key: string,
private readonly value: any
) { }
public cmp(other: ContextKeyExpression): number {
if (other.type !== this.type) {
return this.type - other.type;
}
return cmp2(this.key, this.value, other.key, other.value);
}
public equals(other: ContextKeyExpression): boolean {
if (other.type === this.type) {
return (this.key === other.key && this.value === other.value);
}
return false;
}
public evaluate(context: IContext): boolean {
return (parseFloat(<any>context.getValue(this.key)) > parseFloat(this.value));
}
public serialize(): string {
return `${this.key} > ${this.value}`;
}
public keys(): string[] {
return [this.key];
}
public map(mapFnc: IContextKeyExprMapper): ContextKeyExpression {
return mapFnc.mapGreater(this.key, this.value);
}
public negate(): ContextKeyExpression {
return ContextKeySmallerEqualsExpr.create(this.key, this.value);
}
}
export class ContextKeyGreaterEqualsExpr implements IContextKeyExpression {
public static create(key: string, value: any): ContextKeyExpression {
return new ContextKeyGreaterEqualsExpr(key, value);
}
public readonly type = ContextKeyExprType.GreaterEquals;
private constructor(
private readonly key: string,
private readonly value: any
) { }
public cmp(other: ContextKeyExpression): number {
if (other.type !== this.type) {
return this.type - other.type;
}
return cmp2(this.key, this.value, other.key, other.value);
}
public equals(other: ContextKeyExpression): boolean {
if (other.type === this.type) {
return (this.key === other.key && this.value === other.value);
}
return false;
}
public evaluate(context: IContext): boolean {
return (parseFloat(<any>context.getValue(this.key)) >= parseFloat(this.value));
}
public serialize(): string {
return `${this.key} >= ${this.value}`;
}
public keys(): string[] {
return [this.key];
}
public map(mapFnc: IContextKeyExprMapper): ContextKeyExpression {
return mapFnc.mapGreaterEquals(this.key, this.value);
}
public negate(): ContextKeyExpression {
return ContextKeySmallerExpr.create(this.key, this.value);
}
}
export class ContextKeySmallerExpr implements IContextKeyExpression {
public static create(key: string, value: any): ContextKeyExpression {
return new ContextKeySmallerExpr(key, value);
}
public readonly type = ContextKeyExprType.Smaller;
private constructor(
private readonly key: string,
private readonly value: any
) {
}
public cmp(other: ContextKeyExpression): number {
if (other.type !== this.type) {
return this.type - other.type;
}
return cmp2(this.key, this.value, other.key, other.value);
}
public equals(other: ContextKeyExpression): boolean {
if (other.type === this.type) {
return (this.key === other.key && this.value === other.value);
}
return false;
}
public evaluate(context: IContext): boolean {
return (parseFloat(<any>context.getValue(this.key)) < parseFloat(this.value));
}
public serialize(): string {
return `${this.key} < ${this.value}`;
}
public keys(): string[] {
return [this.key];
}
public map(mapFnc: IContextKeyExprMapper): ContextKeyExpression {
return mapFnc.mapSmaller(this.key, this.value);
}
public negate(): ContextKeyExpression {
return ContextKeyGreaterEqualsExpr.create(this.key, this.value);
}
}
export class ContextKeySmallerEqualsExpr implements IContextKeyExpression {
public static create(key: string, value: any): ContextKeyExpression {
return new ContextKeySmallerEqualsExpr(key, value);
}
public readonly type = ContextKeyExprType.SmallerEquals;
private constructor(
private readonly key: string,
private readonly value: any
) {
}
public cmp(other: ContextKeyExpression): number {
if (other.type !== this.type) {
return this.type - other.type;
}
return cmp2(this.key, this.value, other.key, other.value);
}
public equals(other: ContextKeyExpression): boolean {
if (other.type === this.type) {
return (this.key === other.key && this.value === other.value);
}
return false;
}
public evaluate(context: IContext): boolean {
return (parseFloat(<any>context.getValue(this.key)) <= parseFloat(this.value));
}
public serialize(): string {
return `${this.key} <= ${this.value}`;
}
public keys(): string[] {
return [this.key];
}
public map(mapFnc: IContextKeyExprMapper): ContextKeyExpression {
return mapFnc.mapSmallerEquals(this.key, this.value);
}
public negate(): ContextKeyExpression {
return ContextKeyGreaterExpr.create(this.key, this.value);
}
}
export class ContextKeyRegexExpr implements IContextKeyExpression {
public static create(key: string, regexp: RegExp | null): ContextKeyRegexExpr {
@@ -1143,3 +1333,29 @@ export interface IContextKeyService {
}
export const SET_CONTEXT_COMMAND_ID = 'setContext';
function cmp1(key1: string, key2: string): number {
if (key1 < key2) {
return -1;
}
if (key1 > key2) {
return 1;
}
return 0;
}
function cmp2(key1: string, value1: any, key2: string, value2: any): number {
if (key1 < key2) {
return -1;
}
if (key1 > key2) {
return 1;
}
if (value1 < value2) {
return -1;
}
if (value1 > value2) {
return 1;
}
return 0;
}

View File

@@ -186,4 +186,84 @@ suite('ContextKeyExpr', () => {
);
assert.equal(actual!.equals(expected!), true);
});
test('Greater, GreaterEquals, Smaller, SmallerEquals evaluate', () => {
function checkEvaluate(expr: string, ctx: any, expected: any): void {
const _expr = ContextKeyExpr.deserialize(expr)!;
assert.equal(_expr.evaluate(createContext(ctx)), expected);
}
checkEvaluate('a>1', {}, false);
checkEvaluate('a>1', { a: 0 }, false);
checkEvaluate('a>1', { a: 1 }, false);
checkEvaluate('a>1', { a: 2 }, true);
checkEvaluate('a>1', { a: '0' }, false);
checkEvaluate('a>1', { a: '1' }, false);
checkEvaluate('a>1', { a: '2' }, true);
checkEvaluate('a>1', { a: 'a' }, false);
checkEvaluate('a>10', { a: 2 }, false);
checkEvaluate('a>10', { a: 11 }, true);
checkEvaluate('a>10', { a: '11' }, true);
checkEvaluate('a>10', { a: '2' }, false);
checkEvaluate('a>10', { a: '11' }, true);
checkEvaluate('a>1.1', { a: 1 }, false);
checkEvaluate('a>1.1', { a: 2 }, true);
checkEvaluate('a>1.1', { a: 11 }, true);
checkEvaluate('a>1.1', { a: '1.1' }, false);
checkEvaluate('a>1.1', { a: '2' }, true);
checkEvaluate('a>1.1', { a: '11' }, true);
checkEvaluate('a>b', { a: 'b' }, false);
checkEvaluate('a>b', { a: 'c' }, false);
checkEvaluate('a>b', { a: 1000 }, false);
checkEvaluate('a >= 2', { a: '1' }, false);
checkEvaluate('a >= 2', { a: '2' }, true);
checkEvaluate('a >= 2', { a: '3' }, true);
checkEvaluate('a < 2', { a: '1' }, true);
checkEvaluate('a < 2', { a: '2' }, false);
checkEvaluate('a < 2', { a: '3' }, false);
checkEvaluate('a <= 2', { a: '1' }, true);
checkEvaluate('a <= 2', { a: '2' }, true);
checkEvaluate('a <= 2', { a: '3' }, false);
});
test('Greater, GreaterEquals, Smaller, SmallerEquals negate', () => {
function checkNegate(expr: string, expected: string): void {
const a = ContextKeyExpr.deserialize(expr)!;
const b = a.negate();
assert.equal(b.serialize(), expected);
}
checkNegate('a>1', 'a <= 1');
checkNegate('a>1.1', 'a <= 1.1');
checkNegate('a>b', 'a <= b');
checkNegate('a>=1', 'a < 1');
checkNegate('a>=1.1', 'a < 1.1');
checkNegate('a>=b', 'a < b');
checkNegate('a<1', 'a >= 1');
checkNegate('a<1.1', 'a >= 1.1');
checkNegate('a<b', 'a >= b');
checkNegate('a<=1', 'a > 1');
checkNegate('a<=1.1', 'a > 1.1');
checkNegate('a<=b', 'a > b');
});
test('issue #111899: context keys can use `<` or `>` ', () => {
const actual = ContextKeyExpr.deserialize('editorTextFocus && vim.active && vim.use<C-r>')!;
assert.ok(actual.equals(
ContextKeyExpr.and(
ContextKeyExpr.has('editorTextFocus'),
ContextKeyExpr.has('vim.active'),
ContextKeyExpr.has('vim.use<C-r>'),
)!
));
});
});