diff --git a/src/annotations/fileAnnotationController.ts b/src/annotations/fileAnnotationController.ts index 3821cfe..e547ff0 100644 --- a/src/annotations/fileAnnotationController.ts +++ b/src/annotations/fileAnnotationController.ts @@ -94,7 +94,7 @@ export class FileAnnotationController implements Disposable { private onConfigurationChanged(e: ConfigurationChangeEvent) { const cfg = Container.config; - if (configuration.changed(e, configuration.name('blame')('highlight').value)) { + if (configuration.changed(e, 'blame', 'highlight')) { Decorations.blameHighlight && Decorations.blameHighlight.dispose(); const cfgHighlight = cfg.blame.highlight; @@ -126,7 +126,7 @@ export class FileAnnotationController implements Disposable { } } - if (configuration.changed(e, configuration.name('recentChanges')('highlight').value)) { + if (configuration.changed(e, 'recentChanges', 'highlight')) { Decorations.recentChangesAnnotation && Decorations.recentChangesAnnotation.dispose(); const cfgHighlight = cfg.recentChanges.highlight; @@ -156,21 +156,21 @@ export class FileAnnotationController implements Disposable { const initializing = configuration.initializing(e); - if (configuration.changed(e, configuration.name('blame')('toggleMode').value)) { + if (configuration.changed(e, 'blame', 'toggleMode')) { this._toggleModes.set(FileAnnotationType.Blame, cfg.blame.toggleMode); if (!initializing && cfg.blame.toggleMode === AnnotationsToggleMode.File) { void this.clearAll(); } } - if (configuration.changed(e, configuration.name('heatmap')('toggleMode').value)) { + if (configuration.changed(e, 'heatmap', 'toggleMode')) { this._toggleModes.set(FileAnnotationType.Heatmap, cfg.heatmap.toggleMode); if (!initializing && cfg.heatmap.toggleMode === AnnotationsToggleMode.File) { void this.clearAll(); } } - if (configuration.changed(e, configuration.name('recentChanges')('toggleMode').value)) { + if (configuration.changed(e, 'recentChanges', 'toggleMode')) { this._toggleModes.set(FileAnnotationType.RecentChanges, cfg.recentChanges.toggleMode); if (!initializing && cfg.recentChanges.toggleMode === AnnotationsToggleMode.File) { void this.clearAll(); @@ -180,10 +180,10 @@ export class FileAnnotationController implements Disposable { if (initializing) return; if ( - configuration.changed(e, configuration.name('blame').value) || - configuration.changed(e, configuration.name('recentChanges').value) || - configuration.changed(e, configuration.name('heatmap').value) || - configuration.changed(e, configuration.name('hovers').value) + configuration.changed(e, 'blame') || + configuration.changed(e, 'recentChanges') || + configuration.changed(e, 'heatmap') || + configuration.changed(e, 'hovers') ) { // Since the configuration has changed -- reset any visible annotations for (const provider of this._annotationProviders.values()) { diff --git a/src/annotations/lineAnnotationController.ts b/src/annotations/lineAnnotationController.ts index 2b2430d..a277b68 100644 --- a/src/annotations/lineAnnotationController.ts +++ b/src/annotations/lineAnnotationController.ts @@ -47,9 +47,9 @@ export class LineAnnotationController implements Disposable { } private onConfigurationChanged(e: ConfigurationChangeEvent) { - if (!configuration.changed(e, configuration.name('currentLine').value)) return; + if (!configuration.changed(e, 'currentLine')) return; - if (configuration.changed(e, configuration.name('currentLine')('enabled').value)) { + if (configuration.changed(e, 'currentLine', 'enabled')) { if (Container.config.currentLine.enabled) { this._enabled = true; this.resume(); diff --git a/src/codelens/codeLensController.ts b/src/codelens/codeLensController.ts index c87d6ea..f2680ed 100644 --- a/src/codelens/codeLensController.ts +++ b/src/codelens/codeLensController.ts @@ -28,12 +28,11 @@ export class GitCodeLensController implements Disposable { } private onConfigurationChanged(e: ConfigurationChangeEvent) { - const section = configuration.name('codeLens').value; if ( - configuration.changed(e, section, null) || - configuration.changed(e, configuration.name('defaultDateFormat').value) || - configuration.changed(e, configuration.name('defaultDateSource').value) || - configuration.changed(e, configuration.name('defaultDateStyle').value) + configuration.changed(e, 'codeLens', null) || + configuration.changed(e, 'defaultDateFormat') || + configuration.changed(e, 'defaultDateSource') || + configuration.changed(e, 'defaultDateStyle') ) { if (!configuration.initializing(e)) { Logger.log('CodeLens config changed; resetting CodeLens provider'); diff --git a/src/codelens/codeLensProvider.ts b/src/codelens/codeLensProvider.ts index 6a6bb6c..8ea4c2d 100644 --- a/src/codelens/codeLensProvider.ts +++ b/src/codelens/codeLensProvider.ts @@ -117,7 +117,7 @@ export class GitCodeLensProvider implements CodeLensProvider { } } - const cfg = configuration.get(configuration.name('codeLens').value, document.uri); + const cfg = configuration.get('codeLens', document.uri); let languageScope = cfg.scopesByLanguage && diff --git a/src/commands/gitCommands.ts b/src/commands/gitCommands.ts index 66e3dfd..32ced5d 100644 --- a/src/commands/gitCommands.ts +++ b/src/commands/gitCommands.ts @@ -157,7 +157,7 @@ export class GitCommandsCommand extends Command { private async showInputStep(step: QuickInputStep, commandsStep: PickCommandStep) { const input = window.createInputBox(); - input.ignoreFocusOut = !configuration.get(configuration.name('gitCommands')('closeOnFocusOut').value); + input.ignoreFocusOut = !configuration.get('gitCommands', 'closeOnFocusOut'); const disposables: Disposable[] = []; @@ -226,9 +226,7 @@ export class GitCommandsCommand extends Command { private async showPickStep(step: QuickPickStep, commandsStep: PickCommandStep) { const quickpick = window.createQuickPick(); - quickpick.ignoreFocusOut = !configuration.get( - configuration.name('gitCommands')('closeOnFocusOut').value - ); + quickpick.ignoreFocusOut = !configuration.get('gitCommands', 'closeOnFocusOut'); const disposables: Disposable[] = []; @@ -496,8 +494,7 @@ export class GitCommandsCommand extends Command { ) { if (command === undefined || command.skipConfirmKey === undefined) return; - const section = configuration.name('gitCommands')('skipConfirmations').value; - const skipConfirmations = configuration.get(section) || []; + const skipConfirmations = configuration.get('gitCommands', 'skipConfirmations') || []; const index = skipConfirmations.indexOf(command.skipConfirmKey); if (index !== -1) { @@ -506,10 +503,7 @@ export class GitCommandsCommand extends Command { skipConfirmations.push(command.skipConfirmKey); } - void (await configuration.updateEffective( - configuration.name('gitCommands')('skipConfirmations').value, - skipConfirmations - )); + void (await configuration.updateEffective('gitCommands', 'skipConfirmations', skipConfirmations)); input.buttons = this.getButtons(command.value, command); } diff --git a/src/commands/resetSuppressedWarnings.ts b/src/commands/resetSuppressedWarnings.ts index 3360ef8..bebf140 100644 --- a/src/commands/resetSuppressedWarnings.ts +++ b/src/commands/resetSuppressedWarnings.ts @@ -10,10 +10,6 @@ export class ResetSuppressedWarningsCommand extends Command { } async execute() { - await configuration.update( - configuration.name('advanced')('messages').value, - undefined, - ConfigurationTarget.Global - ); + await configuration.update('advanced', 'messages', undefined, ConfigurationTarget.Global); } } diff --git a/src/commands/switchMode.ts b/src/commands/switchMode.ts index 1f7d821..3ad068c 100644 --- a/src/commands/switchMode.ts +++ b/src/commands/switchMode.ts @@ -38,7 +38,7 @@ export class SwitchModeCommand extends Command { } } - await configuration.update(configuration.name('mode')('active').value, pick.key, ConfigurationTarget.Global); + await configuration.update('mode', 'active', pick.key, ConfigurationTarget.Global); } } @@ -53,7 +53,7 @@ export class ToggleReviewModeCommand extends Command { if (!Object.keys(Container.config.modes).includes('review')) return; const mode = Container.config.mode.active === 'review' ? undefined : 'review'; - await configuration.update(configuration.name('mode')('active').value, mode, ConfigurationTarget.Global); + await configuration.update('mode', 'active', mode, ConfigurationTarget.Global); } } @@ -68,6 +68,6 @@ export class ToggleZenModeCommand extends Command { if (!Object.keys(Container.config.modes).includes('zen')) return; const mode = Container.config.mode.active === 'zen' ? undefined : 'zen'; - await configuration.update(configuration.name('mode')('active').value, mode, ConfigurationTarget.Global); + await configuration.update('mode', 'active', mode, ConfigurationTarget.Global); } } diff --git a/src/configuration.ts b/src/configuration.ts index 727066b..b33e899 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -12,7 +12,7 @@ import { } from 'vscode'; import { Config } from './config'; import { extensionId } from './constants'; -import { Functions, Objects } from './system'; +import { Objects } from './system'; const emptyConfig: Config = new Proxy({} as Config, { get: function() { @@ -20,6 +20,14 @@ const emptyConfig: Config = new Proxy({} as Config, { } }); +type ConfigInspection = { + key: string; + defaultValue?: T; + globalValue?: T; + workspaceValue?: T; + workspaceFolderValue?: T; +}; + export interface ConfigurationWillChangeEvent { change: ConfigurationChangeEvent; transform?(e: ConfigurationChangeEvent): ConfigurationChangeEvent; @@ -70,7 +78,62 @@ export class Configuration { affectsConfiguration: (section: string, resource?: Uri) => true }; - get(section?: string, resource?: Uri | null, defaultValue?: T): T { + get(): Config; + get(s1: S1, resource?: Uri | null, defaultValue?: Config[S1]): Config[S1]; + get( + s1: S1, + s2: S2, + resource?: Uri | null, + defaultValue?: Config[S1][S2] + ): Config[S1][S2]; + get( + s1: S1, + s2: S2, + s3: S3, + resource?: Uri | null, + defaultValue?: Config[S1][S2][S3] + ): Config[S1][S2][S3]; + get< + S1 extends keyof Config, + S2 extends keyof Config[S1], + S3 extends keyof Config[S1][S2], + S4 extends keyof Config[S1][S2][S3] + >( + s1: S1, + s2: S2, + s3: S3, + s4: S4, + resource?: Uri | null, + defaultValue?: Config[S1][S2][S3][S4] + ): Config[S1][S2][S3][S4]; + get(...args: any[]): T { + let section: string | undefined; + let resource: Uri | null | undefined; + let defaultValue: T | undefined; + if (args.length > 0) { + section = args[0]; + if (typeof args[1] === 'string') { + section += `.${args[1]}`; + if (typeof args[2] === 'string') { + section += `.${args[2]}`; + if (typeof args[2] === 'string') { + section += `.${args[3]}`; + resource = args[4]; + defaultValue = args[5]; + } else { + resource = args[3]; + defaultValue = args[4]; + } + } else { + resource = args[2]; + defaultValue = args[3]; + } + } else { + resource = args[1]; + defaultValue = args[2]; + } + } + return defaultValue === undefined ? workspace .getConfiguration(section === undefined ? undefined : extensionId, resource) @@ -86,7 +149,46 @@ export class Configuration { : workspace.getConfiguration(undefined, resource).get(section, defaultValue)!; } - changed(e: ConfigurationChangeEvent, section: string, resource?: Uri | null) { + changed(e: ConfigurationChangeEvent, s1: S1, resource?: Uri | null): boolean; + changed( + e: ConfigurationChangeEvent, + s1: S1, + s2: S2, + resource?: Uri | null + ): boolean; + changed( + e: ConfigurationChangeEvent, + s1: S1, + s2: S2, + s3: S3, + resource?: Uri | null + ): boolean; + changed< + S1 extends keyof Config, + S2 extends keyof Config[S1], + S3 extends keyof Config[S1][S2], + S4 extends keyof Config[S1][S2][S3] + >(e: ConfigurationChangeEvent, s1: S1, s2: S2, s3: S3, s4: S4, resource?: Uri | null): boolean; + changed(e: ConfigurationChangeEvent, ...args: any[]) { + let section: string = args[0]; + let resource: Uri | null | undefined; + if (typeof args[1] === 'string') { + section += `.${args[1]}`; + if (typeof args[2] === 'string') { + section += `.${args[2]}`; + if (typeof args[3] === 'string') { + section += args[3]; + resource = args[4]; + } else { + resource = args[3]; + } + } else { + resource = args[2]; + } + } else { + resource = args[1]; + } + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion return e.affectsConfiguration(`${extensionId}.${section}`, resource!); } @@ -95,7 +197,44 @@ export class Configuration { return e === this.initializingChangeEvent; } - inspect(section?: string, resource?: Uri | null) { + inspect(s1: S1, resource?: Uri | null): ConfigInspection | undefined; + inspect( + s1: S1, + s2: S2, + resource?: Uri | null + ): ConfigInspection | undefined; + inspect( + s1: S1, + s2: S2, + s3: S3, + resource?: Uri | null + ): ConfigInspection | undefined; + inspect< + S1 extends keyof Config, + S2 extends keyof Config[S1], + S3 extends keyof Config[S1][S2], + S4 extends keyof Config[S1][S2][S3] + >(s1: S1, s2: S2, s3: S3, s4: S4, resource?: Uri | null): ConfigInspection | undefined; + inspect(...args: any[]) { + let section: string = args[0]; + let resource: Uri | null | undefined; + if (typeof args[1] === 'string') { + section += `.${args[1]}`; + if (typeof args[2] === 'string') { + section += `.${args[2]}`; + if (typeof args[3] === 'string') { + section += args[3]; + resource = args[4]; + } else { + resource = args[3]; + } + } else { + resource = args[2]; + } + } else { + resource = args[1]; + } + return workspace .getConfiguration(section === undefined ? undefined : extensionId, resource) .inspect(section === undefined ? extensionId : section); @@ -105,19 +244,69 @@ export class Configuration { return workspace.getConfiguration(undefined, resource).inspect(section); } - async migrate( + migrate( from: string, - to: string, - options: { fallbackValue?: TTo; migrationFn?(value: TFrom): TTo } = {} - ): Promise { - const inspection = configuration.inspect(from); + to1: S1, + options: { fallbackValue?: Config[S1]; migrationFn?(value: any): Config[S1] } + ): Promise; + migrate( + from: string, + to1: S1, + to2: S2, + options: { fallbackValue?: Config[S1][S2]; migrationFn?(value: any): Config[S1][S2] } + ): Promise; + migrate( + from: string, + to1: S1, + to2: S2, + to3: S3, + options: { fallbackValue?: Config[S1][S2][S3]; migrationFn?(value: any): Config[S1][S2][S3] } + ): Promise; + migrate< + S1 extends keyof Config, + S2 extends keyof Config[S1], + S3 extends keyof Config[S1][S2], + S4 extends keyof Config[S1][S2][S3] + >( + from: string, + to1: S1, + to2: S2, + to3: S3, + to4: S4, + options: { fallbackValue?: Config[S1][S2][S3][S4]; migrationFn?(value: any): Config[S1][S2][S3][S4] } + ): Promise; + async migrate(from: string, ...args: any[]): Promise { + let to: string = args[0]; + let options: { fallbackValue?: any; migrationFn?(value: any): any } | undefined; + if (typeof args[1] === 'string' && args.length > 3) { + to += `.${args[1]}`; + if (typeof args[2] === 'string' && args.length > 4) { + to += `.${args[2]}`; + if (typeof args[3] === 'string' && args.length > 5) { + to += `.${args[3]}`; + options = args[4]; + } else { + options = args[3]; + } + } else { + options = args[2]; + } + } else { + options = args[1]; + } + + if (options === undefined) { + options = {}; + } + + const inspection = configuration.inspect(from as any); if (inspection === undefined) return false; let migrated = false; if (inspection.globalValue !== undefined) { await this.update( - to, - options.migrationFn ? options.migrationFn(inspection.globalValue as TFrom) : inspection.globalValue, + to as any, + options.migrationFn ? options.migrationFn(inspection.globalValue) : inspection.globalValue, ConfigurationTarget.Global ); migrated = true; @@ -132,10 +321,8 @@ export class Configuration { if (inspection.workspaceValue !== undefined) { await this.update( - to, - options.migrationFn - ? options.migrationFn(inspection.workspaceValue as TFrom) - : inspection.workspaceValue, + to as any, + options.migrationFn ? options.migrationFn(inspection.workspaceValue) : inspection.workspaceValue, ConfigurationTarget.Workspace ); migrated = true; @@ -150,9 +337,9 @@ export class Configuration { if (inspection.workspaceFolderValue !== undefined) { await this.update( - to, + to as any, options.migrationFn - ? options.migrationFn(inspection.workspaceFolderValue as TFrom) + ? options.migrationFn(inspection.workspaceFolderValue) : inspection.workspaceFolderValue, ConfigurationTarget.WorkspaceFolder ); @@ -167,25 +354,78 @@ export class Configuration { } if (!migrated && options.fallbackValue !== undefined) { - await this.update(to, options.fallbackValue, ConfigurationTarget.Global); + await this.update(to as any, options.fallbackValue, ConfigurationTarget.Global); migrated = true; } return migrated; } - async migrateIfMissing(from: string, to: string, options: { migrationFn?(value: TFrom): TTo } = {}) { - const fromInspection = configuration.inspect(from); + migrateIfMissing( + from: string, + to1: S1, + options: { migrationFn?(value: any): Config[S1] } + ): Promise; + migrateIfMissing( + from: string, + to1: S1, + to2: S2, + options: { migrationFn?(value: any): Config[S1][S2] } + ): Promise; + migrateIfMissing( + from: string, + to1: S1, + to2: S2, + to3: S3, + options: { migrationFn?(value: any): Config[S1][S2][S3] } + ): Promise; + migrateIfMissing< + S1 extends keyof Config, + S2 extends keyof Config[S1], + S3 extends keyof Config[S1][S2], + S4 extends keyof Config[S1][S2][S3] + >( + from: string, + to1: S1, + to2: S2, + to3: S3, + to4: S4, + options: { migrationFn?(value: any): Config[S1][S2][S3][S4] } + ): Promise; + async migrateIfMissing(from: string, ...args: any[]): Promise { + let to: string = args[0]; + let options: { migrationFn?(value: any): any } | undefined; + if (typeof args[1] === 'string' && args.length > 3) { + to += `.${args[1]}`; + if (typeof args[2] === 'string' && args.length > 4) { + to += `.${args[2]}`; + if (typeof args[3] === 'string' && args.length > 5) { + to += `.${args[3]}`; + options = args[4]; + } else { + options = args[3]; + } + } else { + options = args[2]; + } + } else { + options = args[1]; + } + + if (options === undefined) { + options = {}; + } + + // async migrateIfMissing(from: string, to: string, options: { migrationFn?(value: TFrom): TTo } = {}) { + const fromInspection = configuration.inspect(from as any); if (fromInspection === undefined) return; - const toInspection = configuration.inspect(to); + const toInspection = configuration.inspect(to as any); if (fromInspection.globalValue !== undefined) { if (toInspection === undefined || toInspection.globalValue === undefined) { await this.update( - to, - options.migrationFn - ? options.migrationFn(fromInspection.globalValue as TFrom) - : fromInspection.globalValue, + to as any, + options.migrationFn ? options.migrationFn(fromInspection.globalValue) : fromInspection.globalValue, ConfigurationTarget.Global ); // Can't delete the old setting currently because it errors with `Unable to write to User Settings because is not a registered configuration` @@ -201,9 +441,9 @@ export class Configuration { if (fromInspection.workspaceValue !== undefined) { if (toInspection === undefined || toInspection.workspaceValue === undefined) { await this.update( - to, + to as any, options.migrationFn - ? options.migrationFn(fromInspection.workspaceValue as TFrom) + ? options.migrationFn(fromInspection.workspaceValue) : fromInspection.workspaceValue, ConfigurationTarget.Workspace ); @@ -220,9 +460,9 @@ export class Configuration { if (fromInspection.workspaceFolderValue !== undefined) { if (toInspection === undefined || toInspection.workspaceFolderValue === undefined) { await this.update( - to, + to as any, options.migrationFn - ? options.migrationFn(fromInspection.workspaceFolderValue as TFrom) + ? options.migrationFn(fromInspection.workspaceFolderValue) : fromInspection.workspaceFolderValue, ConfigurationTarget.WorkspaceFolder ); @@ -237,14 +477,77 @@ export class Configuration { } } - name(name: K) { - return Functions.propOf(emptyConfig, name); + name(s1: S1): string; + name(s1: S1, s2: S2): string; + name( + s1: S1, + s2: S2, + s3: S3 + ): string; + name< + S1 extends keyof Config, + S2 extends keyof Config[S1], + S3 extends keyof Config[S1][S2], + S4 extends keyof Config[S1][S2][S3] + >(s1: S1, s2: S2, s3: S3, s4: S4): string; + name(...args: string[]) { + return args.join('.'); } - update(section: string, value: any, target: ConfigurationTarget, resource?: Uri | null) { - return workspace - .getConfiguration(extensionId, target === ConfigurationTarget.Global ? undefined : resource!) - .update(section, value, target); + update(s1: S1, value: Config[S1] | undefined, target: ConfigurationTarget): Thenable; + update( + s1: S1, + s2: S2, + value: Config[S1][S2] | undefined, + target: ConfigurationTarget + ): Thenable; + + update( + s1: S1, + s2: S2, + s3: S3, + value: Config[S1][S2][S3] | undefined, + target: ConfigurationTarget + ): Thenable; + update< + S1 extends keyof Config, + S2 extends keyof Config[S1], + S3 extends keyof Config[S1][S2], + S4 extends keyof Config[S1][S2][S3] + >( + s1: S1, + s2: S2, + s3: S3, + s4: S4, + value: Config[S1][S2][S3][S4] | undefined, + target: ConfigurationTarget + ): Thenable; + update(...args: any[]) { + let section: string = args[0]; + let value; + let target: ConfigurationTarget; + if (typeof args[1] === 'string' && args.length > 3) { + section += `.${args[1]}`; + if (typeof args[2] === 'string' && args.length > 4) { + section += `.${args[2]}`; + if (typeof args[3] === 'string' && args.length > 5) { + section += `.${args[3]}`; + value = args[4]; + target = args[5]; + } else { + value = args[3]; + target = args[4]; + } + } else { + value = args[2]; + target = args[3]; + } + } else { + value = args[1]; + target = args[2]; + } + + return workspace.getConfiguration(extensionId).update(section, value, target); } updateAny(section: string, value: any, target: ConfigurationTarget, resource?: Uri | null) { @@ -253,18 +556,55 @@ export class Configuration { .update(section, value, target); } - updateEffective(section: string, value: any, resource: Uri | null = null): Thenable { - const inspect = configuration.inspect(section, resource)!; + updateEffective(s1: S1, value: Config[S1]): Thenable; + updateEffective( + s1: S1, + s2: S2, + value: Config[S1][S2] + ): Thenable; + updateEffective( + s1: S1, + s2: S2, + s3: S3, + value: Config[S1][S2][S3] + ): Thenable; + updateEffective< + S1 extends keyof Config, + S2 extends keyof Config[S1], + S3 extends keyof Config[S1][S2], + S4 extends keyof Config[S1][S2][S3] + >(s1: S1, s2: S2, s3: S3, s4: S4, value: Config[S1][S2][S3][S4]): Thenable; + updateEffective(...args: any[]) { + let section: string = args[0]; + let value; + if (typeof args[1] === 'string' && args.length > 2) { + section += `.${args[1]}`; + if (typeof args[2] === 'string' && args.length > 3) { + section += `.${args[2]}`; + if (typeof args[3] === 'string' && args.length > 4) { + section += `.${args[3]}`; + value = args[4]; + } else { + value = args[3]; + } + } else { + value = args[2]; + } + } else { + value = args[1]; + } + + const inspect = configuration.inspect(section as any)!; if (inspect.workspaceFolderValue !== undefined) { if (value === inspect.workspaceFolderValue) return Promise.resolve(undefined); - return configuration.update(section, value, ConfigurationTarget.WorkspaceFolder, resource); + return configuration.update(section as any, value, ConfigurationTarget.WorkspaceFolder); } if (inspect.workspaceValue !== undefined) { if (value === inspect.workspaceValue) return Promise.resolve(undefined); - return configuration.update(section, value, ConfigurationTarget.Workspace); + return configuration.update(section as any, value, ConfigurationTarget.Workspace); } if (inspect.globalValue === value || (inspect.globalValue === undefined && value === inspect.defaultValue)) { @@ -272,7 +612,7 @@ export class Configuration { } return configuration.update( - section, + section as any, Objects.areEquivalent(value, inspect.defaultValue) ? undefined : value, ConfigurationTarget.Global ); diff --git a/src/container.ts b/src/container.ts index c255147..4456ad3 100644 --- a/src/container.ts +++ b/src/container.ts @@ -10,7 +10,7 @@ import { GitService } from './git/gitService'; import { clearAvatarCache } from './avatars'; import { LineHoverController } from './hovers/lineHoverController'; import { Keyboard } from './keyboard'; -import { Logger, TraceLevel } from './logger'; +import { Logger } from './logger'; import { StatusBarController } from './statusbar/statusBarController'; import { GitDocumentTracker } from './trackers/gitDocumentTracker'; import { GitLineTracker } from './trackers/gitLineTracker'; @@ -58,7 +58,7 @@ export class Container { let disposable: Disposable; // eslint-disable-next-line prefer-const disposable = configuration.onDidChange(e => { - if (configuration.changed(e, configuration.name('views')('compare')('enabled').value)) { + if (configuration.changed(e, 'views', 'compare', 'enabled')) { disposable.dispose(); context.subscriptions.push((this._compareView = new CompareView())); } @@ -71,7 +71,7 @@ export class Container { let disposable: Disposable; // eslint-disable-next-line prefer-const disposable = configuration.onDidChange(e => { - if (configuration.changed(e, configuration.name('views')('fileHistory')('enabled').value)) { + if (configuration.changed(e, 'views', 'fileHistory', 'enabled')) { disposable.dispose(); context.subscriptions.push((this._fileHistoryView = new FileHistoryView())); } @@ -84,7 +84,7 @@ export class Container { let disposable: Disposable; // eslint-disable-next-line prefer-const disposable = configuration.onDidChange(e => { - if (configuration.changed(e, configuration.name('views')('lineHistory')('enabled').value)) { + if (configuration.changed(e, 'views', 'lineHistory', 'enabled')) { disposable.dispose(); context.subscriptions.push((this._lineHistoryView = new LineHistoryView())); } @@ -97,7 +97,7 @@ export class Container { let disposable: Disposable; // eslint-disable-next-line prefer-const disposable = configuration.onDidChange(e => { - if (configuration.changed(e, configuration.name('views')('repositories')('enabled').value)) { + if (configuration.changed(e, 'views', 'repositories', 'enabled')) { disposable.dispose(); context.subscriptions.push((this._repositoriesView = new RepositoriesView())); } @@ -110,7 +110,7 @@ export class Container { let disposable: Disposable; // eslint-disable-next-line prefer-const disposable = configuration.onDidChange(e => { - if (configuration.changed(e, configuration.name('views')('search')('enabled').value)) { + if (configuration.changed(e, 'views', 'search', 'enabled')) { disposable.dispose(); context.subscriptions.push((this._searchView = new SearchView())); } @@ -125,18 +125,15 @@ export class Container { private static onConfigurationChanging(e: ConfigurationWillChangeEvent) { this._config = undefined; - if (configuration.changed(e.change, configuration.name('outputLevel').value)) { - Logger.level = configuration.get(configuration.name('outputLevel').value); + if (configuration.changed(e.change, 'outputLevel')) { + Logger.level = configuration.get('outputLevel'); } - if (configuration.changed(e.change, configuration.name('defaultGravatarsStyle').value)) { + if (configuration.changed(e.change, 'defaultGravatarsStyle')) { clearAvatarCache(); } - if ( - configuration.changed(e.change, configuration.name('mode').value) || - configuration.changed(e.change, configuration.name('modes').value) - ) { + if (configuration.changed(e.change, 'mode') || configuration.changed(e.change, 'modes')) { if (this._applyModeConfigurationTransformBound === undefined) { this._applyModeConfigurationTransformBound = this.applyModeConfigurationTransform.bind(this); } @@ -161,7 +158,7 @@ export class Container { private static _config: Config | undefined; static get config() { if (this._config === undefined) { - this._config = Container.applyMode(configuration.get()); + this._config = Container.applyMode(configuration.get()); } return this._config; } @@ -340,20 +337,20 @@ export class Container { private static applyModeConfigurationTransform(e: ConfigurationChangeEvent): ConfigurationChangeEvent { if (this._configsAffectedByMode === undefined) { this._configsAffectedByMode = [ - `gitlens.${configuration.name('mode').value}`, - `gitlens.${configuration.name('modes').value}`, - `gitlens.${configuration.name('blame')('toggleMode').value}`, - `gitlens.${configuration.name('codeLens').value}`, - `gitlens.${configuration.name('currentLine').value}`, - `gitlens.${configuration.name('heatmap')('toggleMode').value}`, - `gitlens.${configuration.name('hovers').value}`, - `gitlens.${configuration.name('recentChanges')('toggleMode').value}`, - `gitlens.${configuration.name('statusBar').value}`, - `gitlens.${configuration.name('views')('compare').value}`, - `gitlens.${configuration.name('views')('fileHistory').value}`, - `gitlens.${configuration.name('views')('lineHistory').value}`, - `gitlens.${configuration.name('views')('repositories').value}`, - `gitlens.${configuration.name('views')('search').value}` + `gitlens.${configuration.name('mode')}`, + `gitlens.${configuration.name('modes')}`, + `gitlens.${configuration.name('blame', 'toggleMode')}`, + `gitlens.${configuration.name('codeLens')}`, + `gitlens.${configuration.name('currentLine')}`, + `gitlens.${configuration.name('heatmap', 'toggleMode')}`, + `gitlens.${configuration.name('hovers')}`, + `gitlens.${configuration.name('recentChanges', 'toggleMode')}`, + `gitlens.${configuration.name('statusBar')}`, + `gitlens.${configuration.name('views', 'compare')}`, + `gitlens.${configuration.name('views', 'fileHistory')}`, + `gitlens.${configuration.name('views', 'lineHistory')}`, + `gitlens.${configuration.name('views', 'repositories')}`, + `gitlens.${configuration.name('views', 'search')}` ]; } diff --git a/src/extension.ts b/src/extension.ts index f6234d4..bc1e7a1 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -2,11 +2,11 @@ import { commands, ExtensionContext, extensions, window, workspace } from 'vscode'; import { Commands, registerCommands } from './commands'; import { ViewShowBranchComparison } from './config'; -import { Config, configuration, Configuration } from './configuration'; +import { configuration, Configuration } from './configuration'; import { CommandContext, extensionQualifiedId, GlobalState, GlyphChars, setCommandContext } from './constants'; import { Container } from './container'; import { GitCommit, GitService, GitUri } from './git/gitService'; -import { Logger, TraceLevel } from './logger'; +import { Logger } from './logger'; import { Messages } from './messages'; import { Strings, Versions } from './system'; // import { Telemetry } from './telemetry'; @@ -17,7 +17,7 @@ export async function activate(context: ExtensionContext) { // Pretend we are enabled (until we know otherwise) and set the view contexts to reduce flashing on load setCommandContext(CommandContext.Enabled, true); - Logger.configure(context, configuration.get(configuration.name('outputLevel').value), o => { + Logger.configure(context, configuration.get('outputLevel'), o => { if (GitUri.is(o)) { return `GitUri(${o.toString(true)}${o.repoPath ? ` repoPath=${o.repoPath}` : ''}${ o.sha ? ` sha=${o.sha}` : '' @@ -46,7 +46,7 @@ export async function activate(context: ExtensionContext) { Configuration.configure(context); - const cfg = configuration.get(); + const cfg = configuration.get(); const previousVersion = context.globalState.get(GlobalState.GitLensVersion); await migrateSettings(context, previousVersion); @@ -105,14 +105,13 @@ async function migrateSettings(context: ExtensionContext, previousVersion: strin try { if (Versions.compare(previous, Versions.from(9, 8, 5)) !== 1) { - const name = configuration.name('views')('commitFormat').value; - const value = configuration.get(name); + const value = configuration.get('views', 'commitFormat'); if (!/\btips\b/.test(value)) { - await configuration.updateEffective(name, `\${❰ tips ❱➤ }${value}`); + await configuration.updateEffective('views', 'commitFormat', `\${❰ tips ❱➤ }${value}`); } } else if (Versions.compare(previous, Versions.from(9, 8, 2)) !== 1) { - const name = configuration.name('views')('repositories')('showBranchComparison').value; - await configuration.migrate(name, name, { + const name = configuration.name('views', 'repositories', 'showBranchComparison'); + await configuration.migrate(name, 'views', 'repositories', 'showBranchComparison', { migrationFn: (v: boolean) => (v === false ? false : ViewShowBranchComparison.Working) }); } else if (Versions.compare(previous, Versions.from(9, 6, 3)) !== 1) { @@ -130,16 +129,16 @@ async function migrateSettings(context: ExtensionContext, previousVersion: strin await Promise.all( [ - configuration.name('blame')('format').value, - configuration.name('currentLine')('format').value, - configuration.name('hovers')('detailsMarkdownFormat').value, - configuration.name('statusBar')('format').value, - configuration.name('views')('commitFormat').value, - configuration.name('views')('commitDescriptionFormat').value, - configuration.name('views')('stashFormat').value, - configuration.name('views')('stashDescriptionFormat').value + configuration.name('blame', 'format'), + configuration.name('currentLine', 'format'), + configuration.name('hovers', 'detailsMarkdownFormat'), + configuration.name('statusBar', 'format'), + configuration.name('views', 'commitFormat'), + configuration.name('views', 'commitDescriptionFormat'), + configuration.name('views', 'stashFormat'), + configuration.name('views', 'stashDescriptionFormat') ].map(s => - configuration.migrate(s, s, { + configuration.migrate(s, s as any, { migrationFn: formatMigrationFn }) ) diff --git a/src/git/gitService.ts b/src/git/gitService.ts index 2f8727b..5b83675 100644 --- a/src/git/gitService.ts +++ b/src/git/gitService.ts @@ -20,7 +20,7 @@ import { } from 'vscode'; // eslint-disable-next-line import/no-unresolved import { API as BuiltInGitApi, GitExtension } from '../@types/git'; -import { configuration, RemotesConfig } from '../configuration'; +import { configuration } from '../configuration'; import { CommandContext, DocumentSchemes, setCommandContext } from '../constants'; import { Container } from '../container'; import { LogCorrelationContext, Logger } from '../logger'; @@ -181,9 +181,9 @@ export class GitService implements Disposable { private onConfigurationChanged(e: ConfigurationChangeEvent) { if ( - configuration.changed(e, configuration.name('defaultDateFormat').value) || - configuration.changed(e, configuration.name('defaultDateSource').value) || - configuration.changed(e, configuration.name('defaultDateStyle').value) + configuration.changed(e, 'defaultDateFormat') || + configuration.changed(e, 'defaultDateSource') || + configuration.changed(e, 'defaultDateStyle') ) { CommitFormatting.reset(); } @@ -291,7 +291,7 @@ export class GitService implements Disposable { private async repositorySearch(folder: WorkspaceFolder): Promise { const cc = Logger.getCorrelationContext(); const { uri } = folder; - const depth = configuration.get(configuration.name('advanced')('repositorySearchDepth').value, uri); + const depth = configuration.get('advanced', 'repositorySearchDepth', uri); Logger.log(cc, `searching (depth=${depth})...`); @@ -2114,11 +2114,7 @@ export class GitService implements Disposable { ): Promise { if (repoPath === undefined) return []; - providers = - providers || - RemoteProviderFactory.loadProviders( - configuration.get(configuration.name('remotes').value, null) - ); + providers = providers || RemoteProviderFactory.loadProviders(configuration.get('remotes', null)); try { const data = await Git.remote(repoPath); diff --git a/src/git/models/commit.ts b/src/git/models/commit.ts index 6392455..864074d 100644 --- a/src/git/models/commit.ts +++ b/src/git/models/commit.ts @@ -36,9 +36,9 @@ export const CommitFormatting = { dateStyle: undefined! as DateStyle, reset: () => { - CommitFormatting.dateFormat = configuration.get(configuration.name('defaultDateFormat').value); - CommitFormatting.dateSource = configuration.get(configuration.name('defaultDateSource').value); - CommitFormatting.dateStyle = configuration.get(configuration.name('defaultDateStyle').value); + CommitFormatting.dateFormat = configuration.get('defaultDateFormat'); + CommitFormatting.dateSource = configuration.get('defaultDateSource'); + CommitFormatting.dateStyle = configuration.get('defaultDateStyle'); } }; diff --git a/src/git/models/repository.ts b/src/git/models/repository.ts index 8d6c47b..75b99b6 100644 --- a/src/git/models/repository.ts +++ b/src/git/models/repository.ts @@ -14,7 +14,7 @@ import { workspace, WorkspaceFolder } from 'vscode'; -import { configuration, RemotesConfig } from '../../configuration'; +import { configuration } from '../../configuration'; import { StarredRepositories, WorkspaceState } from '../../constants'; import { Container } from '../../container'; import { Functions, gate, log } from '../../system'; @@ -167,11 +167,8 @@ export class Repository implements Disposable { } private onConfigurationChanged(e: ConfigurationChangeEvent) { - const section = configuration.name('remotes').value; - if (configuration.changed(e, section, this.folder.uri)) { - this._providers = RemoteProviderFactory.loadProviders( - configuration.get(section, this.folder.uri) - ); + if (configuration.changed(e, 'remotes', this.folder.uri)) { + this._providers = RemoteProviderFactory.loadProviders(configuration.get('remotes', this.folder.uri)); if (!configuration.initializing(e)) { this._remotes = undefined; @@ -336,10 +333,7 @@ export class Repository implements Disposable { getRemotes(options: { sort?: boolean } = {}): Promise { if (this._remotes === undefined || !this.supportsChangeEvents) { if (this._providers === undefined) { - const remotesCfg = configuration.get( - configuration.name('remotes').value, - this.folder.uri - ); + const remotesCfg = configuration.get('remotes', this.folder.uri); this._providers = RemoteProviderFactory.loadProviders(remotesCfg); } diff --git a/src/hovers/lineHoverController.ts b/src/hovers/lineHoverController.ts index 51cf647..a68a0cf 100644 --- a/src/hovers/lineHoverController.ts +++ b/src/hovers/lineHoverController.ts @@ -34,8 +34,8 @@ export class LineHoverController implements Disposable { private onConfigurationChanged(e: ConfigurationChangeEvent) { if ( - !configuration.changed(e, configuration.name('hovers')('enabled').value) && - !configuration.changed(e, configuration.name('hovers')('currentLine')('enabled').value) + !configuration.changed(e, 'hovers', 'enabled') && + !configuration.changed(e, 'hovers', 'currentLine', 'enabled') ) { return; } diff --git a/src/messages.ts b/src/messages.ts index 84749fc..fc0216d 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -160,10 +160,7 @@ export class Messages { ): Promise { Logger.log(`ShowMessage(${type}, '${message}', ${suppressionKey}, ${dontShowAgain})`); - if ( - suppressionKey !== undefined && - configuration.get(configuration.name('advanced')('messages')(suppressionKey).value) - ) { + if (suppressionKey !== undefined && configuration.get('advanced', 'messages', suppressionKey)) { Logger.log(`ShowMessage(${type}, '${message}', ${suppressionKey}, ${dontShowAgain}) skipped`); return undefined; } @@ -205,8 +202,7 @@ export class Messages { } private static suppressedMessage(suppressionKey: SuppressedMessages) { - const section = configuration.name('advanced')('messages').value; - const messages: { [key: string]: boolean | undefined } = configuration.get<{}>(section); + const messages: { [key: string]: boolean | undefined } = configuration.get('advanced', 'messages'); messages[suppressionKey] = true; @@ -216,6 +212,6 @@ export class Messages { } } - return configuration.update(section, messages, ConfigurationTarget.Global); + return configuration.update('advanced', 'messages', messages as any, ConfigurationTarget.Global); } } diff --git a/src/quickpicks/commonQuickPicks.ts b/src/quickpicks/commonQuickPicks.ts index 5a8c63d..e80d957 100644 --- a/src/quickpicks/commonQuickPicks.ts +++ b/src/quickpicks/commonQuickPicks.ts @@ -8,7 +8,7 @@ import { KeyMapping, Keys } from '../keyboard'; import { ReferencesQuickPick, ReferencesQuickPickItem } from './referencesQuickPick'; export function getQuickPickIgnoreFocusOut() { - return !configuration.get(configuration.name('advanced')('quickPick')('closeOnFocusOut').value); + return !configuration.get('advanced', 'quickPick', 'closeOnFocusOut'); } export function showQuickPickProgress(message: string, mapping?: KeyMapping): CancellationTokenSource { diff --git a/src/statusbar/statusBarController.ts b/src/statusbar/statusBarController.ts index 61e46c9..723882f 100644 --- a/src/statusbar/statusBarController.ts +++ b/src/statusbar/statusBarController.ts @@ -28,7 +28,7 @@ export class StatusBarController implements Disposable { } private onConfigurationChanged(e: ConfigurationChangeEvent) { - if (configuration.changed(e, configuration.name('mode').value)) { + if (configuration.changed(e, 'mode')) { const mode = Container.config.mode.active && Container.config.mode.statusBar.enabled ? Container.config.modes[Container.config.mode.active] @@ -39,7 +39,7 @@ export class StatusBarController implements Disposable { ? StatusBarAlignment.Right : StatusBarAlignment.Left; - if (configuration.changed(e, configuration.name('mode')('statusBar')('alignment').value)) { + if (configuration.changed(e, 'mode', 'statusBar', 'alignment')) { if (this._modeStatusBarItem !== undefined && this._modeStatusBarItem.alignment !== alignment) { this._modeStatusBarItem.dispose(); this._modeStatusBarItem = undefined; @@ -59,13 +59,13 @@ export class StatusBarController implements Disposable { } } - if (!configuration.changed(e, configuration.name('statusBar').value)) return; + if (!configuration.changed(e, 'statusBar')) return; if (Container.config.statusBar.enabled) { const alignment = Container.config.statusBar.alignment !== 'left' ? StatusBarAlignment.Right : StatusBarAlignment.Left; - if (configuration.changed(e, configuration.name('statusBar')('alignment').value)) { + if (configuration.changed(e, 'statusBar', 'alignment')) { if (this._blameStatusBarItem !== undefined && this._blameStatusBarItem.alignment !== alignment) { this._blameStatusBarItem.dispose(); this._blameStatusBarItem = undefined; @@ -77,13 +77,13 @@ export class StatusBarController implements Disposable { window.createStatusBarItem(alignment, alignment === StatusBarAlignment.Right ? 1000 : 0); this._blameStatusBarItem.command = Container.config.statusBar.command; - if (configuration.changed(e, configuration.name('statusBar')('enabled').value)) { + if (configuration.changed(e, 'statusBar', 'enabled')) { Container.lineTracker.start( this, Disposable.from(Container.lineTracker.onDidChangeActiveLines(this.onActiveLinesChanged, this)) ); } - } else if (configuration.changed(e, configuration.name('statusBar')('enabled').value)) { + } else if (configuration.changed(e, 'statusBar', 'enabled')) { Container.lineTracker.stop(this); if (this._blameStatusBarItem !== undefined) { diff --git a/src/trackers/documentTracker.ts b/src/trackers/documentTracker.ts index cf75335..d49c437 100644 --- a/src/trackers/documentTracker.ts +++ b/src/trackers/documentTracker.ts @@ -81,17 +81,16 @@ export class DocumentTracker implements Disposable { // Only rest the cached state if we aren't initializing if ( !configuration.initializing(e) && - (configuration.changed(e, configuration.name('blame')('ignoreWhitespace').value, null) || - configuration.changed(e, configuration.name('advanced')('caching')('enabled').value)) + (configuration.changed(e, 'blame', 'ignoreWhitespace', null) || + configuration.changed(e, 'advanced', 'caching', 'enabled')) ) { for (const d of this._documentMap.values()) { d.reset('config'); } } - const section = configuration.name('advanced')('blame')('delayAfterEdit').value; - if (configuration.changed(e, section)) { - this._dirtyIdleTriggerDelay = configuration.get(section); + if (configuration.changed(e, 'advanced', 'blame', 'delayAfterEdit')) { + this._dirtyIdleTriggerDelay = configuration.get('advanced', 'blame', 'delayAfterEdit'); this._dirtyIdleTriggeredDebounced = undefined; } } diff --git a/src/views/compareView.ts b/src/views/compareView.ts index 3bcb130..0d706c2 100644 --- a/src/views/compareView.ts +++ b/src/views/compareView.ts @@ -70,14 +70,14 @@ export class CompareView extends ViewBase { protected onConfigurationChanged(e: ConfigurationChangeEvent) { if ( - !configuration.changed(e, configuration.name('views')('compare').value) && - !configuration.changed(e, configuration.name('views').value) && - !configuration.changed(e, configuration.name('defaultGravatarsStyle').value) + !configuration.changed(e, 'views', 'compare') && + !configuration.changed(e, 'views') && + !configuration.changed(e, 'defaultGravatarsStyle') ) { return; } - if (configuration.changed(e, configuration.name('views')('compare')('location').value)) { + if (configuration.changed(e, 'views', 'compare', 'location')) { this.initialize(this.config.location, { showCollapseAll: true }); } @@ -164,7 +164,7 @@ export class CompareView extends ViewBase { } private setFilesLayout(layout: ViewFilesLayout) { - return configuration.updateEffective(configuration.name('views')('compare')('files')('layout').value, layout); + return configuration.updateEffective('views', 'compare', 'files', 'layout', layout); } private setKeepResults(enabled: boolean) { diff --git a/src/views/fileHistoryView.ts b/src/views/fileHistoryView.ts index ebfffaa..0abfa46 100644 --- a/src/views/fileHistoryView.ts +++ b/src/views/fileHistoryView.ts @@ -54,19 +54,19 @@ export class FileHistoryView extends ViewBase { protected onConfigurationChanged(e: ConfigurationChangeEvent) { if ( - !configuration.changed(e, configuration.name('views')('fileHistory').value) && - !configuration.changed(e, configuration.name('views').value) && - !configuration.changed(e, configuration.name('defaultGravatarsStyle').value) && - !configuration.changed(e, configuration.name('advanced')('fileHistoryFollowsRenames').value) + !configuration.changed(e, 'views', 'fileHistory') && + !configuration.changed(e, 'views') && + !configuration.changed(e, 'defaultGravatarsStyle') && + !configuration.changed(e, 'advanced', 'fileHistoryFollowsRenames') ) { return; } - if (configuration.changed(e, configuration.name('views')('fileHistory')('enabled').value)) { + if (configuration.changed(e, 'views', 'fileHistory', 'enabled')) { setCommandContext(CommandContext.ViewsFileHistoryEditorFollowing, true); } - if (configuration.changed(e, configuration.name('views')('fileHistory')('location').value)) { + if (configuration.changed(e, 'views', 'fileHistory', 'location')) { this.initialize(this.config.location); } @@ -101,9 +101,6 @@ export class FileHistoryView extends ViewBase { } private setRenameFollowing(enabled: boolean) { - return configuration.updateEffective( - configuration.name('advanced')('fileHistoryFollowsRenames').value, - enabled - ); + return configuration.updateEffective('advanced', 'fileHistoryFollowsRenames', enabled); } } diff --git a/src/views/lineHistoryView.ts b/src/views/lineHistoryView.ts index 7a57da7..d6832b9 100644 --- a/src/views/lineHistoryView.ts +++ b/src/views/lineHistoryView.ts @@ -53,19 +53,19 @@ export class LineHistoryView extends ViewBase { protected onConfigurationChanged(e: ConfigurationChangeEvent) { if ( - !configuration.changed(e, configuration.name('views')('lineHistory').value) && - !configuration.changed(e, configuration.name('views').value) && - !configuration.changed(e, configuration.name('defaultGravatarsStyle').value) && - !configuration.changed(e, configuration.name('advanced')('fileHistoryFollowsRenames').value) + !configuration.changed(e, 'views', 'lineHistory') && + !configuration.changed(e, 'views') && + !configuration.changed(e, 'defaultGravatarsStyle') && + !configuration.changed(e, 'advanced', 'fileHistoryFollowsRenames') ) { return; } - if (configuration.changed(e, configuration.name('views')('lineHistory')('enabled').value)) { + if (configuration.changed(e, 'views', 'lineHistory', 'enabled')) { setCommandContext(CommandContext.ViewsLineHistoryEditorFollowing, true); } - if (configuration.changed(e, configuration.name('views')('lineHistory')('location').value)) { + if (configuration.changed(e, 'views', 'lineHistory', 'location')) { this.initialize(this.config.location); } @@ -92,9 +92,6 @@ export class LineHistoryView extends ViewBase { } private setRenameFollowing(enabled: boolean) { - return configuration.updateEffective( - configuration.name('advanced')('fileHistoryFollowsRenames').value, - enabled - ); + return configuration.updateEffective('advanced', 'fileHistoryFollowsRenames', enabled); } } diff --git a/src/views/repositoriesView.ts b/src/views/repositoriesView.ts index 3e75f11..ffcc1da 100644 --- a/src/views/repositoriesView.ts +++ b/src/views/repositoriesView.ts @@ -76,18 +76,18 @@ export class RepositoriesView extends ViewBase { protected onConfigurationChanged(e: ConfigurationChangeEvent) { if ( - !configuration.changed(e, configuration.name('views')('repositories').value) && - !configuration.changed(e, configuration.name('views').value) && - !configuration.changed(e, configuration.name('defaultGravatarsStyle').value) + !configuration.changed(e, 'views', 'repositories') && + !configuration.changed(e, 'views') && + !configuration.changed(e, 'defaultGravatarsStyle') ) { return; } - if (configuration.changed(e, configuration.name('views')('repositories')('autoRefresh').value)) { + if (configuration.changed(e, 'views', 'repositories', 'autoRefresh')) { void this.setAutoRefresh(Container.config.views.repositories.autoRefresh); } - if (configuration.changed(e, configuration.name('views')('repositories')('location').value)) { + if (configuration.changed(e, 'views', 'repositories', 'location')) { this.initialize(this.config.location, { showCollapseAll: true }); } @@ -134,9 +134,6 @@ export class RepositoriesView extends ViewBase { } private setFilesLayout(layout: ViewFilesLayout) { - return configuration.updateEffective( - configuration.name('views')('repositories')('files')('layout').value, - layout - ); + return configuration.updateEffective('views', 'repositories', 'files', 'layout', layout); } } diff --git a/src/views/searchView.ts b/src/views/searchView.ts index a241f9d..b38329d 100644 --- a/src/views/searchView.ts +++ b/src/views/searchView.ts @@ -63,14 +63,14 @@ export class SearchView extends ViewBase { protected onConfigurationChanged(e: ConfigurationChangeEvent) { if ( - !configuration.changed(e, configuration.name('views')('search').value) && - !configuration.changed(e, configuration.name('views').value) && - !configuration.changed(e, configuration.name('defaultGravatarsStyle').value) + !configuration.changed(e, 'views', 'search') && + !configuration.changed(e, 'views') && + !configuration.changed(e, 'defaultGravatarsStyle') ) { return; } - if (configuration.changed(e, configuration.name('views')('search')('location').value)) { + if (configuration.changed(e, 'views', 'search', 'location')) { this.initialize(this.config.location, { showCollapseAll: true }); } @@ -222,7 +222,7 @@ export class SearchView extends ViewBase { } private setFilesLayout(layout: ViewFilesLayout) { - return configuration.updateEffective(configuration.name('views')('search')('files')('layout').value, layout); + return configuration.updateEffective('views', 'search', 'files', 'layout', layout); } private setKeepResults(enabled: boolean) { diff --git a/src/views/viewBase.ts b/src/views/viewBase.ts index f022642..38919e8 100644 --- a/src/views/viewBase.ts +++ b/src/views/viewBase.ts @@ -204,8 +204,8 @@ export abstract class ViewBase> implements TreeData } catch (ex) { Logger.error(ex); - const setting = `${Strings.splitSingle(this.id, '.')[1]}.enabled`; - if (!configuration.get(setting)) { + const section = Strings.splitSingle(this.id, '.')[1]; + if (!configuration.get(section as any, 'enabled')) { const actions: MessageItem[] = [{ title: 'Enable' }, { title: 'Cancel', isCloseAffordance: true }]; const result = await window.showErrorMessage( @@ -214,7 +214,7 @@ export abstract class ViewBase> implements TreeData ); if (result === actions[0]) { - await configuration.update(setting, true, ConfigurationTarget.Global); + await configuration.update(section as any, 'enabled', true, ConfigurationTarget.Global); void (await commands.executeCommand(`${this.id}${location ? `:${location}` : ''}.focus`)); } diff --git a/src/webviews/helpers.ts b/src/webviews/helpers.ts index b3fbfac..730c55c 100644 --- a/src/webviews/helpers.ts +++ b/src/webviews/helpers.ts @@ -26,29 +26,9 @@ export function applyViewLayoutPreset(preset: 'contextual' | 'default' | 'scm') return; } - configuration.update( - configuration.name('views')('repositories')('location').value, - repositories, - ConfigurationTarget.Global - ); - configuration.update( - configuration.name('views')('fileHistory')('location').value, - histories, - ConfigurationTarget.Global - ); - configuration.update( - configuration.name('views')('lineHistory')('location').value, - histories, - ConfigurationTarget.Global - ); - configuration.update( - configuration.name('views')('compare')('location').value, - compareAndSearch, - ConfigurationTarget.Global - ); - configuration.update( - configuration.name('views')('search')('location').value, - compareAndSearch, - ConfigurationTarget.Global - ); + configuration.update('views', 'repositories', 'location', repositories, ConfigurationTarget.Global); + configuration.update('views', 'fileHistory', 'location', histories, ConfigurationTarget.Global); + configuration.update('views', 'lineHistory', 'location', histories, ConfigurationTarget.Global); + configuration.update('views', 'compare', 'location', compareAndSearch, ConfigurationTarget.Global); + configuration.update('views', 'search', 'location', compareAndSearch, ConfigurationTarget.Global); } diff --git a/src/webviews/settingsWebview.ts b/src/webviews/settingsWebview.ts index b89f066..fad7cd5 100644 --- a/src/webviews/settingsWebview.ts +++ b/src/webviews/settingsWebview.ts @@ -1,7 +1,7 @@ 'use strict'; import { commands, Disposable, workspace } from 'vscode'; import { Commands } from '../commands'; -import { Config, configuration } from '../configuration'; +import { configuration } from '../configuration'; import { IpcMessage, onIpcCommand, @@ -87,7 +87,7 @@ export class SettingsWebview extends WebviewBase { const bootstrap: SettingsState = { // Make sure to get the raw config, not from the container which has the modes mixed in - config: configuration.get(), + config: configuration.get(), scope: 'user', scopes: scopes }; diff --git a/src/webviews/webviewBase.ts b/src/webviews/webviewBase.ts index 9e86060..f37f8bf 100644 --- a/src/webviews/webviewBase.ts +++ b/src/webviews/webviewBase.ts @@ -13,7 +13,7 @@ import { window, workspace } from 'vscode'; -import { Config, configuration } from '../configuration'; +import { configuration } from '../configuration'; import { Container } from '../container'; import { Logger } from '../logger'; import { @@ -98,18 +98,18 @@ export abstract class WebviewBase implements Disposable { params.scope === 'workspace' ? ConfigurationTarget.Workspace : ConfigurationTarget.Global; for (const key in params.changes) { - const inspect = configuration.inspect(key)!; + const inspect = configuration.inspect(key as any)!; const value = params.changes[key]; void (await configuration.update( - key, + key as any, value === inspect.defaultValue ? undefined : value, target )); } for (const key of params.removes) { - void (await configuration.update(key, undefined, target)); + void (await configuration.update(key as any, undefined, target)); } }); @@ -239,7 +239,7 @@ export abstract class WebviewBase implements Disposable { private notifyDidChangeConfiguration() { // Make sure to get the raw config, not from the container which has the modes mixed in - return this.notify(DidChangeConfigurationNotificationType, { config: configuration.get() }); + return this.notify(DidChangeConfigurationNotificationType, { config: configuration.get() }); } private postMessage(message: IpcMessage) {