diff --git a/src/annotations/autolinks.ts b/src/annotations/autolinks.ts index 9e906a8..1055e6c 100644 --- a/src/annotations/autolinks.ts +++ b/src/annotations/autolinks.ts @@ -34,14 +34,14 @@ export class Autolinks implements Disposable { constructor() { this._disposable = Disposable.from(configuration.onDidChange(this.onConfigurationChanged, this)); - this.onConfigurationChanged(configuration.initializingChangeEvent); + this.onConfigurationChanged(); } dispose() { this._disposable?.dispose(); } - private onConfigurationChanged(e: ConfigurationChangeEvent) { + private onConfigurationChanged(e?: ConfigurationChangeEvent) { if (configuration.changed(e, 'autolinks')) { this._references = Container.config.autolinks ?? []; } diff --git a/src/annotations/fileAnnotationController.ts b/src/annotations/fileAnnotationController.ts index 7256887..503daf5 100644 --- a/src/annotations/fileAnnotationController.ts +++ b/src/annotations/fileAnnotationController.ts @@ -83,7 +83,7 @@ export class FileAnnotationController implements Disposable { this._disposable = Disposable.from(configuration.onDidChange(this.onConfigurationChanged, this)); this._toggleModes = new Map(); - this.onConfigurationChanged(configuration.initializingChangeEvent); + this.onConfigurationChanged(); } dispose() { @@ -99,7 +99,7 @@ export class FileAnnotationController implements Disposable { this._disposable?.dispose(); } - private onConfigurationChanged(e: ConfigurationChangeEvent) { + private onConfigurationChanged(e?: ConfigurationChangeEvent) { const cfg = Container.config; if (configuration.changed(e, 'blame.highlight')) { @@ -189,7 +189,7 @@ export class FileAnnotationController implements Disposable { }); } - const initializing = configuration.initializing(e); + const initializing = e == null; if (configuration.changed(e, 'blame.toggleMode')) { this._toggleModes.set(FileAnnotationType.Blame, cfg.blame.toggleMode); diff --git a/src/annotations/lineAnnotationController.ts b/src/annotations/lineAnnotationController.ts index 0be87a2..c6387e4 100644 --- a/src/annotations/lineAnnotationController.ts +++ b/src/annotations/lineAnnotationController.ts @@ -40,7 +40,7 @@ export class LineAnnotationController implements Disposable { Container.fileAnnotations.onDidToggleAnnotations(this.onFileAnnotationsToggled, this), Authentication.onDidChange(() => void this.refresh(window.activeTextEditor)), ); - this.onConfigurationChanged(configuration.initializingChangeEvent); + this.onConfigurationChanged(); } dispose() { @@ -50,7 +50,7 @@ export class LineAnnotationController implements Disposable { this._disposable.dispose(); } - private onConfigurationChanged(e: ConfigurationChangeEvent) { + private onConfigurationChanged(e?: ConfigurationChangeEvent) { if (!configuration.changed(e, 'currentLine')) return; if (configuration.changed(e, 'currentLine.enabled')) { diff --git a/src/codelens/codeLensController.ts b/src/codelens/codeLensController.ts index 7805a76..339a4aa 100644 --- a/src/codelens/codeLensController.ts +++ b/src/codelens/codeLensController.ts @@ -19,7 +19,7 @@ export class GitCodeLensController implements Disposable { constructor() { this._disposable = Disposable.from(configuration.onDidChange(this.onConfigurationChanged, this)); - this.onConfigurationChanged(configuration.initializingChangeEvent); + this.onConfigurationChanged(); } dispose() { @@ -27,14 +27,14 @@ export class GitCodeLensController implements Disposable { this._disposable?.dispose(); } - private onConfigurationChanged(e: ConfigurationChangeEvent) { + private onConfigurationChanged(e?: ConfigurationChangeEvent) { if ( configuration.changed(e, 'codeLens') || configuration.changed(e, 'defaultDateFormat') || configuration.changed(e, 'defaultDateSource') || configuration.changed(e, 'defaultDateStyle') ) { - if (!configuration.initializing(e)) { + if (e != null) { Logger.log('CodeLens config changed; resetting CodeLens provider'); } diff --git a/src/configuration.ts b/src/configuration.ts index b533cac..e290a80 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -13,15 +13,7 @@ import { import { Config } from './config'; import { Objects } from './system'; -const extensionId = 'gitlens'; - -type ConfigInspection = { - key: string; - defaultValue?: T; - globalValue?: T; - workspaceValue?: T; - workspaceFolderValue?: T; -}; +const configPrefix = 'gitlens'; export interface ConfigurationWillChangeEvent { change: ConfigurationChangeEvent; @@ -29,7 +21,7 @@ export interface ConfigurationWillChangeEvent { } export class Configuration { - static configure(context: ExtensionContext) { + static configure(context: ExtensionContext): void { context.subscriptions.push( workspace.onDidChangeConfiguration(configuration.onConfigurationChanged, configuration), ); @@ -51,7 +43,7 @@ export class Configuration { } private onConfigurationChanged(e: ConfigurationChangeEvent) { - if (!e.affectsConfiguration(extensionId)) { + if (!e.affectsConfiguration(configPrefix)) { this._onDidChangeAny.fire(e); return; @@ -70,8 +62,6 @@ export class Configuration { this._onDidChange.fire(e); } - readonly initializingChangeEvent: ConfigurationChangeEvent = { affectsConfiguration: () => true }; - get(): Config; get( section: T, @@ -85,40 +75,33 @@ export class Configuration { ): Config | ConfigPathValue { return defaultValue === undefined ? workspace - .getConfiguration(section === undefined ? undefined : extensionId, scope) - .get>(section === undefined ? extensionId : section)! + .getConfiguration(section === undefined ? undefined : configPrefix, scope) + .get>(section === undefined ? configPrefix : section)! : workspace - .getConfiguration(section === undefined ? undefined : extensionId, scope) - .get>(section === undefined ? extensionId : section, defaultValue)!; + .getConfiguration(section === undefined ? undefined : configPrefix, scope) + .get>(section === undefined ? configPrefix : section, defaultValue)!; } getAny(section: string, scope?: ConfigurationScope | null): T | undefined; getAny(section: string, scope: ConfigurationScope | null | undefined, defaultValue: T): T; - getAny(section: string, scope?: ConfigurationScope | null, defaultValue?: T) { + getAny(section: string, scope?: ConfigurationScope | null, defaultValue?: T): T | undefined { return defaultValue === undefined ? workspace.getConfiguration(undefined, scope).get(section) : workspace.getConfiguration(undefined, scope).get(section, defaultValue); } changed( - e: ConfigurationChangeEvent, + e: ConfigurationChangeEvent | undefined, section: T, scope?: ConfigurationScope | null | undefined, ): boolean { - return e.affectsConfiguration(`${extensionId}.${section}`, scope!); + return e?.affectsConfiguration(`${configPrefix}.${section}`, scope!) ?? true; } - initializing(e: ConfigurationChangeEvent) { - return e === this.initializingChangeEvent; - } - - inspect( - section: T, - scope?: ConfigurationScope | null, - ): ConfigInspection> | undefined { + inspect>(section: T, scope?: ConfigurationScope | null) { return workspace - .getConfiguration(section === undefined ? undefined : extensionId, scope) - .inspect(section === undefined ? extensionId : section); + .getConfiguration(section === undefined ? undefined : configPrefix, scope) + .inspect(section === undefined ? configPrefix : section); } inspectAny(section: string, scope?: ConfigurationScope | null) { @@ -270,10 +253,15 @@ export class Configuration { value: ConfigPathValue | undefined, target: ConfigurationTarget, ): Thenable { - return workspace.getConfiguration(extensionId).update(section, value, target); + return workspace.getConfiguration(configPrefix).update(section, value, target); } - updateAny(section: string, value: any, target: ConfigurationTarget, scope?: ConfigurationScope | null) { + updateAny( + section: string, + value: any, + target: ConfigurationTarget, + scope?: ConfigurationScope | null, + ): Thenable { return workspace .getConfiguration(undefined, target === ConfigurationTarget.Global ? undefined : scope!) .update(section, value, target); @@ -307,17 +295,15 @@ export class Configuration { export const configuration = new Configuration(); -type PathImpl = Key extends string +type SubPath = Key extends string ? T[Key] extends Record ? - | `${Key}.${PathImpl> & string}` + | `${Key}.${SubPath> & string}` | `${Key}.${Exclude & string}` : never : never; -type PathImpl2 = PathImpl | keyof T; - -type Path = PathImpl2 extends string | keyof T ? PathImpl2 : keyof T; +type Path = SubPath | keyof T extends string | keyof T ? SubPath | keyof T : keyof T; type PathValue> = P extends `${infer Key}.${infer Rest}` ? Key extends keyof T diff --git a/src/git/gitService.ts b/src/git/gitService.ts index bfefbb7..02cafc5 100644 --- a/src/git/gitService.ts +++ b/src/git/gitService.ts @@ -162,7 +162,7 @@ export class GitService implements Disposable { void this.updateContext(this._repositoryTree); }), ); - this.onConfigurationChanged(configuration.initializingChangeEvent); + this.onConfigurationChanged(); this._repositoriesLoadingPromise = this.onWorkspaceFoldersChanged(); } @@ -237,7 +237,7 @@ export class GitService implements Disposable { } } - private onConfigurationChanged(e: ConfigurationChangeEvent) { + private onConfigurationChanged(e?: ConfigurationChangeEvent) { if ( configuration.changed(e, 'defaultDateFormat') || configuration.changed(e, 'defaultDateSource') || diff --git a/src/git/models/repository.ts b/src/git/models/repository.ts index c72adee..6c462c0 100644 --- a/src/git/models/repository.ts +++ b/src/git/models/repository.ts @@ -265,7 +265,7 @@ export class Repository implements Disposable { watcher.onDidDelete(this.onRepositoryChanged, this), configuration.onDidChange(this.onConfigurationChanged, this), ); - this.onConfigurationChanged(configuration.initializingChangeEvent); + this.onConfigurationChanged(); if (!this.supportsChangeEvents) { void this.tryWatchingForChangesViaBuiltInApi(); @@ -307,11 +307,11 @@ export class Repository implements Disposable { return this._updatedAt; } - private onConfigurationChanged(e: ConfigurationChangeEvent) { + private onConfigurationChanged(e?: ConfigurationChangeEvent) { if (configuration.changed(e, 'remotes', this.folder.uri)) { this._providers = RemoteProviderFactory.loadProviders(configuration.get('remotes', this.folder.uri)); - if (!configuration.initializing(e)) { + if (e != null) { this.resetCaches('remotes'); this.fireChange(RepositoryChange.Remotes); } diff --git a/src/hovers/lineHoverController.ts b/src/hovers/lineHoverController.ts index 6f3f1d6..4afdd6a 100644 --- a/src/hovers/lineHoverController.ts +++ b/src/hovers/lineHoverController.ts @@ -26,7 +26,7 @@ export class LineHoverController implements Disposable { constructor() { this._disposable = Disposable.from(configuration.onDidChange(this.onConfigurationChanged, this)); - this.onConfigurationChanged(configuration.initializingChangeEvent); + this.onConfigurationChanged(); } dispose() { @@ -36,7 +36,7 @@ export class LineHoverController implements Disposable { this._disposable.dispose(); } - private onConfigurationChanged(e: ConfigurationChangeEvent) { + private onConfigurationChanged(e?: ConfigurationChangeEvent) { if (!configuration.changed(e, 'hovers.enabled') && !configuration.changed(e, 'hovers.currentLine.enabled')) { return; } diff --git a/src/statusbar/statusBarController.ts b/src/statusbar/statusBarController.ts index 5d59d93..06d3793 100644 --- a/src/statusbar/statusBarController.ts +++ b/src/statusbar/statusBarController.ts @@ -27,7 +27,7 @@ export class StatusBarController implements Disposable { constructor() { this._disposable = Disposable.from(configuration.onDidChange(this.onConfigurationChanged, this)); - this.onConfigurationChanged(configuration.initializingChangeEvent); + this.onConfigurationChanged(); } dispose() { @@ -40,7 +40,7 @@ export class StatusBarController implements Disposable { this._disposable.dispose(); } - private onConfigurationChanged(e: ConfigurationChangeEvent) { + private onConfigurationChanged(e?: ConfigurationChangeEvent) { if (configuration.changed(e, 'mode')) { const mode = Container.config.mode.active && Container.config.mode.statusBar.enabled diff --git a/src/trackers/documentTracker.ts b/src/trackers/documentTracker.ts index 6cdca8c..7254f0b 100644 --- a/src/trackers/documentTracker.ts +++ b/src/trackers/documentTracker.ts @@ -76,7 +76,7 @@ export class DocumentTracker implements Disposable { workspace.onDidSaveTextDocument(this.onTextDocumentSaved, this), ); - void this.onConfigurationChanged(configuration.initializingChangeEvent); + void this.onConfigurationChanged(); } dispose() { @@ -89,10 +89,10 @@ export class DocumentTracker implements Disposable { void this.onActiveTextEditorChanged(window.activeTextEditor); } - private async onConfigurationChanged(e: ConfigurationChangeEvent) { + private async onConfigurationChanged(e?: ConfigurationChangeEvent) { // Only rest the cached state if we aren't initializing if ( - !configuration.initializing(e) && + e != null && (configuration.changed(e, 'blame.ignoreWhitespace') || configuration.changed(e, 'advanced.caching.enabled')) ) { for (const d of this._documentMap.values()) { diff --git a/src/views/viewBase.ts b/src/views/viewBase.ts index a25369f..378f770 100644 --- a/src/views/viewBase.ts +++ b/src/views/viewBase.ts @@ -149,7 +149,7 @@ export abstract class ViewBase< this.initialize({ showCollapseAll: this.showCollapseAll }); - setImmediate(() => this.onConfigurationChanged(configuration.initializingChangeEvent)); + setImmediate(() => this.onConfigurationChanged()); } protected get showCollapseAll(): boolean { @@ -210,8 +210,8 @@ export abstract class ViewBase< protected abstract getRoot(): RootNode; protected abstract registerCommands(): void; - protected onConfigurationChanged(e: ConfigurationChangeEvent): void { - if (!configuration.initializing(e) && this.root != null) { + protected onConfigurationChanged(e?: ConfigurationChangeEvent): void { + if (e != null && this.root != null) { void this.refresh(true); } }