소스 검색

Changes configuration to have better type safety

main
Eric Amodio 5 년 전
부모
커밋
798213df5f
27개의 변경된 파일520개의 추가작업 그리고 239개의 파일을 삭제
  1. +9
    -9
      src/annotations/fileAnnotationController.ts
  2. +2
    -2
      src/annotations/lineAnnotationController.ts
  3. +4
    -5
      src/codelens/codeLensController.ts
  4. +1
    -1
      src/codelens/codeLensProvider.ts
  5. +4
    -10
      src/commands/gitCommands.ts
  6. +1
    -5
      src/commands/resetSuppressedWarnings.ts
  7. +3
    -3
      src/commands/switchMode.ts
  8. +380
    -40
      src/configuration.ts
  9. +25
    -28
      src/container.ts
  10. +17
    -18
      src/extension.ts
  11. +6
    -10
      src/git/gitService.ts
  12. +3
    -3
      src/git/models/commit.ts
  13. +4
    -10
      src/git/models/repository.ts
  14. +2
    -2
      src/hovers/lineHoverController.ts
  15. +3
    -7
      src/messages.ts
  16. +1
    -1
      src/quickpicks/commonQuickPicks.ts
  17. +6
    -6
      src/statusbar/statusBarController.ts
  18. +4
    -5
      src/trackers/documentTracker.ts
  19. +5
    -5
      src/views/compareView.ts
  20. +7
    -10
      src/views/fileHistoryView.ts
  21. +7
    -10
      src/views/lineHistoryView.ts
  22. +6
    -9
      src/views/repositoriesView.ts
  23. +5
    -5
      src/views/searchView.ts
  24. +3
    -3
      src/views/viewBase.ts
  25. +5
    -25
      src/webviews/helpers.ts
  26. +2
    -2
      src/webviews/settingsWebview.ts
  27. +5
    -5
      src/webviews/webviewBase.ts

+ 9
- 9
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()) {

+ 2
- 2
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();

+ 4
- 5
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');

+ 1
- 1
src/codelens/codeLensProvider.ts 파일 보기

@ -117,7 +117,7 @@ export class GitCodeLensProvider implements CodeLensProvider {
}
}
const cfg = configuration.get<CodeLensConfig>(configuration.name('codeLens').value, document.uri);
const cfg = configuration.get('codeLens', document.uri);
let languageScope =
cfg.scopesByLanguage &&

+ 4
- 10
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<boolean>(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<boolean>(
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<string[]>(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);
}

+ 1
- 5
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);
}
}

+ 3
- 3
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);
}
}

