From ad8f85639e8879fa6e173002c13343051953c4c4 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Mon, 27 Mar 2023 11:48:17 -0400 Subject: [PATCH] Fixes missing configuration events - Renames `onDidChangeOther` to `onDidChangeAny` for accuracy - Removes `onDidChangeBeforeOverrides` as its unneeded (use `onDidChangeAny` instead) Consolidates to `onDidChangeAny` where possible --- src/container.ts | 24 +++++++------ src/plus/github/github.ts | 28 +++++++--------- src/plus/gitlab/gitlab.ts | 34 +++++++++---------- src/system/configuration.ts | 20 +++-------- src/webviews/commitDetails/commitDetailsWebview.ts | 39 ++++++++++------------ src/webviews/webviewWithConfigBase.ts | 26 ++++++--------- 6 files changed, 76 insertions(+), 95 deletions(-) diff --git a/src/container.ts b/src/container.ts index 1b11814..96b00bd 100644 --- a/src/container.ts +++ b/src/container.ts @@ -10,7 +10,7 @@ import { GitCodeLensController } from './codelens/codeLensController'; import type { ToggleFileAnnotationCommandArgs } from './commands'; import type { FileAnnotationType, ModeConfig } from './config'; import { AnnotationsToggleMode, DateSource, DateStyle, fromOutputLevel } from './config'; -import { Commands } from './constants'; +import { Commands, extensionPrefix } from './constants'; import { EventBus } from './eventBus'; import { GitFileSystemProvider } from './git/fsProvider'; import { GitProviderService } from './git/gitProviderService'; @@ -178,9 +178,7 @@ export class Container { context.subscriptions.unshift((this._telemetry = new TelemetryService(this))); context.subscriptions.unshift((this._usage = new UsageTracker(this, storage))); - context.subscriptions.unshift( - configuration.onDidChangeBeforeOverrides(this.onConfigurationChangedBeforeOverrides, this), - ); + context.subscriptions.unshift(configuration.onDidChangeAny(this.onAnyConfigurationChanged, this)); this._richRemoteProviders = new RichRemoteProviderService(this); @@ -292,7 +290,9 @@ export class Container { this._git.registrationComplete(); } - private onConfigurationChangedBeforeOverrides(e: ConfigurationChangeEvent) { + private onAnyConfigurationChanged(e: ConfigurationChangeEvent) { + if (!configuration.changedAny(e, extensionPrefix)) return; + this._mode = undefined; if (configuration.changed(e, 'outputLevel')) { @@ -710,11 +710,15 @@ export class Container { if (!configuration.changed(e, ['mode', 'modes'])) return e; 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; + return { + ...e, + affectsConfiguration: (section, scope) => + /^gitlens\\.(?:modes?|blame|changes|heatmap|codeLens|currentLine|hovers|statusBar)\\b/.test( + section, + ) + ? true + : originalAffectsConfiguration(section, scope), + }; }, }); } diff --git a/src/plus/github/github.ts b/src/plus/github/github.ts index 3d685ee..05f27ad 100644 --- a/src/plus/github/github.ts +++ b/src/plus/github/github.ts @@ -3,8 +3,8 @@ import { GraphqlResponseError } from '@octokit/graphql'; import { RequestError } from '@octokit/request-error'; import type { Endpoints, OctokitResponse, RequestParameters } from '@octokit/types'; import type { HttpsProxyAgent } from 'https-proxy-agent'; -import type { Event } from 'vscode'; -import { Disposable, EventEmitter, Uri, window } from 'vscode'; +import type { Disposable, Event } from 'vscode'; +import { EventEmitter, Uri, window } from 'vscode'; import { fetch, getProxyAgent, wrapForForcedInsecureSSL } from '@env/fetch'; import { isWeb } from '@env/platform'; import type { CoreConfiguration } from '../../constants'; @@ -187,25 +187,21 @@ export class GitHubApi implements Disposable { return this._onDidReauthenticate.event; } - private _disposable: Disposable | undefined; + private readonly _disposable: Disposable; constructor(_container: Container) { - this._disposable = Disposable.from( - configuration.onDidChange(e => { - if (configuration.changed(e, 'proxy') || configuration.changed(e, 'outputLevel')) { - this.resetCaches(); - } - }), - configuration.onDidChangeOther(e => { - if (configuration.changedAny(e, ['http.proxy', 'http.proxyStrictSSL'])) { - this.resetCaches(); - } - }), - ); + this._disposable = configuration.onDidChangeAny(e => { + if ( + configuration.changedAny(e, ['http.proxy', 'http.proxyStrictSSL']) || + configuration.changed(e, ['outputLevel', 'proxy']) + ) { + this.resetCaches(); + } + }); } dispose(): void { - this._disposable?.dispose(); + this._disposable.dispose(); } private resetCaches(): void { diff --git a/src/plus/gitlab/gitlab.ts b/src/plus/gitlab/gitlab.ts index 9c75cf5..a5d0cc9 100644 --- a/src/plus/gitlab/gitlab.ts +++ b/src/plus/gitlab/gitlab.ts @@ -1,5 +1,6 @@ import type { HttpsProxyAgent } from 'https-proxy-agent'; -import { Disposable, Uri, window } from 'vscode'; +import type { Disposable } from 'vscode'; +import { Uri, window } from 'vscode'; import type { RequestInit, Response } from '@env/fetch'; import { fetch, getProxyAgent, wrapForForcedInsecureSSL } from '@env/fetch'; import { isWeb } from '@env/platform'; @@ -35,28 +36,27 @@ import type { GitLabCommit, GitLabIssue, GitLabMergeRequest, GitLabMergeRequestR import { fromGitLabMergeRequestREST, fromGitLabMergeRequestState, GitLabMergeRequestState } from './models'; export class GitLabApi implements Disposable { - private _disposable: Disposable | undefined; + private readonly _disposable: Disposable; private _projectIds = new Map>(); constructor(_container: Container) { - this._disposable = Disposable.from( - configuration.onDidChange(e => { - if (configuration.changed(e, 'proxy') || configuration.changed(e, 'remotes')) { - this._projectIds.clear(); - this._proxyAgents.clear(); - } - }), - configuration.onDidChangeOther(e => { - if (configuration.changedAny(e, ['http.proxy', 'http.proxyStrictSSL'])) { - this._projectIds.clear(); - this._proxyAgents.clear(); - } - }), - ); + this._disposable = configuration.onDidChangeAny(e => { + if ( + configuration.changedAny(e, ['http.proxy', 'http.proxyStrictSSL']) || + configuration.changed(e, ['proxy', 'remotes']) + ) { + this.resetCaches(); + } + }); } dispose(): void { - this._disposable?.dispose(); + this._disposable.dispose(); + } + + private resetCaches(): void { + this._projectIds.clear(); + this._proxyAgents.clear(); } private _proxyAgents = new Map(); diff --git a/src/system/configuration.ts b/src/system/configuration.ts index 5584015..8965adc 100644 --- a/src/system/configuration.ts +++ b/src/system/configuration.ts @@ -23,24 +23,14 @@ export class Configuration { return this._onDidChange.event; } - private _onDidChangeBeforeOverrides = new EventEmitter(); - get onDidChangeBeforeOverrides(): Event { - return this._onDidChangeBeforeOverrides.event; - } - - private _onDidChangeOther = new EventEmitter(); - get onDidChangeOther(): Event { - return this._onDidChangeOther.event; + private _onDidChangeAny = new EventEmitter(); + get onDidChangeAny(): Event { + return this._onDidChangeAny.event; } private onConfigurationChanged(e: ConfigurationChangeEvent) { - if (!e.affectsConfiguration(extensionPrefix)) { - this._onDidChangeOther.fire(e); - - return; - } - - this._onDidChangeBeforeOverrides.fire(e); + this._onDidChangeAny.fire(e); + if (!e.affectsConfiguration(extensionPrefix)) return; if (this._overrides?.onDidChange != null) { e = this._overrides.onDidChange(e); diff --git a/src/webviews/commitDetails/commitDetailsWebview.ts b/src/webviews/commitDetails/commitDetailsWebview.ts index af856ce..e349c25 100644 --- a/src/webviews/commitDetails/commitDetailsWebview.ts +++ b/src/webviews/commitDetails/commitDetailsWebview.ts @@ -123,10 +123,7 @@ export class CommitDetailsWebviewProvider implements WebviewProvider(e, 'workbench.tree.indent')) { - // this.updatePendingContext({ indent: configuration.getAny('workbench.tree.indent') ?? 8 }); - // this.updateState(); - // } - - if (configuration.changedAny(e, 'workbench.tree.renderIndentGuides')) { - this.updatePendingContext({ - indentGuides: - configuration.getAny( - 'workbench.tree.renderIndentGuides', - ) ?? 'onHover', - }); - this.updateState(); - } - } - - private onConfigurationChanged(e: ConfigurationChangeEvent) { + private onAnyConfigurationChanged(e: ConfigurationChangeEvent) { if (configuration.changed(e, 'defaultDateFormat')) { this.updatePendingContext({ dateFormat: configuration.get('defaultDateFormat') ?? 'MMMM Do, YYYY h:mma' }); this.updateState(); @@ -252,6 +232,21 @@ export class CommitDetailsWebviewProvider implements WebviewProvider(e, 'workbench.tree.indent')) { + // this.updatePendingContext({ indent: configuration.getAny('workbench.tree.indent') ?? 8 }); + // this.updateState(); + // } + + if (configuration.changedAny(e, 'workbench.tree.renderIndentGuides')) { + this.updatePendingContext({ + indentGuides: + configuration.getAny( + 'workbench.tree.renderIndentGuides', + ) ?? 'onHover', + }); + this.updateState(); + } } private _commitTrackerDisposable: Disposable | undefined; diff --git a/src/webviews/webviewWithConfigBase.ts b/src/webviews/webviewWithConfigBase.ts index e602b1e..ee163ec 100644 --- a/src/webviews/webviewWithConfigBase.ts +++ b/src/webviews/webviewWithConfigBase.ts @@ -1,6 +1,7 @@ -import type { ConfigurationChangeEvent } from 'vscode'; -import { ConfigurationTarget, Disposable } from 'vscode'; +import type { ConfigurationChangeEvent, Disposable } from 'vscode'; +import { ConfigurationTarget } from 'vscode'; import type { CoreConfiguration, WebviewIds, WebviewViewIds } from '../constants'; +import { extensionPrefix } from '../constants'; import type { Container } from '../container'; import { CommitFormatter } from '../git/formatters/commitFormatter'; import { GitCommit, GitCommitIdentity } from '../git/models/commit'; @@ -29,10 +30,7 @@ export abstract class WebviewProviderWithConfigBase implements WebviewPro readonly id: `gitlens.${WebviewIds}` | `gitlens.views.${WebviewViewIds}`, readonly host: WebviewController, ) { - this._disposable = Disposable.from( - configuration.onDidChange(this.onConfigurationChanged, this), - configuration.onDidChangeOther(this.onOtherConfigurationChanged, this), - ); + this._disposable = configuration.onDidChangeAny(this.onAnyConfigurationChanged, this); } dispose() { @@ -174,16 +172,14 @@ export abstract class WebviewProviderWithConfigBase implements WebviewPro } } - private onOtherConfigurationChanged(e: ConfigurationChangeEvent) { - const notify = configuration.changedAny(e, [ - ...map(this.customSettings.values(), s => s.name), - ]); - if (!notify) return; - - void this.notifyDidChangeConfiguration(); - } + private onAnyConfigurationChanged(e: ConfigurationChangeEvent) { + if (!configuration.changedAny(e, extensionPrefix)) { + const notify = configuration.changedAny(e, [ + ...map(this.customSettings.values(), s => s.name), + ]); + if (!notify) return; + } - private onConfigurationChanged(_e: ConfigurationChangeEvent) { void this.notifyDidChangeConfiguration(); }