Procházet zdrojové kódy

Fixes missing configuration events

- Renames `onDidChangeOther` to `onDidChangeAny` for accuracy
 - Removes `onDidChangeBeforeOverrides` as its unneeded (use `onDidChangeAny` instead)
Consolidates to `onDidChangeAny` where possible
main
Eric Amodio před 1 rokem
rodič
revize
ad8f85639e
6 změnil soubory, kde provedl 76 přidání a 95 odebrání
  1. +14
    -10
      src/container.ts
  2. +12
    -16
      src/plus/github/github.ts
  3. +17
    -17
      src/plus/gitlab/gitlab.ts
  4. +5
    -15
      src/system/configuration.ts
  5. +17
    -22
      src/webviews/commitDetails/commitDetailsWebview.ts
  6. +11
    -15
      src/webviews/webviewWithConfigBase.ts

+ 14
- 10
src/container.ts Zobrazit soubor

@ -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),
};
},
});
}

+ 12
- 16
src/plus/github/github.ts Zobrazit soubor

@ -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<CoreConfiguration>(e, ['http.proxy', 'http.proxyStrictSSL'])) {
this.resetCaches();
}
}),
);
this._disposable = configuration.onDidChangeAny(e => {
if (
configuration.changedAny<CoreConfiguration>(e, ['http.proxy', 'http.proxyStrictSSL']) ||
configuration.changed(e, ['outputLevel', 'proxy'])
) {
this.resetCaches();
}
});
}
dispose(): void {
this._disposable?.dispose();
this._disposable.dispose();
}
private resetCaches(): void {

+ 17
- 17
src/plus/gitlab/gitlab.ts Zobrazit soubor

@ -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<string, Promise<string | undefined>>();
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<CoreConfiguration>(e, ['http.proxy', 'http.proxyStrictSSL'])) {
this._projectIds.clear();
this._proxyAgents.clear();
}
}),
);
this._disposable = configuration.onDidChangeAny(e => {
if (
configuration.changedAny<CoreConfiguration>(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<string, HttpsProxyAgent | null | undefined>();

+ 5
- 15
src/system/configuration.ts Zobrazit soubor

@ -23,24 +23,14 @@ export class Configuration {
return this._onDidChange.event;
}
private _onDidChangeBeforeOverrides = new EventEmitter<ConfigurationChangeEvent>();
get onDidChangeBeforeOverrides(): Event<ConfigurationChangeEvent> {
return this._onDidChangeBeforeOverrides.event;
}
private _onDidChangeOther = new EventEmitter<ConfigurationChangeEvent>();
get onDidChangeOther(): Event<ConfigurationChangeEvent> {
return this._onDidChangeOther.event;
private _onDidChangeAny = new EventEmitter<ConfigurationChangeEvent>();
get onDidChangeAny(): Event<ConfigurationChangeEvent> {
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);

+ 17
- 22
src/webviews/commitDetails/commitDetailsWebview.ts Zobrazit soubor

@ -123,10 +123,7 @@ export class CommitDetailsWebviewProvider implements WebviewProvider
},
};
this._disposable = Disposable.from(
configuration.onDidChange(this.onConfigurationChanged, this),
configuration.onDidChangeOther(this.onOtherConfigurationChanged, this),
);
this._disposable = configuration.onDidChangeAny(this.onAnyConfigurationChanged, this);
}
dispose() {
@ -204,24 +201,7 @@ export class CommitDetailsWebviewProvider implements WebviewProvider
this.updateState(true);
}
private onOtherConfigurationChanged(e: ConfigurationChangeEvent) {
// if (configuration.changedAny<CoreConfiguration>(e, 'workbench.tree.indent')) {
// this.updatePendingContext({ indent: configuration.getAny('workbench.tree.indent') ?? 8 });
// this.updateState();
// }
if (configuration.changedAny<CoreConfiguration>(e, 'workbench.tree.renderIndentGuides')) {
this.updatePendingContext({
indentGuides:
configuration.getAny<CoreConfiguration, Context['indentGuides']>(
'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
this.updateState();
}
// if (configuration.changedAny<CoreConfiguration>(e, 'workbench.tree.indent')) {
// this.updatePendingContext({ indent: configuration.getAny('workbench.tree.indent') ?? 8 });
// this.updateState();
// }
if (configuration.changedAny<CoreConfiguration>(e, 'workbench.tree.renderIndentGuides')) {
this.updatePendingContext({
indentGuides:
configuration.getAny<CoreConfiguration, Context['indentGuides']>(
'workbench.tree.renderIndentGuides',
) ?? 'onHover',
});
this.updateState();
}
}
private _commitTrackerDisposable: Disposable | undefined;

+ 11
- 15
src/webviews/webviewWithConfigBase.ts Zobrazit soubor

@ -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<State>,
) {
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<CustomSetting['name']>(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<CustomSetting['name']>(e, [
...map(this.customSettings.values(), s => s.name),
]);
if (!notify) return;
}
private onConfigurationChanged(_e: ConfigurationChangeEvent) {
void this.notifyDidChangeConfiguration();
}

Načítá se…
Zrušit
Uložit