+ 380
- 40
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<Config>({} as Config, {
get: function() {
@ -20,6 +20,14 @@ const emptyConfig: Config = new Proxy({} as Config, {
}
});
type ConfigInspection<T> = {
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<T>(section?: string, resource?: Uri | null, defaultValue?: T): T {
get(): Config;
get<S1 extends keyof Config>(s1: S1, resource?: Uri | null, defaultValue?: Config[S1]): Config[S1];
get<S1 extends keyof Config, S2 extends keyof Config[S1]>(
s1: S1,
s2: S2,
resource?: Uri | 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,
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<T>(...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<T>(section, defaultValue)!;
}
changed(e: ConfigurationChangeEvent, section: string, resource?: Uri | null) {
changed<S1 extends keyof Config>(e: ConfigurationChangeEvent, s1: S1, resource?: Uri | null): boolean;
changed<S1 extends keyof Config, S2 extends keyof Config[S1]>(
e: ConfigurationChangeEvent,
s1: S1,
s2: S2,
resource?: Uri | null
): boolean;
changed<S1 extends keyof Config, S2 extends keyof Config[S1], S3 extends keyof Config[S1][S2]>(
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 extends keyof Config>(s1: S1, resource?: Uri | null): ConfigInspection<Config[S1]> | undefined;
inspect<S1 extends keyof Config, S2 extends keyof Config[S1]>(
s1: S1,
s2: S2,
resource?: Uri | 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,
resource?: Uri | 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, resource?: Uri | 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];
}
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<TFrom, TTo>(
migrate<S1 extends keyof Config>(
from: string,
to: string,
options: { fallbackValue?: TTo; migrationFn?(value: TFrom): TTo } = {}
): Promise<boolean> {
const inspection = configuration.inspect(from);
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 = {};
}
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<TFrom, TTo>(from: string, to: string, options: { migrationFn?(value: TFrom): TTo } = {}) {
const fromInspection = configuration.inspect(from);
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]
>(
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 } = {}) {
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 <setting name> 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<K extends keyof Config>(name: K) {
return Functions.propOf(emptyConfig, name);
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('.');
}
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 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,
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];
}
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<void> {
const inspect = configuration.inspect(section, resource)!;
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)!;
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
);

+ 25
- 28
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<TraceLevel>(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<Config>());
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')}`
];
}

+ 17
- 18
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<TraceLevel>(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<Config>();
const cfg = configuration.get();
const previousVersion = context.globalState.get<string>(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<string>(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<string, string>(s, s, {
configuration.migrate(s, s as any, {
migrationFn: formatMigrationFn
})
)

+ 6
- 10
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<Repository[]> {
const cc = Logger.getCorrelationContext();
const { uri } = folder;
const depth = configuration.get<number>(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<GitRemote[]> {
if (repoPath === undefined) return [];
providers =
providers ||
RemoteProviderFactory.loadProviders(
configuration.get<RemotesConfig[] | null | undefined>(configuration.name('remotes').value, null)
);
providers = providers || RemoteProviderFactory.loadProviders(configuration.get('remotes', null));
try {
const data = await Git.remote(repoPath);

+ 3
- 3
src/git/models/commit.ts 파일 보기

@ -36,9 +36,9 @@ export const CommitFormatting = {
dateStyle: undefined! as DateStyle,
reset: () => {
CommitFormatting.dateFormat = configuration.get<string | null>(configuration.name('defaultDateFormat').value);
CommitFormatting.dateSource = configuration.get<DateSource>(configuration.name('defaultDateSource').value);
CommitFormatting.dateStyle = configuration.get<DateStyle>(configuration.name('defaultDateStyle').value);
CommitFormatting.dateFormat = configuration.get('defaultDateFormat');
CommitFormatting.dateSource = configuration.get('defaultDateSource');
CommitFormatting.dateStyle = configuration.get('defaultDateStyle');
}
};

+ 4
- 10
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<RemotesConfig[] | null | undefined>(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<GitRemote[]> {
if (this._remotes === undefined || !this.supportsChangeEvents) {
if (this._providers === undefined) {
const remotesCfg = configuration.get<RemotesConfig[] | null | undefined>(
configuration.name('remotes').value,
this.folder.uri
);
const remotesCfg = configuration.get('remotes', this.folder.uri);
this._providers = RemoteProviderFactory.loadProviders(remotesCfg);
}

+ 2
- 2
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;
}

+ 3
- 7
src/messages.ts 파일 보기

@ -160,10 +160,7 @@ export class Messages {
): Promise<MessageItem | undefined> {
Logger.log(`ShowMessage(${type}, '${message}', ${suppressionKey}, ${dontShowAgain})`);
if (
suppressionKey !== undefined &&
configuration.get<boolean>(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);
}
}

+ 1
- 1
src/quickpicks/commonQuickPicks.ts 파일 보기

@ -8,7 +8,7 @@ import { KeyMapping, Keys } from '../keyboard';
import { ReferencesQuickPick, ReferencesQuickPickItem } from './referencesQuickPick';
export function getQuickPickIgnoreFocusOut() {
return !configuration.get<boolean>(configuration.name('advanced')('quickPick')('closeOnFocusOut').value);
return !configuration.get('advanced', 'quickPick', 'closeOnFocusOut');
}
export function showQuickPickProgress(message: string, mapping?: KeyMapping): CancellationTokenSource {

+ 6
- 6
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) {

+ 4
- 5
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<number>(section);
if (configuration.changed(e, 'advanced', 'blame', 'delayAfterEdit')) {
this._dirtyIdleTriggerDelay = configuration.get('advanced', 'blame', 'delayAfterEdit');
this._dirtyIdleTriggeredDebounced = undefined;
}
}

+ 5
- 5
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) {

+ 7
- 10
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);
}
}

+ 7
- 10
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);
}
}

+ 6
- 9
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);
}
}

+ 5
- 5
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) {

+ 3
- 3
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`));
}

+ 5
- 25
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);
}

+ 2
- 2
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>(),
config: configuration.get(),
scope: 'user',
scopes: scopes
};

+ 5
- 5
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<Config>() });
return this.notify(DidChangeConfigurationNotificationType, { config: configuration.get() });
}
private postMessage(message: IpcMessage) {

불러오는 중...
취소
저장