From d21cbabe6b047c3d7333c3647aabe67c49fc6755 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sun, 25 Oct 2020 22:45:58 -0400 Subject: [PATCH] Adds default context caching for objects Clears all cached config context values for objects --- .../contextkey/browser/contextKeyService.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/vs/platform/contextkey/browser/contextKeyService.ts b/src/vs/platform/contextkey/browser/contextKeyService.ts index b4d8e42cf9a..84870cdefe2 100644 --- a/src/vs/platform/contextkey/browser/contextKeyService.ts +++ b/src/vs/platform/contextkey/browser/contextKeyService.ts @@ -89,6 +89,8 @@ class NullContext extends Context { } } +const configContextObject = Object.freeze({}); + class ConfigAwareContextValuesContainer extends Context { private static readonly _keyPrefix = 'config.'; @@ -112,10 +114,23 @@ class ConfigAwareContextValuesContainer extends Context { } else { const changedKeys: string[] = []; for (const configKey of event.affectedKeys) { - const contextKey = `config.${configKey}`; + let contextKey = `config.${configKey}`; if (this._values.has(contextKey)) { + const value = this._values.get(contextKey); + this._values.delete(contextKey); changedKeys.push(contextKey); + + if (value === configContextObject) { + contextKey += '.'; + + for (const key of this._values.keys()) { + if (key.startsWith(contextKey)) { + this._values.delete(key); + changedKeys.push(key); + } + } + } } } emitter.fire(new ArrayContextKeyChangeEvent(changedKeys)); @@ -149,6 +164,8 @@ class ConfigAwareContextValuesContainer extends Context { default: if (Array.isArray(configValue)) { value = JSON.stringify(configValue); + } else { + value = configContextObject; } } -- GitLab