From e71df65ccd9f2e3c77cb47f52aceb8ff5ca1db7b Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sun, 26 Mar 2023 12:22:56 -0400 Subject: [PATCH] Clarifies/refines configuration events & overrides --- src/container.ts | 34 +++++++--------------- src/plus/github/github.ts | 2 +- src/plus/gitlab/gitlab.ts | 2 +- src/system/configuration.ts | 26 ++++++++--------- src/webviews/commitDetails/commitDetailsWebview.ts | 4 +-- src/webviews/webviewWithConfigBase.ts | 4 +-- 6 files changed, 30 insertions(+), 42 deletions(-) diff --git a/src/container.ts b/src/container.ts index 583a5a9..2eb0d19 100644 --- a/src/container.ts +++ b/src/container.ts @@ -158,7 +158,6 @@ export class Container { }, }; - private _configAffectedByModeRegex: RegExp | undefined; private _terminalLinks: GitTerminalLinkProvider | undefined; private _webviews: WebviewsController; @@ -179,7 +178,9 @@ export class Container { context.subscriptions.unshift((this._telemetry = new TelemetryService(this))); context.subscriptions.unshift((this._usage = new UsageTracker(this, storage))); - context.subscriptions.unshift(configuration.onWillChange(this.onConfigurationChanging, this)); + context.subscriptions.unshift( + configuration.onDidChangeBeforeOverrides(this.onConfigurationChangedBeforeOverrides, this), + ); this._richRemoteProviders = new RichRemoteProviderService(this); @@ -291,7 +292,7 @@ export class Container { this._git.registrationComplete(); } - private onConfigurationChanging(e: ConfigurationChangeEvent) { + private onConfigurationChangedBeforeOverrides(e: ConfigurationChangeEvent) { this._mode = undefined; if (configuration.changed(e, 'outputLevel')) { @@ -695,28 +696,15 @@ export class Container { return cfg; }, - onChange: e => { + onDidChange: e => { // When the mode or modes change, we will simulate that all the affected configuration also changed - if (configuration.changed(e, ['mode', 'modes'])) { - if (this._configAffectedByModeRegex == null) { - this._configAffectedByModeRegex = new RegExp( - `^gitlens\\.(?:${configuration.name('mode')}|${configuration.name( - 'modes', - )}|${configuration.name('blame')}|${configuration.name('changes')}|${configuration.name( - 'heatmap', - )}|${configuration.name('codeLens')}|${configuration.name( - 'currentLine', - )}|${configuration.name('hovers')}|${configuration.name('statusBar')})\\b`, - ); - } + if (!configuration.changed(e, ['mode', 'modes'])) return e; - const original = e.affectsConfiguration; - e = { - ...e, - affectsConfiguration: (section, scope) => - this._configAffectedByModeRegex!.test(section) ? true : original(section, scope), - }; - } + const originalAffectsConfiguration = e.affectsConfiguration; + e.affectsConfiguration = (section, scope) => + /^gitlens\\.(?:modes?|blame|changes|heatmap|codeLens|currentLine|hovers|statusBar)\\b/.test(section) + ? true + : originalAffectsConfiguration(section, scope); return e; }, }); diff --git a/src/plus/github/github.ts b/src/plus/github/github.ts index b4f6d7b..a970b59 100644 --- a/src/plus/github/github.ts +++ b/src/plus/github/github.ts @@ -195,7 +195,7 @@ export class GitHubApi implements Disposable { this.resetCaches(); } }), - configuration.onDidChangeAny(e => { + configuration.onDidChangeOther(e => { if (e.affectsConfiguration('http.proxy') || e.affectsConfiguration('http.proxyStrictSSL')) { this.resetCaches(); } diff --git a/src/plus/gitlab/gitlab.ts b/src/plus/gitlab/gitlab.ts index 9324063..c845982 100644 --- a/src/plus/gitlab/gitlab.ts +++ b/src/plus/gitlab/gitlab.ts @@ -45,7 +45,7 @@ export class GitLabApi implements Disposable { this._proxyAgents.clear(); } }), - configuration.onDidChangeAny(e => { + configuration.onDidChangeOther(e => { if (e.affectsConfiguration('http.proxy') || e.affectsConfiguration('http.proxyStrictSSL')) { this._projectIds.clear(); this._proxyAgents.clear(); diff --git a/src/system/configuration.ts b/src/system/configuration.ts index d08a064..456e33d 100644 --- a/src/system/configuration.ts +++ b/src/system/configuration.ts @@ -7,7 +7,7 @@ import { areEqual } from './object'; interface ConfigurationOverrides { get(section: T, value: ConfigPathValue): ConfigPathValue; getAll(config: Config): Config; - onChange(e: ConfigurationChangeEvent): ConfigurationChangeEvent; + onDidChange(e: ConfigurationChangeEvent): ConfigurationChangeEvent; } export class Configuration { @@ -23,30 +23,29 @@ export class Configuration { return this._onDidChange.event; } - private _onDidChangeAny = new EventEmitter(); - get onDidChangeAny(): Event { - return this._onDidChangeAny.event; + private _onDidChangeBeforeOverrides = new EventEmitter(); + get onDidChangeBeforeOverrides(): Event { + return this._onDidChangeBeforeOverrides.event; } - private _onWillChange = new EventEmitter(); - get onWillChange(): Event { - return this._onWillChange.event; + private _onDidChangeOther = new EventEmitter(); + get onDidChangeOther(): Event { + return this._onDidChangeOther.event; } private onConfigurationChanged(e: ConfigurationChangeEvent) { if (!e.affectsConfiguration(configPrefix)) { - this._onDidChangeAny.fire(e); + this._onDidChangeOther.fire(e); return; } - this._onWillChange.fire(e); + this._onDidChangeBeforeOverrides.fire(e); - if (this._overrides?.onChange != null) { - e = this._overrides.onChange(e); + if (this._overrides?.onDidChange != null) { + e = this._overrides.onDidChange(e); } - this._onDidChangeAny.fire(e); this._onDidChange.fire(e); } @@ -75,12 +74,13 @@ export class Configuration { section: T, scope?: ConfigurationScope | null, defaultValue?: NonNullable>, + skipOverrides?: boolean, ): ConfigPathValue { const value = defaultValue === undefined ? workspace.getConfiguration(configPrefix, scope).get>(section)! : workspace.getConfiguration(configPrefix, scope).get>(section, defaultValue)!; - return this._overrides?.get == null ? value : this._overrides.get(section, value); + return skipOverrides || this._overrides?.get == null ? value : this._overrides.get(section, value); } getAll(skipOverrides?: boolean): Config { diff --git a/src/webviews/commitDetails/commitDetailsWebview.ts b/src/webviews/commitDetails/commitDetailsWebview.ts index fbfb825..1bc686a 100644 --- a/src/webviews/commitDetails/commitDetailsWebview.ts +++ b/src/webviews/commitDetails/commitDetailsWebview.ts @@ -123,7 +123,7 @@ export class CommitDetailsWebviewProvider implements WebviewProvider implements WebviewPro ) { this._disposable = Disposable.from( configuration.onDidChange(this.onConfigurationChanged, this), - configuration.onDidChangeAny(this.onAnyConfigurationChanged, this), + configuration.onDidChangeOther(this.onOtherConfigurationChanged, this), ); } @@ -172,7 +172,7 @@ export abstract class WebviewProviderWithConfigBase implements WebviewPro } } - private onAnyConfigurationChanged(e: ConfigurationChangeEvent) { + private onOtherConfigurationChanged(e: ConfigurationChangeEvent) { let notify = false; for (const setting of this.customSettings.values()) { if (e.affectsConfiguration(setting.name)) {