Sfoglia il codice sorgente

Reworks config using new TypeScript features

main
Eric Amodio 3 anni fa
parent
commit
db5285d4ad
33 ha cambiato i file con 183 aggiunte e 512 eliminazioni
  1. +3
    -3
      src/annotations/annotations.ts
  2. +5
    -5
      src/annotations/fileAnnotationController.ts
  3. +1
    -1
      src/annotations/lineAnnotationController.ts
  4. +5
    -5
      src/commands/gitCommands.actions.ts
  5. +4
    -6
      src/commands/gitCommands.ts
  6. +2
    -2
      src/commands/quickCommand.steps.ts
  7. +1
    -1
      src/commands/resetSuppressedWarnings.ts
  8. +7
    -7
      src/commands/switchMode.ts
  9. +1
    -1
      src/config.ts
  10. +70
    -368
      src/configuration.ts
  11. +5
    -5
      src/container.ts
  12. +2
    -2
      src/git/gitService.ts
  13. +1
    -4
      src/hovers/lineHoverController.ts
  14. +4
    -4
      src/messages.ts
  15. +1
    -1
      src/quickpicks.ts
  16. +1
    -1
      src/quickpicks/commitPicker.ts
  17. +8
    -5
      src/quickpicks/modePicker.ts
  18. +5
    -5
      src/statusbar/statusBarController.ts
  19. +3
    -4
      src/trackers/documentTracker.ts
  20. +6
    -8
      src/views/branchesView.ts
  21. +5
    -7
      src/views/commitsView.ts
  22. +3
    -3
      src/views/contributorsView.ts
  23. +5
    -5
      src/views/fileHistoryView.ts
  24. +1
    -1
      src/views/lineHistoryView.ts
  25. +1
    -1
      src/views/nodes/fileHistoryNode.ts
  26. +6
    -6
      src/views/remotesView.ts
  27. +15
    -20
      src/views/repositoriesView.ts
  28. +2
    -2
      src/views/searchAndCompareView.ts
  29. +1
    -1
      src/views/stashesView.ts
  30. +3
    -3
      src/views/tagsView.ts
  31. +3
    -22
      src/views/viewBase.ts
  32. +1
    -1
      src/views/viewCommands.ts
  33. +2
    -2
      src/webviews/webviewBase.ts

+ 3
- 3
src/annotations/annotations.ts Vedi File

