|
@ -13,15 +13,7 @@ import { |
|
|
import { Config } from './config'; |
|
|
import { Config } from './config'; |
|
|
import { Objects } from './system'; |
|
|
import { Objects } from './system'; |
|
|
|
|
|
|
|
|
const extensionId = 'gitlens'; |
|
|
|
|
|
|
|
|
|
|
|
type ConfigInspection<T> = { |
|
|
|
|
|
key: string; |
|
|
|
|
|
defaultValue?: T; |
|
|
|
|
|
globalValue?: T; |
|
|
|
|
|
workspaceValue?: T; |
|
|
|
|
|
workspaceFolderValue?: T; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
const configPrefix = 'gitlens'; |
|
|
|
|
|
|
|
|
export interface ConfigurationWillChangeEvent { |
|
|
export interface ConfigurationWillChangeEvent { |
|
|
change: ConfigurationChangeEvent; |
|
|
change: ConfigurationChangeEvent; |
|
@ -29,7 +21,7 @@ export interface ConfigurationWillChangeEvent { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export class Configuration { |
|
|
export class Configuration { |
|
|
static configure(context: ExtensionContext) { |
|
|
|
|
|
|
|
|
static configure(context: ExtensionContext): void { |
|
|
context.subscriptions.push( |
|
|
context.subscriptions.push( |
|
|
workspace.onDidChangeConfiguration(configuration.onConfigurationChanged, configuration), |
|
|
workspace.onDidChangeConfiguration(configuration.onConfigurationChanged, configuration), |
|
|
); |
|
|
); |
|
@ -51,7 +43,7 @@ export class Configuration { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private onConfigurationChanged(e: ConfigurationChangeEvent) { |
|
|
private onConfigurationChanged(e: ConfigurationChangeEvent) { |
|
|
if (!e.affectsConfiguration(extensionId)) { |
|
|
|
|
|
|
|
|
if (!e.affectsConfiguration(configPrefix)) { |
|
|
this._onDidChangeAny.fire(e); |
|
|
this._onDidChangeAny.fire(e); |
|
|
|
|
|
|
|
|
return; |
|
|
return; |
|
@ -70,8 +62,6 @@ export class Configuration { |
|
|
this._onDidChange.fire(e); |
|
|
this._onDidChange.fire(e); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
readonly initializingChangeEvent: ConfigurationChangeEvent = { affectsConfiguration: () => true }; |
|
|
|
|
|
|
|
|
|
|
|
get(): Config; |
|
|
get(): Config; |
|
|
get<T extends ConfigPath>( |
|
|
get<T extends ConfigPath>( |
|
|
section: T, |
|
|
section: T, |
|
@ -85,40 +75,33 @@ export class Configuration { |
|
|
): Config | ConfigPathValue<T> { |
|
|
): Config | ConfigPathValue<T> { |
|
|
return defaultValue === undefined |
|
|
return defaultValue === undefined |
|
|
? workspace |
|
|
? workspace |
|
|
.getConfiguration(section === undefined ? undefined : extensionId, scope) |
|
|
|
|
|
.get<ConfigPathValue<T>>(section === undefined ? extensionId : section)! |
|
|
|
|
|
|
|
|
.getConfiguration(section === undefined ? undefined : configPrefix, scope) |
|
|
|
|
|
.get<ConfigPathValue<T>>(section === undefined ? configPrefix : section)! |
|
|
: workspace |
|
|
: workspace |
|
|
.getConfiguration(section === undefined ? undefined : extensionId, scope) |
|
|
|
|
|
.get<ConfigPathValue<T>>(section === undefined ? extensionId : section, defaultValue)!; |
|
|
|
|
|
|
|
|
.getConfiguration(section === undefined ? undefined : configPrefix, scope) |
|
|
|
|
|
.get<ConfigPathValue<T>>(section === undefined ? configPrefix : section, defaultValue)!; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getAny<T>(section: string, scope?: ConfigurationScope | null): T | undefined; |
|
|
getAny<T>(section: string, scope?: ConfigurationScope | null): T | undefined; |
|
|
getAny<T>(section: string, scope: ConfigurationScope | null | undefined, defaultValue: T): T; |
|
|
getAny<T>(section: string, scope: ConfigurationScope | null | undefined, defaultValue: T): T; |
|
|
getAny<T>(section: string, scope?: ConfigurationScope | null, defaultValue?: T) { |
|
|
|
|
|
|
|
|
getAny<T>(section: string, scope?: ConfigurationScope | null, defaultValue?: T): T | undefined { |
|
|
return defaultValue === undefined |
|
|
return defaultValue === undefined |
|
|
? workspace.getConfiguration(undefined, scope).get<T>(section) |
|
|
? workspace.getConfiguration(undefined, scope).get<T>(section) |
|
|
: workspace.getConfiguration(undefined, scope).get<T>(section, defaultValue); |
|
|
: workspace.getConfiguration(undefined, scope).get<T>(section, defaultValue); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
changed<T extends ConfigPath>( |
|
|
changed<T extends ConfigPath>( |
|
|
e: ConfigurationChangeEvent, |
|
|
|
|
|
|
|
|
e: ConfigurationChangeEvent | undefined, |
|
|
section: T, |
|
|
section: T, |
|
|
scope?: ConfigurationScope | null | undefined, |
|
|
scope?: ConfigurationScope | null | undefined, |
|
|
): boolean { |
|
|
): boolean { |
|
|
return e.affectsConfiguration(`${extensionId}.${section}`, scope!); |
|
|
|
|
|
|
|
|
return e?.affectsConfiguration(`${configPrefix}.${section}`, scope!) ?? true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
initializing(e: ConfigurationChangeEvent) { |
|
|
|
|
|
return e === this.initializingChangeEvent; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
inspect<T extends ConfigPath>( |
|
|
|
|
|
section: T, |
|
|
|
|
|
scope?: ConfigurationScope | null, |
|
|
|
|
|
): ConfigInspection<ConfigPathValue<T>> | undefined { |
|
|
|
|
|
|
|
|
inspect<T extends ConfigPath, V extends ConfigPathValue<T>>(section: T, scope?: ConfigurationScope | null) { |
|
|
return workspace |
|
|
return workspace |
|
|
.getConfiguration(section === undefined ? undefined : extensionId, scope) |
|
|
|
|
|
.inspect(section === undefined ? extensionId : section); |
|
|
|
|
|
|
|
|
.getConfiguration(section === undefined ? undefined : configPrefix, scope) |
|
|
|
|
|
.inspect<V>(section === undefined ? configPrefix : section); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
inspectAny<T>(section: string, scope?: ConfigurationScope | null) { |
|
|
inspectAny<T>(section: string, scope?: ConfigurationScope | null) { |
|
@ -270,10 +253,15 @@ export class Configuration { |
|
|
value: ConfigPathValue<T> | undefined, |
|
|
value: ConfigPathValue<T> | undefined, |
|
|
target: ConfigurationTarget, |
|
|
target: ConfigurationTarget, |
|
|
): Thenable<void> { |
|
|
): Thenable<void> { |
|
|
return workspace.getConfiguration(extensionId).update(section, value, target); |
|
|
|
|
|
|
|
|
return workspace.getConfiguration(configPrefix).update(section, value, target); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
updateAny(section: string, value: any, target: ConfigurationTarget, scope?: ConfigurationScope | null) { |
|
|
|
|
|
|
|
|
updateAny( |
|
|
|
|
|
section: string, |
|
|
|
|
|
value: any, |
|
|
|
|
|
target: ConfigurationTarget, |
|
|
|
|
|
scope?: ConfigurationScope | null, |
|
|
|
|
|
): Thenable<void> { |
|
|
return workspace |
|
|
return workspace |
|
|
.getConfiguration(undefined, target === ConfigurationTarget.Global ? undefined : scope!) |
|
|
.getConfiguration(undefined, target === ConfigurationTarget.Global ? undefined : scope!) |
|
|
.update(section, value, target); |
|
|
.update(section, value, target); |
|
@ -307,17 +295,15 @@ export class Configuration { |
|
|
|
|
|
|
|
|
export const configuration = new Configuration(); |
|
|
export const configuration = new Configuration(); |
|
|
|
|
|
|
|
|
type PathImpl<T, Key extends keyof T> = Key extends string |
|
|
|
|
|
|
|
|
type SubPath<T, Key extends keyof T> = Key extends string |
|
|
? T[Key] extends Record<string, any> |
|
|
? T[Key] extends Record<string, any> |
|
|
? |
|
|
? |
|
|
| `${Key}.${PathImpl<T[Key], Exclude<keyof T[Key], keyof any[]>> & string}` |
|
|
|
|
|
|
|
|
| `${Key}.${SubPath<T[Key], Exclude<keyof T[Key], keyof any[]>> & string}` |
|
|
| `${Key}.${Exclude<keyof T[Key], keyof any[]> & string}` |
|
|
| `${Key}.${Exclude<keyof T[Key], keyof any[]> & string}` |
|
|
: never |
|
|
: never |
|
|
: 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 Path<T> = SubPath<T, keyof T> | keyof T extends string | keyof T ? SubPath<T, keyof T> | keyof T : keyof T; |
|
|
|
|
|
|
|
|
type PathValue<T, P extends Path<T>> = P extends `${infer Key}.${infer Rest}` |
|
|
type PathValue<T, P extends Path<T>> = P extends `${infer Key}.${infer Rest}` |
|
|
? Key extends keyof T |
|
|
? Key extends keyof T |
|
|