Browse Source

Clarifies/refines configuration events & overrides

main
Eric Amodio 1 year ago
parent
commit
e71df65ccd
6 changed files with 30 additions and 42 deletions
  1. +11
    -23
      src/container.ts
  2. +1
    -1
      src/plus/github/github.ts
  3. +1
    -1
      src/plus/gitlab/gitlab.ts
  4. +13
    -13
      src/system/configuration.ts
  5. +2
    -2
      src/webviews/commitDetails/commitDetailsWebview.ts
  6. +2
    -2
      src/webviews/webviewWithConfigBase.ts

+ 11
- 23
src/container.ts View File

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

+ 1
- 1
src/plus/github/github.ts View File

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

+ 1
- 1
src/plus/gitlab/gitlab.ts View File

@ -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();

+ 13
- 13
src/system/configuration.ts View File

@ -7,7 +7,7 @@ import { areEqual } from './object';
interface ConfigurationOverrides {
get<T extends ConfigPath>(section: T, value: ConfigPathValue<T>): ConfigPathValue<T>;
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<ConfigurationChangeEvent>();
get onDidChangeAny(): Event<ConfigurationChangeEvent> {
return this._onDidChangeAny.event;
private _onDidChangeBeforeOverrides = new EventEmitter<ConfigurationChangeEvent>();
get onDidChangeBeforeOverrides(): Event<ConfigurationChangeEvent> {
return this._onDidChangeBeforeOverrides.event;
}
private _onWillChange = new EventEmitter<ConfigurationChangeEvent>();
get onWillChange(): Event<ConfigurationChangeEvent> {
return this._onWillChange.event;
private _onDidChangeOther = new EventEmitter<ConfigurationChangeEvent>();
get onDidChangeOther(): Event<ConfigurationChangeEvent> {
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<ConfigPathValue<T>>,
skipOverrides?: boolean,
): ConfigPathValue<T> {
const value =
defaultValue === undefined
? workspace.getConfiguration(configPrefix, scope).get<ConfigPathValue<T>>(section)!
: workspace.getConfiguration(configPrefix, scope).get<ConfigPathValue<T>>(section, defaultValue)!;
return this._overrides?.get == null ? value : this._overrides.get<T>(section, value);
return skipOverrides || this._overrides?.get == null ? value : this._overrides.get<T>(section, value);
}
getAll(skipOverrides?: boolean): Config {

+ 2
- 2
src/webviews/commitDetails/commitDetailsWebview.ts View File

@ -123,7 +123,7 @@ export class CommitDetailsWebviewProvider implements WebviewProvider
this._disposable = Disposable.from(
configuration.onDidChange(this.onConfigurationChanged, this),
configuration.onDidChangeAny(this.onAnyConfigurationChanged, this),
configuration.onDidChangeOther(this.onOtherConfigurationChanged, this),
);
}
@ -202,7 +202,7 @@ export class CommitDetailsWebviewProvider implements WebviewProvider
this.updateState(true);
}
private onAnyConfigurationChanged(e: ConfigurationChangeEvent) {
private onOtherConfigurationChanged(e: ConfigurationChangeEvent) {
// if (e.affectsConfiguration('workbench.tree.indent')) {
// this.updatePendingContext({ indent: configuration.getAny('workbench.tree.indent') ?? 8 });
// this.updateState();

+ 2
- 2
src/webviews/webviewWithConfigBase.ts View File

@ -29,7 +29,7 @@ export abstract class WebviewProviderWithConfigBase 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)) {

Loading…
Cancel
Save