@ -83,9 +83,9 @@ export async function getHeatmapColors() {
const disposable = configuration.onDidChange(e => {
if (
configuration.changed(e, 'heatmap', 'ageThreshold') ||
configuration.changed(e, 'heatmap', 'hotColor') ||
configuration.changed(e, 'heatmap', 'coldColor')
configuration.changed(e, 'heatmap.ageThreshold') ||
configuration.changed(e, 'heatmap.hotColor') ||
configuration.changed(e, 'heatmap.coldColor')
) {
disposable.dispose();
heatmapColors = undefined;

+ 5
- 5
src/annotations/fileAnnotationController.ts Vedi File

@ -102,7 +102,7 @@ export class FileAnnotationController implements Disposable {
private onConfigurationChanged(e: ConfigurationChangeEvent) {
const cfg = Container.config;
if (configuration.changed(e, 'blame', 'highlight')) {
if (configuration.changed(e, 'blame.highlight')) {
Decorations.gutterBlameHighlight?.dispose();
Decorations.gutterBlameHighlight = undefined;
@ -136,7 +136,7 @@ export class FileAnnotationController implements Disposable {
}
}
if (configuration.changed(e, 'changes', 'locations')) {
if (configuration.changed(e, 'changes.locations')) {
Decorations.changesLineAddedAnnotation?.dispose();
Decorations.changesLineChangedAnnotation?.dispose();
Decorations.changesLineDeletedAnnotation?.dispose();
@ -191,21 +191,21 @@ export class FileAnnotationController implements Disposable {
const initializing = configuration.initializing(e);
if (configuration.changed(e, 'blame', 'toggleMode')) {
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, 'changes', 'toggleMode')) {
if (configuration.changed(e, 'changes.toggleMode')) {
this._toggleModes.set(FileAnnotationType.Changes, cfg.changes.toggleMode);
if (!initializing && cfg.changes.toggleMode === AnnotationsToggleMode.File) {
void this.clearAll();
}
}
if (configuration.changed(e, 'heatmap', 'toggleMode')) {
if (configuration.changed(e, 'heatmap.toggleMode')) {
this._toggleModes.set(FileAnnotationType.Heatmap, cfg.heatmap.toggleMode);
if (!initializing && cfg.heatmap.toggleMode === AnnotationsToggleMode.File) {
void this.clearAll();

+ 1
- 1
src/annotations/lineAnnotationController.ts Vedi File

@ -53,7 +53,7 @@ export class LineAnnotationController implements Disposable {
private onConfigurationChanged(e: ConfigurationChangeEvent) {
if (!configuration.changed(e, 'currentLine')) return;
if (configuration.changed(e, 'currentLine', 'enabled')) {
if (configuration.changed(e, 'currentLine.enabled')) {
if (Container.config.currentLine.enabled) {
this._enabled = true;
this.resume();

+ 5
- 5
src/commands/gitCommands.actions.ts Vedi File

@ -151,7 +151,7 @@ export namespace GitActions {
},
) {
if (
!configuration.get('views', branch.remote ? 'remotes' : 'branches', 'reveal') ||
!configuration.get(`views.${branch.remote ? 'remotes' : 'branches'}.reveal` as const) ||
(Container.repositoriesView.visible &&
!(branch.remote ? Container.remotesView.visible : Container.branchesView.visible))
) {
@ -647,7 +647,7 @@ export namespace GitActions {
},
) {
if (
!configuration.get('views', 'commits', 'reveal') ||
!configuration.get('views.commits.reveal') ||
(Container.repositoriesView.visible && !Container.commitsView.visible)
) {
return Container.repositoriesView.revealCommit(commit, options);
@ -710,7 +710,7 @@ export namespace GitActions {
},
) {
if (
!configuration.get('views', 'tags', 'reveal') ||
!configuration.get('views.tags.reveal') ||
(Container.repositoriesView.visible && !Container.tagsView.visible)
) {
return Container.repositoriesView.revealTag(tag, options);
@ -780,7 +780,7 @@ export namespace GitActions {
},
) {
// if (
// configuration.get('views', 'repositories', 'enabled') &&
// configuration.get('views.repositories.enabled') &&
// (Container.repositoriesView.visible || !Container.remotesView.visible)
// ) {
// return Container.repositoriesView.revealRemote(remote, options);
@ -835,7 +835,7 @@ export namespace GitActions {
},
) {
if (
!configuration.get('views', 'stashes', 'reveal') ||
!configuration.get('views.stashes.reveal') ||
(Container.repositoriesView.visible && !Container.stashesView.visible)
) {
return Container.repositoriesView.revealStash(stash, options);

+ 4
- 6
src/commands/gitCommands.ts Vedi File

@ -238,7 +238,7 @@ export class GitCommandsCommand extends Command {
const willConfirmToggle = new QuickCommandButtons.WillConfirmToggle(command.confirm(), async () => {
if (command?.skipConfirmKey == null) return;
const skipConfirmations = configuration.get('gitCommands', 'skipConfirmations') ?? [];
const skipConfirmations = configuration.get('gitCommands.skipConfirmations') ?? [];
const index = skipConfirmations.indexOf(command.skipConfirmKey);
if (index !== -1) {
@ -247,7 +247,7 @@ export class GitCommandsCommand extends Command {
skipConfirmations.push(command.skipConfirmKey);
}
void (await configuration.updateEffective('gitCommands', 'skipConfirmations', skipConfirmations));
void (await configuration.updateEffective('gitCommands.skipConfirmations', skipConfirmations));
});
buttons.push(willConfirmToggle);
} else {
@ -284,9 +284,7 @@ export class GitCommandsCommand extends Command {
private async showInputStep(step: QuickInputStep, commandsStep: PickCommandStep) {
const input = window.createInputBox();
input.ignoreFocusOut = !configuration.get('gitCommands', 'closeOnFocusOut')
? true
: step.ignoreFocusOut ?? false;
input.ignoreFocusOut = !configuration.get('gitCommands.closeOnFocusOut') ? true : step.ignoreFocusOut ?? false;
const disposables: Disposable[] = [];
@ -398,7 +396,7 @@ export class GitCommandsCommand extends Command {
}
private async showPickStep(step: QuickPickStep, commandsStep: PickCommandStep) {
const originalIgnoreFocusOut = !configuration.get('gitCommands', 'closeOnFocusOut')
const originalIgnoreFocusOut = !configuration.get('gitCommands.closeOnFocusOut')
? true
: step.ignoreFocusOut ?? false;
const originalStepIgnoreFocusOut = step.ignoreFocusOut;

+ 2
- 2
src/commands/quickCommand.steps.ts Vedi File

@ -805,7 +805,7 @@ export async function* pickCommitStep<
value: typeof picked === 'string' && log?.count === 0 ? picked : undefined,
items: showInSideBarCommand != null ? [showInSideBarCommand, ...getItems(log)] : getItems(log),
onDidLoadMore: async quickpick => {
log = await log?.more?.(configuration.get('advanced', 'maxListItems'));
log = await log?.more?.(configuration.get('advanced.maxListItems'));
onDidLoadMore?.(log);
if (typeof placeholder !== 'string') {
quickpick.placeholder = placeholder(context, log);
@ -949,7 +949,7 @@ export function* pickCommitsStep<
matchOnDetail: true,
items: getItems(log),
onDidLoadMore: async quickpick => {
log = await log?.more?.(configuration.get('advanced', 'maxListItems'));
log = await log?.more?.(configuration.get('advanced.maxListItems'));
onDidLoadMore?.(log);
if (typeof placeholder !== 'string') {
quickpick.placeholder = placeholder(context, log);

+ 1
- 1
src/commands/resetSuppressedWarnings.ts Vedi File

@ -10,6 +10,6 @@ export class ResetSuppressedWarningsCommand extends Command {
}
async execute() {
void (await configuration.update('advanced', 'messages', undefined, ConfigurationTarget.Global));
void (await configuration.update('advanced.messages', undefined, ConfigurationTarget.Global));
}
}

+ 7
- 7
src/commands/switchMode.ts Vedi File

@ -29,16 +29,16 @@ export class SwitchModeCommand extends Command {
// Check if we have applied any annotations and clear them if we won't be applying them again
if (active != null && active.length !== 0) {
const activeAnnotations = Container.config.modes[active].annotations;
const activeAnnotations = Container.config.modes?.[active].annotations;
if (activeAnnotations != null) {
const newAnnotations = pick.key != null ? Container.config.modes[pick.key].annotations : undefined;
const newAnnotations = pick.key != null ? Container.config.modes?.[pick.key].annotations : undefined;
if (activeAnnotations !== newAnnotations) {
await Container.fileAnnotations.clearAll();
}
}
}
await configuration.update('mode', 'active', pick.key, ConfigurationTarget.Global);
await configuration.update('mode.active', pick.key, ConfigurationTarget.Global);
}
}
@ -50,10 +50,10 @@ export class ToggleReviewModeCommand extends Command {
@log({ args: false, singleLine: true, timed: false })
async execute() {
if (!Object.keys(Container.config.modes).includes('review')) return;
if (Container.config.modes == null || !Object.keys(Container.config.modes).includes('review')) return;
const mode = Container.config.mode.active === 'review' ? undefined : 'review';
await configuration.update('mode', 'active', mode, ConfigurationTarget.Global);
await configuration.update('mode.active', mode, ConfigurationTarget.Global);
}
}
@ -65,9 +65,9 @@ export class ToggleZenModeCommand extends Command {
@log({ args: false, singleLine: true, timed: false })
async execute() {
if (!Object.keys(Container.config.modes).includes('zen')) return;
if (Container.config.modes == null || !Object.keys(Container.config.modes).includes('zen')) return;
const mode = Container.config.mode.active === 'zen' ? undefined : 'zen';
await configuration.update('mode', 'active', mode, ConfigurationTarget.Global);
await configuration.update('mode.active', mode, ConfigurationTarget.Global);
}
}

+ 1
- 1
src/config.ts Vedi File

@ -109,7 +109,7 @@ export interface Config {
alignment: 'left' | 'right';
};
};
modes: Record<string, ModeConfig>;
modes: Record<string, ModeConfig> | null;
outputLevel: TraceLevel;
partners: Record<
string,

+ 70
- 368
src/configuration.ts Vedi File

@ -8,7 +8,6 @@ import {
Event,
EventEmitter,
ExtensionContext,
Uri,
workspace,
} from 'vscode';
import { Config } from './config';
@ -74,68 +73,23 @@ export class Configuration {
readonly initializingChangeEvent: ConfigurationChangeEvent = { affectsConfiguration: () => true };
get(): Config;
get<S1 extends keyof Config>(s1: S1, scope?: ConfigurationScope | null, defaultValue?: Config[S1]): Config[S1];
get<S1 extends keyof Config, S2 extends keyof Config[S1]>(
s1: S1,
s2: S2,
get<T extends ConfigPath>(
section: T,
scope?: ConfigurationScope | null,
defaultValue?: Config[S1][S2],
): Config[S1][S2];
get<S1 extends keyof Config, S2 extends keyof Config[S1], S3 extends keyof Config[S1][S2]>(
s1: S1,
s2: S2,
s3: S3,
defaultValue?: ConfigPathValue<T>,
): ConfigPathValue<T>;
get<T extends ConfigPath>(
section?: T,
scope?: ConfigurationScope | 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,
scope?: ConfigurationScope | null,
defaultValue?: Config[S1][S2][S3][S4],
): Config[S1][S2][S3][S4];
get<T>(...args: any[]): T {
let section: string | undefined;
let scope: ConfigurationScope | 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[3] === 'string') {
section += `.${args[3]}`;
scope = args[4];
defaultValue = args[5];
} else {
scope = args[3];
defaultValue = args[4];
}
} else {
scope = args[2];
defaultValue = args[3];
}
} else {
scope = args[1];
defaultValue = args[2];
}
}
defaultValue?: ConfigPathValue<T>,
): Config | ConfigPathValue<T> {
return defaultValue === undefined
? workspace
.getConfiguration(section === undefined ? undefined : extensionId, scope)
.get<T>(section === undefined ? extensionId : section)!
.get<ConfigPathValue<T>>(section === undefined ? extensionId : section)!
: workspace
.getConfiguration(section === undefined ? undefined : extensionId, scope)
.get<T>(section === undefined ? extensionId : section, defaultValue)!;
.get<ConfigPathValue<T>>(section === undefined ? extensionId : section, defaultValue)!;
}
getAny<T>(section: string, scope?: ConfigurationScope | null): T | undefined;
@ -146,46 +100,11 @@ export class Configuration {
: workspace.getConfiguration(undefined, scope).get<T>(section, defaultValue);
}
changed<S1 extends keyof Config>(e: ConfigurationChangeEvent, s1: S1, scope?: ConfigurationScope | null): boolean;
changed<S1 extends keyof Config, S2 extends keyof Config[S1]>(
e: ConfigurationChangeEvent,
s1: S1,
s2: S2,
scope?: ConfigurationScope | null,
): boolean;
changed<S1 extends keyof Config, S2 extends keyof Config[S1], S3 extends keyof Config[S1][S2]>(
changed<T extends ConfigPath>(
e: ConfigurationChangeEvent,
s1: S1,
s2: S2,
s3: S3,
scope?: ConfigurationScope | 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, scope?: ConfigurationScope | null): boolean;
changed(e: ConfigurationChangeEvent, ...args: any[]) {
let section: string = args[0];
let scope: ConfigurationScope | 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];
scope = args[4];
} else {
scope = args[3];
}
} else {
scope = args[2];
}
} else {
scope = args[1];
}
section: T,
scope?: ConfigurationScope | null | undefined,
): boolean {
return e.affectsConfiguration(`${extensionId}.${section}`, scope!);
}
@ -193,55 +112,12 @@ export class Configuration {
return e === this.initializingChangeEvent;
}
inspect<S1 extends keyof Config>(
s1: S1,
scope?: ConfigurationScope | null,
): ConfigInspection<Config[S1]> | undefined;
inspect<S1 extends keyof Config, S2 extends keyof Config[S1]>(
s1: S1,
s2: S2,
inspect<T extends ConfigPath>(
section: T,
scope?: ConfigurationScope | null,
): ConfigInspection<Config[S1][S2]> | undefined;
inspect<S1 extends keyof Config, S2 extends keyof Config[S1], S3 extends keyof Config[S1][S2]>(
s1: S1,
s2: S2,
s3: S3,
scope?: ConfigurationScope | null,
): ConfigInspection<Config[S1][S2][S3]> | 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,
scope?: ConfigurationScope | null,
): ConfigInspection<Config[S1][S2][S3][S4]> | 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];
}
): ConfigInspection<ConfigPathValue<T>> | undefined {
return workspace
.getConfiguration(section === undefined ? undefined : extensionId, resource)
.getConfiguration(section === undefined ? undefined : extensionId, scope)
.inspect(section === undefined ? extensionId : section);
}
@ -249,68 +125,18 @@ export class Configuration {
return workspace.getConfiguration(undefined, scope).inspect<T>(section);
}
migrate<S1 extends keyof Config>(
async migrate<T extends ConfigPath>(
from: string,
to1: S1,
options: { fallbackValue?: Config[S1]; migrationFn?(value: any): Config[S1] },
): Promise<boolean>;
migrate<S1 extends keyof Config, S2 extends keyof Config[S1]>(
from: string,
to1: S1,
to2: S2,
options: { fallbackValue?: Config[S1][S2]; migrationFn?(value: any): Config[S1][S2] },
): Promise<boolean>;
migrate<S1 extends keyof Config, S2 extends keyof Config[S1], S3 extends keyof Config[S1][S2]>(
from: string,
to1: S1,
to2: S2,
to3: S3,
options: { fallbackValue?: Config[S1][S2][S3]; migrationFn?(value: any): Config[S1][S2][S3] },
): Promise<boolean>;
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<boolean>;
async migrate(from: string, ...args: any[]): Promise<boolean> {
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 = {};
}
to: T,
options: { fallbackValue?: ConfigPathValue<T>; migrationFn?(value: any): ConfigPathValue<T> },
): Promise<boolean> {
const inspection = configuration.inspect(from as any);
if (inspection === undefined) return false;
let migrated = false;
if (inspection.globalValue !== undefined) {
await this.update(
to as any,
to,
options.migrationFn != null ? options.migrationFn(inspection.globalValue) : inspection.globalValue,
ConfigurationTarget.Global,
);
@ -326,7 +152,7 @@ export class Configuration {
if (inspection.workspaceValue !== undefined) {
await this.update(
to as any,
to,
options.migrationFn != null
? options.migrationFn(inspection.workspaceValue)
: inspection.workspaceValue,
@ -344,7 +170,7 @@ export class Configuration {
if (inspection.workspaceFolderValue !== undefined) {
await this.update(
to as any,
to,
options.migrationFn != null
? options.migrationFn(inspection.workspaceFolderValue)
: inspection.workspaceFolderValue,
@ -361,77 +187,26 @@ export class Configuration {
}
if (!migrated && options.fallbackValue !== undefined) {
await this.update(to as any, options.fallbackValue, ConfigurationTarget.Global);
await this.update(to, options.fallbackValue, ConfigurationTarget.Global);
migrated = true;
}
return migrated;
}
migrateIfMissing<S1 extends keyof Config>(
from: string,
to1: S1,
options: { migrationFn?(value: any): Config[S1] },
): Promise<void>;
migrateIfMissing<S1 extends keyof Config, S2 extends keyof Config[S1]>(
from: string,
to1: S1,
to2: S2,
options: { migrationFn?(value: any): Config[S1][S2] },
): Promise<void>;
migrateIfMissing<S1 extends keyof Config, S2 extends keyof Config[S1], S3 extends keyof Config[S1][S2]>(
from: string,
to1: S1,
to2: S2,
to3: S3,
options: { migrationFn?(value: any): Config[S1][S2][S3] },
): Promise<void>;
migrateIfMissing<
S1 extends keyof Config,
S2 extends keyof Config[S1],
S3 extends keyof Config[S1][S2],
S4 extends keyof Config[S1][S2][S3]
>(
async migrateIfMissing<T extends ConfigPath>(
from: string,
to1: S1,
to2: S2,
to3: S3,
to4: S4,
options: { migrationFn?(value: any): Config[S1][S2][S3][S4] },
): Promise<void>;
async migrateIfMissing(from: string, ...args: any[]): Promise<void> {
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<TFrom, TTo>(from: string, to: string, options: { migrationFn?(value: TFrom): TTo } = {}) {
to: T,
options: { migrationFn?(value: any): ConfigPathValue<T> },
): Promise<void> {
const fromInspection = configuration.inspect(from as any);
if (fromInspection === undefined) return;
const toInspection = configuration.inspect(to as any);
const toInspection = configuration.inspect(to);
if (fromInspection.globalValue !== undefined) {
if (toInspection === undefined || toInspection.globalValue === undefined) {
await this.update(
to as any,
to,
options.migrationFn != null
? options.migrationFn(fromInspection.globalValue)
: fromInspection.globalValue,
@ -450,7 +225,7 @@ export class Configuration {
if (fromInspection.workspaceValue !== undefined) {
if (toInspection === undefined || toInspection.workspaceValue === undefined) {
await this.update(
to as any,
to,
options.migrationFn != null
? options.migrationFn(fromInspection.workspaceValue)
: fromInspection.workspaceValue,
@ -469,7 +244,7 @@ export class Configuration {
if (fromInspection.workspaceFolderValue !== undefined) {
if (toInspection === undefined || toInspection.workspaceFolderValue === undefined) {
await this.update(
to as any,
to,
options.migrationFn != null
? options.migrationFn(fromInspection.workspaceFolderValue)
: fromInspection.workspaceFolderValue,
@ -486,76 +261,15 @@ export class Configuration {
}
}
name<S1 extends keyof Config>(s1: S1): string;
name<S1 extends keyof Config, S2 extends keyof Config[S1]>(s1: S1, s2: S2): string;
name<S1 extends keyof Config, S2 extends keyof Config[S1], S3 extends keyof Config[S1][S2]>(
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('.');
name<T extends ConfigPath>(section: T): string {
return section;
}
update<S1 extends keyof Config>(s1: S1, value: Config[S1] | undefined, target: ConfigurationTarget): Thenable<void>;
update<S1 extends keyof Config, S2 extends keyof Config[S1]>(
s1: S1,
s2: S2,
value: Config[S1][S2] | undefined,
update<T extends ConfigPath>(
section: T,
value: ConfigPathValue<T> | undefined,
target: ConfigurationTarget,
): Thenable<void>;
update<S1 extends keyof Config, S2 extends keyof Config[S1], S3 extends keyof Config[S1][S2]>(
s1: S1,
s2: S2,
s3: S3,
value: Config[S1][S2][S3] | undefined,
target: ConfigurationTarget,
): Thenable<void>;
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<void>;
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];
}
): Thenable<void> {
return workspace.getConfiguration(extensionId).update(section, value, target);
}
@ -565,55 +279,18 @@ export class Configuration {
.update(section, value, target);
}
updateEffective<S1 extends keyof Config>(s1: S1, value: Config[S1]): Thenable<void>;
updateEffective<S1 extends keyof Config, S2 extends keyof Config[S1]>(
s1: S1,
s2: S2,
value: Config[S1][S2],
): Thenable<void>;
updateEffective<S1 extends keyof Config, S2 extends keyof Config[S1], S3 extends keyof Config[S1][S2]>(
s1: S1,
s2: S2,
s3: S3,
value: Config[S1][S2][S3],
): Thenable<void>;
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<void>;
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)!;
updateEffective<T extends ConfigPath>(section: T, value: ConfigPathValue<T> | undefined): Thenable<void> {
const inspect = configuration.inspect(section)!;
if (inspect.workspaceFolderValue !== undefined) {
if (value === inspect.workspaceFolderValue) return Promise.resolve(undefined);
return configuration.update(section as any, value, ConfigurationTarget.WorkspaceFolder);
return configuration.update(section, value, ConfigurationTarget.WorkspaceFolder);
}
if (inspect.workspaceValue !== undefined) {
if (value === inspect.workspaceValue) return Promise.resolve(undefined);
return configuration.update(section as any, value, ConfigurationTarget.Workspace);
return configuration.update(section, value, ConfigurationTarget.Workspace);
}
if (inspect.globalValue === value || (inspect.globalValue === undefined && value === inspect.defaultValue)) {
@ -621,7 +298,7 @@ export class Configuration {
}
return configuration.update(
section as any,
section,
Objects.areEquivalent(value, inspect.defaultValue) ? undefined : value,
ConfigurationTarget.Global,
);
@ -629,3 +306,28 @@ export class Configuration {
}
export const configuration = new Configuration();
type PathImpl<T, Key extends keyof T> = Key extends string
? T[Key] extends Record<string, any>
?
| `${Key}.${PathImpl<T[Key], Exclude<keyof T[Key], keyof any[]>> & string}`
| `${Key}.${Exclude<keyof T[Key], keyof any[]> & string}`
: never
: never;
type PathImpl2<T> = PathImpl<T, keyof T> | keyof T;
type Path<T> = PathImpl2<T> extends string | keyof T ? PathImpl2<T> : keyof T;
type PathValue<T, P extends Path<T>> = P extends `${infer Key}.${infer Rest}`
? Key extends keyof T
? Rest extends Path<T[Key]>
? PathValue<T[Key], Rest>
: never
: never
: P extends keyof T
? T[P]
: never;
type ConfigPath = Path<Config>;
type ConfigPathValue<P extends ConfigPath> = PathValue<Config, P>;

+ 5
- 5
src/container.ts Vedi File

@ -94,7 +94,7 @@ export class Container {
context.subscriptions.push(
configuration.onDidChange(e => {
if (!configuration.changed(e, 'terminalLinks', 'enabled')) return;
if (!configuration.changed(e, 'terminalLinks.enabled')) return;
this._terminalLinks?.dispose();
if (Container.config.terminalLinks.enabled) {
@ -356,7 +356,7 @@ export class Container {
private static applyMode(config: Config) {
if (!config.mode.active) return config;
const mode = config.modes[config.mode.active];
const mode = config.modes?.[config.mode.active];
if (mode == null) return config;
if (mode.annotations != null) {
@ -410,11 +410,11 @@ export class Container {
this._configsAffectedByMode = [
`gitlens.${configuration.name('mode')}`,
`gitlens.${configuration.name('modes')}`,
`gitlens.${configuration.name('blame', 'toggleMode')}`,
`gitlens.${configuration.name('changes', 'toggleMode')}`,
`gitlens.${configuration.name('blame.toggleMode')}`,
`gitlens.${configuration.name('changes.toggleMode')}`,
`gitlens.${configuration.name('codeLens')}`,
`gitlens.${configuration.name('currentLine')}`,
`gitlens.${configuration.name('heatmap', 'toggleMode')}`,
`gitlens.${configuration.name('heatmap.toggleMode')}`,
`gitlens.${configuration.name('hovers')}`,
`gitlens.${configuration.name('statusBar')}`,
];

+ 2
- 2
src/git/gitService.ts Vedi File

@ -249,7 +249,7 @@ export class GitService implements Disposable {
PullRequestDateFormatting.reset();
}
if (configuration.changed(e, 'views', 'contributors', 'showAllBranches')) {
if (configuration.changed(e, 'views.contributors.showAllBranches')) {
this._contributorsCache.clear();
}
}
@ -369,7 +369,7 @@ export class GitService implements Disposable {
private async repositorySearch(folder: WorkspaceFolder): Promise<Repository[]> {
const cc = Logger.getCorrelationContext();
const { uri } = folder;
const depth = configuration.get('advanced', 'repositorySearchDepth', uri);
const depth = configuration.get('advanced.repositorySearchDepth', uri);
Logger.log(cc, `searching (depth=${depth})...`);

+ 1
- 4
src/hovers/lineHoverController.ts Vedi File

@ -37,10 +37,7 @@ export class LineHoverController implements Disposable {
}
private onConfigurationChanged(e: ConfigurationChangeEvent) {
if (
!configuration.changed(e, 'hovers', 'enabled') &&
!configuration.changed(e, 'hovers', 'currentLine', 'enabled')
) {
if (!configuration.changed(e, 'hovers.enabled') && !configuration.changed(e, 'hovers.currentLine.enabled')) {
return;
}

+ 4
- 4
src/messages.ts Vedi File

@ -185,7 +185,7 @@ export class Messages {
): Promise<MessageItem | undefined> {
Logger.log(`ShowMessage(${type}, '${message}', ${suppressionKey}, ${JSON.stringify(dontShowAgain)})`);
if (suppressionKey !== undefined && configuration.get('advanced', 'messages', suppressionKey)) {
if (suppressionKey !== undefined && configuration.get(`advanced.messages.${suppressionKey}` as const)) {
Logger.log(
`ShowMessage(${type}, '${message}', ${suppressionKey}, ${JSON.stringify(dontShowAgain)}) skipped`,
);
@ -231,16 +231,16 @@ export class Messages {
}
private static suppressedMessage(suppressionKey: SuppressedMessages) {
const messages: Record<string, boolean | undefined> = configuration.get('advanced', 'messages');
const messages = configuration.get('advanced.messages');
messages[suppressionKey] = true;
for (const [key, value] of Object.entries(messages)) {
if (value !== true) {
messages[key] = undefined;
delete messages[key as keyof typeof messages];
}
}
return configuration.update('advanced', 'messages', messages as any, ConfigurationTarget.Global);
return configuration.update('advanced.messages', messages, ConfigurationTarget.Global);
}
}

+ 1
- 1
src/quickpicks.ts Vedi File

@ -3,7 +3,7 @@
import { configuration } from './configuration';
export function getQuickPickIgnoreFocusOut() {
return !configuration.get('advanced', 'quickPick', 'closeOnFocusOut');
return !configuration.get('advanced.quickPick.closeOnFocusOut');
}
export * from './quickpicks/quickPicksItems';

+ 1
- 1
src/quickpicks/commitPicker.ts Vedi File

@ -71,7 +71,7 @@ export namespace CommitPicker {
quickpick.enabled = false;
try {
log = await (await log)?.more?.(configuration.get('advanced', 'maxListItems'));
log = await (await log)?.more?.(configuration.get('advanced.maxListItems'));
const items = getItems(log);
let activeIndex = -1;

+ 8
- 5
src/quickpicks/modePicker.ts Vedi File

@ -9,13 +9,16 @@ export interface ModesQuickPickItem extends QuickPickItem {
export namespace ModePicker {
export async function show(): Promise<ModesQuickPickItem | undefined> {
const modes = Object.keys(Container.config.modes);
if (modes.length === 0) return undefined;
if (Container.config.modes == null) return undefined;
const modes = Container.config.modes;
const modeKeys = Object.keys(modes);
if (modeKeys.length === 0) return undefined;
const mode = Container.config.mode.active;
const items = modes.map(key => {
const modeCfg = Container.config.modes[key];
const items = modeKeys.map(key => {
const modeCfg = modes[key];
const item: ModesQuickPickItem = {
label: `${mode === key ? '$(check)\u00a0\u00a0' : '\u00a0\u00a0\u00a0\u00a0\u00a0'}${
modeCfg.name
@ -28,7 +31,7 @@ export namespace ModePicker {
if (mode) {
items.splice(0, 0, {
label: `Exit ${Container.config.modes[mode].name} mode`,
label: `Exit ${modes[mode].name} mode`,
key: undefined,
});
}

+ 5
- 5
src/statusbar/statusBarController.ts Vedi File

@ -44,7 +44,7 @@ export class StatusBarController implements Disposable {
if (configuration.changed(e, 'mode')) {
const mode =
Container.config.mode.active && Container.config.mode.statusBar.enabled
? Container.config.modes[Container.config.mode.active]
? Container.config.modes?.[Container.config.mode.active]
: undefined;
if (mode?.statusBarItemName) {
const alignment =
@ -52,7 +52,7 @@ export class StatusBarController implements Disposable {
? StatusBarAlignment.Right
: StatusBarAlignment.Left;
if (configuration.changed(e, 'mode', 'statusBar', 'alignment')) {
if (configuration.changed(e, 'mode.statusBar.alignment')) {
if (this._statusBarMode?.alignment !== alignment) {
this._statusBarMode?.dispose();
this._statusBarMode = undefined;
@ -78,7 +78,7 @@ export class StatusBarController implements Disposable {
const alignment =
Container.config.statusBar.alignment !== 'left' ? StatusBarAlignment.Right : StatusBarAlignment.Left;
if (configuration.changed(e, 'statusBar', 'alignment')) {
if (configuration.changed(e, 'statusBar.alignment')) {
if (this._statusBarBlame?.alignment !== alignment) {
this._statusBarBlame?.dispose();
this._statusBarBlame = undefined;
@ -90,13 +90,13 @@ export class StatusBarController implements Disposable {
window.createStatusBarItem(alignment, alignment === StatusBarAlignment.Right ? 1000 : 0);
this._statusBarBlame.command = Container.config.statusBar.command;
if (configuration.changed(e, 'statusBar', 'enabled')) {
if (configuration.changed(e, 'statusBar.enabled')) {
Container.lineTracker.start(
this,
Container.lineTracker.onDidChangeActiveLines(this.onActiveLinesChanged, this),
);
}
} else if (configuration.changed(e, 'statusBar', 'enabled')) {
} else if (configuration.changed(e, 'statusBar.enabled')) {
Container.lineTracker.stop(this);
this._statusBarBlame?.dispose();

+ 3
- 4
src/trackers/documentTracker.ts Vedi File

@ -93,16 +93,15 @@ export class DocumentTracker implements Disposable {
// Only rest the cached state if we aren't initializing
if (
!configuration.initializing(e) &&
(configuration.changed(e, 'blame', 'ignoreWhitespace') ||
configuration.changed(e, 'advanced', 'caching', 'enabled'))
(configuration.changed(e, 'blame.ignoreWhitespace') || configuration.changed(e, 'advanced.caching.enabled'))
) {
for (const d of this._documentMap.values()) {
(await d).reset('config');
}
}
if (configuration.changed(e, 'advanced', 'blame', 'delayAfterEdit')) {
this._dirtyIdleTriggerDelay = configuration.get('advanced', 'blame', 'delayAfterEdit');
if (configuration.changed(e, 'advanced.blame.delayAfterEdit')) {
this._dirtyIdleTriggerDelay = configuration.get('advanced.blame.delayAfterEdit');
this._dirtyIdleTriggeredDebounced = undefined;
}
}

+ 6
- 8
src/views/branchesView.ts Vedi File

@ -333,28 +333,26 @@ export class BranchesView extends ViewBase
}
private setLayout(layout: ViewBranchesLayout) {
return configuration.updateEffective('views', this.configKey, 'branches', 'layout', layout);
return configuration.updateEffective(`views.${this.configKey}.branches.layout` as const, layout);
}
private setFilesLayout(layout: ViewFilesLayout) {
return configuration.updateEffective('views', this.configKey, 'files', 'layout', layout);
return configuration.updateEffective(`views.${this.configKey}.files.layout` as const, layout);
}
private setShowAvatars(enabled: boolean) {
return configuration.updateEffective('views', this.configKey, 'avatars', enabled);
return configuration.updateEffective(`views.${this.configKey}.avatars` as const, enabled);
}
private setShowBranchComparison(enabled: boolean) {
return configuration.updateEffective(
'views',
this.configKey,
'showBranchComparison',
`views.${this.configKey}.showBranchComparison` as const,
enabled ? ViewShowBranchComparison.Branch : false,
);
}
private async setShowBranchPullRequest(enabled: boolean) {
await configuration.updateEffective('views', this.configKey, 'pullRequests', 'showForBranches', enabled);
await configuration.updateEffective('views', this.configKey, 'pullRequests', 'enabled', enabled);
await configuration.updateEffective(`views.${this.configKey}.pullRequests.showForBranches` as const, enabled);
await configuration.updateEffective(`views.${this.configKey}.pullRequests.enabled` as const, enabled);
}
}

+ 5
- 7
src/views/commitsView.ts Vedi File

@ -371,7 +371,7 @@ export class CommitsView extends ViewBase {
}
private setFilesLayout(layout: ViewFilesLayout) {
return configuration.updateEffective('views', this.configKey, 'files', 'layout', layout);
return configuration.updateEffective(`views.${this.configKey}.files.layout` as const, layout);
}
private setMyCommitsOnly(enabled: boolean) {
@ -381,20 +381,18 @@ export class CommitsView extends ViewBase {
}
private setShowAvatars(enabled: boolean) {
return configuration.updateEffective('views', this.configKey, 'avatars', enabled);
return configuration.updateEffective(`views.${this.configKey}.avatars` as const, enabled);
}
private setShowBranchComparison(enabled: boolean) {
return configuration.updateEffective(
'views',
this.configKey,
'showBranchComparison',
`views.${this.configKey}.showBranchComparison` as const,
enabled ? ViewShowBranchComparison.Working : false,
);
}
private async setShowBranchPullRequest(enabled: boolean) {
await configuration.updateEffective('views', this.configKey, 'pullRequests', 'showForBranches', enabled);
await configuration.updateEffective('views', this.configKey, 'pullRequests', 'enabled', enabled);
await configuration.updateEffective(`views.${this.configKey}.pullRequests.showForBranches` as const, enabled);
await configuration.updateEffective(`views.${this.configKey}.pullRequests.enabled` as const, enabled);
}
}

+ 3
- 3
src/views/contributorsView.ts Vedi File

@ -204,14 +204,14 @@ export class ContributorsView extends ViewBase
}
private setFilesLayout(layout: ViewFilesLayout) {
return configuration.updateEffective('views', this.configKey, 'files', 'layout', layout);
return configuration.updateEffective(`views.${this.configKey}.files.layout` as const, layout);
}
private setShowAllBranches(enabled: boolean) {
return configuration.updateEffective('views', this.configKey, 'showAllBranches', enabled);
return configuration.updateEffective(`views.${this.configKey}.showAllBranches` as const, enabled);
}
private setShowAvatars(enabled: boolean) {
return configuration.updateEffective('views', this.configKey, 'avatars', enabled);
return configuration.updateEffective(`views.${this.configKey}.avatars` as const, enabled);
}
}

+ 5
- 5
src/views/fileHistoryView.ts Vedi File

@ -94,8 +94,8 @@ export class FileHistoryView extends ViewBase
!configuration.changed(e, 'defaultDateStyle') &&
!configuration.changed(e, 'defaultGravatarsStyle') &&
!configuration.changed(e, 'defaultTimeFormat') &&
!configuration.changed(e, 'advanced', 'fileHistoryFollowsRenames') &&
!configuration.changed(e, 'advanced', 'fileHistoryShowAllBranches')
!configuration.changed(e, 'advanced.fileHistoryFollowsRenames') &&
!configuration.changed(e, 'advanced.fileHistoryShowAllBranches')
) {
return false;
}
@ -162,14 +162,14 @@ export class FileHistoryView extends ViewBase
}
private setRenameFollowing(enabled: boolean) {
return configuration.updateEffective('advanced', 'fileHistoryFollowsRenames', enabled);
return configuration.updateEffective('advanced.fileHistoryFollowsRenames', enabled);
}
private setShowAllBranches(enabled: boolean) {
return configuration.updateEffective('advanced', 'fileHistoryShowAllBranches', enabled);
return configuration.updateEffective('advanced.fileHistoryShowAllBranches', enabled);
}
private setShowAvatars(enabled: boolean) {
return configuration.updateEffective('views', this.configKey, 'avatars', enabled);
return configuration.updateEffective(`views.${this.configKey}.avatars` as const, enabled);
}
}

+ 1
- 1
src/views/lineHistoryView.ts Vedi File

@ -93,6 +93,6 @@ export class LineHistoryView extends ViewBase
}
private setShowAvatars(enabled: boolean) {
return configuration.updateEffective('views', this.configKey, 'avatars', enabled);
return configuration.updateEffective(`views.${this.configKey}.avatars` as const, enabled);
}
}

+ 1
- 1
src/views/nodes/fileHistoryNode.ts Vedi File

@ -163,7 +163,7 @@ export class FileHistoryNode extends SubscribeableViewNode impl
repo.onDidChangeFileSystem(this.onFileSystemChanged, this),
repo.startWatchingFileSystem(),
configuration.onDidChange(e => {
if (configuration.changed(e, 'advanced', 'fileHistoryFollowsRenames')) {
if (configuration.changed(e, 'advanced.fileHistoryFollowsRenames')) {
this.view.resetNodeLastKnownLimit(this);
}
}),

+ 6
- 6
src/views/remotesView.ts Vedi File

@ -207,7 +207,7 @@ export class RemotesView extends ViewBase {
!configuration.changed(e, 'defaultDateStyle') &&
!configuration.changed(e, 'defaultGravatarsStyle') &&
!configuration.changed(e, 'defaultTimeFormat') &&
!configuration.changed(e, 'integrations', 'enabled') &&
!configuration.changed(e, 'integrations.enabled') &&
!configuration.changed(e, 'sortBranchesBy')
) {
return false;
@ -378,19 +378,19 @@ export class RemotesView extends ViewBase {
}
private setLayout(layout: ViewBranchesLayout) {
return configuration.updateEffective('views', this.configKey, 'branches', 'layout', layout);
return configuration.updateEffective(`views.${this.configKey}.branches.layout` as const, layout);
}
private setFilesLayout(layout: ViewFilesLayout) {
return configuration.updateEffective('views', this.configKey, 'files', 'layout', layout);
return configuration.updateEffective(`views.${this.configKey}.files.layout` as const, layout);
}
private setShowAvatars(enabled: boolean) {
return configuration.updateEffective('views', this.configKey, 'avatars', enabled);
return configuration.updateEffective(`views.${this.configKey}.avatars` as const, enabled);
}
private async setShowBranchPullRequest(enabled: boolean) {
await configuration.updateEffective('views', this.configKey, 'pullRequests', 'showForBranches', enabled);
await configuration.updateEffective('views', this.configKey, 'pullRequests', 'enabled', enabled);
await configuration.updateEffective(`views.${this.configKey}.pullRequests.showForBranches` as const, enabled);
await configuration.updateEffective(`views.${this.configKey}.pullRequests.enabled` as const, enabled);
}
}

+ 15
- 20
src/views/repositoriesView.ts Vedi File

@ -250,7 +250,7 @@ export class RepositoriesView extends ViewBase
return true;
}
protected onConfigurationChanged(e: ConfigurationChangeEvent) {
if (configuration.changed(e, 'views', this.configKey, 'autoRefresh')) {
if (configuration.changed(e, `views.${this.configKey}.autoRefresh` as const)) {
void this.setAutoRefresh(Container.config.views.repositories.autoRefresh);
}
@ -670,32 +670,27 @@ export class RepositoriesView extends ViewBase
}
private setBranchesLayout(layout: ViewBranchesLayout) {
return configuration.updateEffective('views', this.configKey, 'branches', 'layout', layout);
return configuration.updateEffective(`views.${this.configKey}.branches.layout` as const, layout);
}
private setFilesLayout(layout: ViewFilesLayout) {
return configuration.updateEffective('views', this.configKey, 'files', 'layout', layout);
return configuration.updateEffective(`views.${this.configKey}.files.layout` as const, layout);
}
private setShowAvatars(enabled: boolean) {
return configuration.updateEffective('views', this.configKey, 'avatars', enabled);
return configuration.updateEffective(`views.${this.configKey}.avatars` as const, enabled);
}
private setShowBranchComparison(enabled: boolean) {
return configuration.updateEffective(
'views',
this.configKey,
'showBranchComparison',
`views.${this.configKey}.showBranchComparison` as const,
enabled ? ViewShowBranchComparison.Working : false,
);
}
private setBranchShowBranchComparison(enabled: boolean) {
return configuration.updateEffective(
'views',
this.configKey,
'branches',
'showBranchComparison',
`views.${this.configKey}.branches.showBranchComparison` as const,
enabled ? ViewShowBranchComparison.Branch : false,
);
}
@ -712,7 +707,7 @@ export class RepositoriesView extends ViewBase
| 'showUpstreamStatus',
enabled: boolean,
) {
return configuration.updateEffective('views', this.configKey, key, enabled);
return configuration.updateEffective(`views.${this.configKey}.${key}` as const, enabled);
}
toggleSectionByNode(
@ -729,15 +724,15 @@ export class RepositoriesView extends ViewBase
enabled: boolean,
) {
if (node instanceof BranchesNode) {
return configuration.updateEffective('views', this.configKey, 'showBranches', enabled);
return configuration.updateEffective(`views.${this.configKey}.showBranches` as const, enabled);
}
if (node instanceof BranchNode) {
return configuration.updateEffective('views', this.configKey, 'showCommits', enabled);
return configuration.updateEffective(`views.${this.configKey}.showCommits` as const, enabled);
}
if (node instanceof BranchTrackingStatusNode) {
return configuration.updateEffective('views', this.configKey, 'showUpstreamStatus', enabled);
return configuration.updateEffective(`views.${this.configKey}.showUpstreamStatus` as const, enabled);
}
if (node instanceof CompareBranchNode) {
@ -745,23 +740,23 @@ export class RepositoriesView extends ViewBase
}
if (node instanceof ContributorsNode) {
return configuration.updateEffective('views', this.configKey, 'showContributors', enabled);
return configuration.updateEffective(`views.${this.configKey}.showContributors` as const, enabled);
}
if (node instanceof ReflogNode) {
return configuration.updateEffective('views', this.configKey, 'showIncomingActivity', enabled);
return configuration.updateEffective(`views.${this.configKey}.showIncomingActivity` as const, enabled);
}
if (node instanceof RemotesNode) {
return configuration.updateEffective('views', this.configKey, 'showRemotes', enabled);
return configuration.updateEffective(`views.${this.configKey}.showRemotes` as const, enabled);
}
if (node instanceof StashesNode) {
return configuration.updateEffective('views', this.configKey, 'showStashes', enabled);
return configuration.updateEffective(`views.${this.configKey}.showStashes` as const, enabled);
}
if (node instanceof TagsNode) {
return configuration.updateEffective('views', this.configKey, 'showTags', enabled);
return configuration.updateEffective(`views.${this.configKey}.showTags` as const, enabled);
}
return Promise.resolve();

+ 2
- 2
src/views/searchAndCompareView.ts Vedi File

@ -466,7 +466,7 @@ export class SearchAndCompareView extends ViewBase
}
private setFilesLayout(layout: ViewFilesLayout) {
return configuration.updateEffective('views', this.configKey, 'files', 'layout', layout);
return configuration.updateEffective(`views.${this.configKey}.files.layout` as const, layout);
}
private setKeepResults(enabled: boolean) {
@ -475,7 +475,7 @@ export class SearchAndCompareView extends ViewBase
}
private setShowAvatars(enabled: boolean) {
return configuration.updateEffective('views', this.configKey, 'avatars', enabled);
return configuration.updateEffective(`views.${this.configKey}.avatars` as const, enabled);
}
private pin(node: CompareResultsNode | SearchResultsNode) {

+ 1
- 1
src/views/stashesView.ts Vedi File

@ -219,6 +219,6 @@ export class StashesView extends ViewBase {
}
private setFilesLayout(layout: ViewFilesLayout) {
return configuration.updateEffective('views', this.configKey, 'files', 'layout', layout);
return configuration.updateEffective(`views.${this.configKey}.files.layout` as const, layout);
}
}

+ 3
- 3
src/views/tagsView.ts Vedi File

@ -240,14 +240,14 @@ export class TagsView extends ViewBase {
}
private setLayout(layout: ViewBranchesLayout) {
return configuration.updateEffective('views', this.configKey, 'branches', 'layout', layout);
return configuration.updateEffective(`views.${this.configKey}.branches.layout` as const, layout);
}
private setFilesLayout(layout: ViewFilesLayout) {
return configuration.updateEffective('views', this.configKey, 'files', 'layout', layout);
return configuration.updateEffective(`views.${this.configKey}.files.layout` as const, layout);
}
private setShowAvatars(enabled: boolean) {
return configuration.updateEffective('views', this.configKey, 'avatars', enabled);
return configuration.updateEffective(`views.${this.configKey}.avatars` as const, enabled);
}
}

+ 3
- 22
src/views/viewBase.ts Vedi File

@ -3,12 +3,10 @@ import {
CancellationToken,
commands,
ConfigurationChangeEvent,
ConfigurationTarget,
Disposable,
Event,
EventEmitter,
MarkdownString,
MessageItem,
TreeDataProvider,
TreeItem,
TreeItemCollapsibleState,
@ -46,7 +44,7 @@ import { RemotesView } from './remotesView';
import { RepositoriesView } from './repositoriesView';
import { SearchAndCompareView } from './searchAndCompareView';
import { StashesView } from './stashesView';
import { debug, Functions, log, Promises, Strings } from '../system';
import { debug, Functions, log, Promises } from '../system';
import { TagsView } from './tagsView';
export type View =
@ -161,9 +159,9 @@ export abstract class ViewBase<
protected filterConfigurationChanged(e: ConfigurationChangeEvent) {
if (!configuration.changed(e, 'views')) return false;
if (configuration.changed(e, 'views', this.configKey)) return true;
if (configuration.changed(e, `views.${this.configKey}` as const)) return true;
for (const key of viewsCommonConfigKeys) {
if (configuration.changed(e, 'views', key)) return true;
if (configuration.changed(e, `views.${key}` as const)) return true;
}
return false;
@ -502,23 +500,6 @@ export abstract class ViewBase<
void (await commands.executeCommand(`${this.id}.focus`));
} catch (ex) {
Logger.error(ex);
const section = Strings.splitSingle(this.id, '.')[1];
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (!configuration.get(section as any, 'enabled')) {
const actions: MessageItem[] = [{ title: 'Enable' }, { title: 'Cancel', isCloseAffordance: true }];
const result = await window.showErrorMessage(
`Unable to show the ${this.name} view since it's currently disabled. Would you like to enable it?`,
...actions,
);
if (result === actions[0]) {
await configuration.update(section as any, 'enabled', true, ConfigurationTarget.Global);
void (await commands.executeCommand(`${this.id}.focus`));
}
}
}
}

+ 1
- 1
src/views/viewCommands.ts Vedi File

@ -587,7 +587,7 @@ export class ViewCommands {
@debug()
private setShowRelativeDateMarkers(enabled: boolean) {
return configuration.updateEffective('views', 'showRelativeDateMarkers', enabled);
return configuration.updateEffective('views.showRelativeDateMarkers', enabled);
}
@debug()

+ 2
- 2
src/webviews/webviewBase.ts Vedi File

@ -212,10 +212,10 @@ export abstract class WebviewBase implements Disposable {
let includePullRequest = false;
switch (params.key) {
case configuration.name('currentLine', 'format'):
case configuration.name('currentLine.format'):
includePullRequest = Container.config.currentLine.pullRequests.enabled;
break;
case configuration.name('statusBar', 'format'):
case configuration.name('statusBar.format'):
includePullRequest = Container.config.statusBar.pullRequests.enabled;
break;
}

Caricamento…
Annulla
Salva