Ver código fonte

More configuation changes

main
Eric Amodio 3 anos atrás
pai
commit
a85b58280b
11 arquivos alterados com 48 adições e 62 exclusões
  1. +2
    -2
      src/annotations/autolinks.ts
  2. +3
    -3
      src/annotations/fileAnnotationController.ts
  3. +2
    -2
      src/annotations/lineAnnotationController.ts
  4. +3
    -3
      src/codelens/codeLensController.ts
  5. +23
    -37
      src/configuration.ts
  6. +2
    -2
      src/git/gitService.ts
  7. +3
    -3
      src/git/models/repository.ts
  8. +2
    -2
      src/hovers/lineHoverController.ts
  9. +2
    -2
      src/statusbar/statusBarController.ts
  10. +3
    -3
      src/trackers/documentTracker.ts
  11. +3
    -3
      src/views/viewBase.ts

+ 2
- 2
src/annotations/autolinks.ts Ver arquivo

@ -34,14 +34,14 @@ export class Autolinks implements Disposable {
constructor() { constructor() {
this._disposable = Disposable.from(configuration.onDidChange(this.onConfigurationChanged, this)); this._disposable = Disposable.from(configuration.onDidChange(this.onConfigurationChanged, this));
this.onConfigurationChanged(configuration.initializingChangeEvent);
this.onConfigurationChanged();
} }
dispose() { dispose() {
this._disposable?.dispose(); this._disposable?.dispose();
} }
private onConfigurationChanged(e: ConfigurationChangeEvent) {
private onConfigurationChanged(e?: ConfigurationChangeEvent) {
if (configuration.changed(e, 'autolinks')) { if (configuration.changed(e, 'autolinks')) {
this._references = Container.config.autolinks ?? []; this._references = Container.config.autolinks ?? [];
} }

+ 3
- 3
src/annotations/fileAnnotationController.ts Ver arquivo

@ -83,7 +83,7 @@ export class FileAnnotationController implements Disposable {
this._disposable = Disposable.from(configuration.onDidChange(this.onConfigurationChanged, this)); this._disposable = Disposable.from(configuration.onDidChange(this.onConfigurationChanged, this));
this._toggleModes = new Map<FileAnnotationType, AnnotationsToggleMode>(); this._toggleModes = new Map<FileAnnotationType, AnnotationsToggleMode>();
this.onConfigurationChanged(configuration.initializingChangeEvent);
this.onConfigurationChanged();
} }
dispose() { dispose() {
@ -99,7 +99,7 @@ export class FileAnnotationController implements Disposable {
this._disposable?.dispose(); this._disposable?.dispose();
} }
private onConfigurationChanged(e: ConfigurationChangeEvent) {
private onConfigurationChanged(e?: ConfigurationChangeEvent) {
const cfg = Container.config; const cfg = Container.config;
if (configuration.changed(e, 'blame.highlight')) { if (configuration.changed(e, 'blame.highlight')) {
@ -189,7 +189,7 @@ export class FileAnnotationController implements Disposable {
}); });
} }
const initializing = configuration.initializing(e);
const initializing = e == null;
if (configuration.changed(e, 'blame.toggleMode')) { if (configuration.changed(e, 'blame.toggleMode')) {
this._toggleModes.set(FileAnnotationType.Blame, cfg.blame.toggleMode); this._toggleModes.set(FileAnnotationType.Blame, cfg.blame.toggleMode);

+ 2
- 2
src/annotations/lineAnnotationController.ts Ver arquivo

@ -40,7 +40,7 @@ export class LineAnnotationController implements Disposable {
Container.fileAnnotations.onDidToggleAnnotations(this.onFileAnnotationsToggled, this), Container.fileAnnotations.onDidToggleAnnotations(this.onFileAnnotationsToggled, this),
Authentication.onDidChange(() => void this.refresh(window.activeTextEditor)), Authentication.onDidChange(() => void this.refresh(window.activeTextEditor)),
); );
this.onConfigurationChanged(configuration.initializingChangeEvent);
this.onConfigurationChanged();
} }
dispose() { dispose() {
@ -50,7 +50,7 @@ export class LineAnnotationController implements Disposable {
this._disposable.dispose(); this._disposable.dispose();
} }
private onConfigurationChanged(e: ConfigurationChangeEvent) {
private onConfigurationChanged(e?: ConfigurationChangeEvent) {
if (!configuration.changed(e, 'currentLine')) return; if (!configuration.changed(e, 'currentLine')) return;
if (configuration.changed(e, 'currentLine.enabled')) { if (configuration.changed(e, 'currentLine.enabled')) {

+ 3
- 3
src/codelens/codeLensController.ts Ver arquivo

@ -19,7 +19,7 @@ export class GitCodeLensController implements Disposable {
constructor() { constructor() {
this._disposable = Disposable.from(configuration.onDidChange(this.onConfigurationChanged, this)); this._disposable = Disposable.from(configuration.onDidChange(this.onConfigurationChanged, this));
this.onConfigurationChanged(configuration.initializingChangeEvent);
this.onConfigurationChanged();
} }
dispose() { dispose() {
@ -27,14 +27,14 @@ export class GitCodeLensController implements Disposable {
this._disposable?.dispose(); this._disposable?.dispose();
} }
private onConfigurationChanged(e: ConfigurationChangeEvent) {
private onConfigurationChanged(e?: ConfigurationChangeEvent) {
if ( if (
configuration.changed(e, 'codeLens') || configuration.changed(e, 'codeLens') ||
configuration.changed(e, 'defaultDateFormat') || configuration.changed(e, 'defaultDateFormat') ||
configuration.changed(e, 'defaultDateSource') || configuration.changed(e, 'defaultDateSource') ||
configuration.changed(e, 'defaultDateStyle') configuration.changed(e, 'defaultDateStyle')
) { ) {
if (!configuration.initializing(e)) {
if (e != null) {
Logger.log('CodeLens config changed; resetting CodeLens provider'); Logger.log('CodeLens config changed; resetting CodeLens provider');
} }

+ 23
- 37
src/configuration.ts Ver arquivo

@ -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

+ 2
- 2
src/git/gitService.ts Ver arquivo

@ -162,7 +162,7 @@ export class GitService implements Disposable {
void this.updateContext(this._repositoryTree); void this.updateContext(this._repositoryTree);
}), }),
); );
this.onConfigurationChanged(configuration.initializingChangeEvent);
this.onConfigurationChanged();
this._repositoriesLoadingPromise = this.onWorkspaceFoldersChanged(); this._repositoriesLoadingPromise = this.onWorkspaceFoldersChanged();
} }
@ -237,7 +237,7 @@ export class GitService implements Disposable {
} }
} }
private onConfigurationChanged(e: ConfigurationChangeEvent) {
private onConfigurationChanged(e?: ConfigurationChangeEvent) {
if ( if (
configuration.changed(e, 'defaultDateFormat') || configuration.changed(e, 'defaultDateFormat') ||
configuration.changed(e, 'defaultDateSource') || configuration.changed(e, 'defaultDateSource') ||

+ 3
- 3
src/git/models/repository.ts Ver arquivo

@ -265,7 +265,7 @@ export class Repository implements Disposable {
watcher.onDidDelete(this.onRepositoryChanged, this), watcher.onDidDelete(this.onRepositoryChanged, this),
configuration.onDidChange(this.onConfigurationChanged, this), configuration.onDidChange(this.onConfigurationChanged, this),
); );
this.onConfigurationChanged(configuration.initializingChangeEvent);
this.onConfigurationChanged();
if (!this.supportsChangeEvents) { if (!this.supportsChangeEvents) {
void this.tryWatchingForChangesViaBuiltInApi(); void this.tryWatchingForChangesViaBuiltInApi();
@ -307,11 +307,11 @@ export class Repository implements Disposable {
return this._updatedAt; return this._updatedAt;
} }
private onConfigurationChanged(e: ConfigurationChangeEvent) {
private onConfigurationChanged(e?: ConfigurationChangeEvent) {
if (configuration.changed(e, 'remotes', this.folder.uri)) { if (configuration.changed(e, 'remotes', this.folder.uri)) {
this._providers = RemoteProviderFactory.loadProviders(configuration.get('remotes', this.folder.uri)); this._providers = RemoteProviderFactory.loadProviders(configuration.get('remotes', this.folder.uri));
if (!configuration.initializing(e)) {
if (e != null) {
this.resetCaches('remotes'); this.resetCaches('remotes');
this.fireChange(RepositoryChange.Remotes); this.fireChange(RepositoryChange.Remotes);
} }

+ 2
- 2
src/hovers/lineHoverController.ts Ver arquivo

@ -26,7 +26,7 @@ export class LineHoverController implements Disposable {
constructor() { constructor() {
this._disposable = Disposable.from(configuration.onDidChange(this.onConfigurationChanged, this)); this._disposable = Disposable.from(configuration.onDidChange(this.onConfigurationChanged, this));
this.onConfigurationChanged(configuration.initializingChangeEvent);
this.onConfigurationChanged();
} }
dispose() { dispose() {
@ -36,7 +36,7 @@ export class LineHoverController implements Disposable {
this._disposable.dispose(); this._disposable.dispose();
} }
private onConfigurationChanged(e: ConfigurationChangeEvent) {
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; return;
} }

+ 2
- 2
src/statusbar/statusBarController.ts Ver arquivo

@ -27,7 +27,7 @@ export class StatusBarController implements Disposable {
constructor() { constructor() {
this._disposable = Disposable.from(configuration.onDidChange(this.onConfigurationChanged, this)); this._disposable = Disposable.from(configuration.onDidChange(this.onConfigurationChanged, this));
this.onConfigurationChanged(configuration.initializingChangeEvent);
this.onConfigurationChanged();
} }
dispose() { dispose() {
@ -40,7 +40,7 @@ export class StatusBarController implements Disposable {
this._disposable.dispose(); this._disposable.dispose();
} }
private onConfigurationChanged(e: ConfigurationChangeEvent) {
private onConfigurationChanged(e?: ConfigurationChangeEvent) {
if (configuration.changed(e, 'mode')) { if (configuration.changed(e, 'mode')) {
const mode = const mode =
Container.config.mode.active && Container.config.mode.statusBar.enabled Container.config.mode.active && Container.config.mode.statusBar.enabled

+ 3
- 3
src/trackers/documentTracker.ts Ver arquivo

@ -76,7 +76,7 @@ export class DocumentTracker implements Disposable {
workspace.onDidSaveTextDocument(this.onTextDocumentSaved, this), workspace.onDidSaveTextDocument(this.onTextDocumentSaved, this),
); );
void this.onConfigurationChanged(configuration.initializingChangeEvent);
void this.onConfigurationChanged();
} }
dispose() { dispose() {
@ -89,10 +89,10 @@ export class DocumentTracker implements Disposable {
void this.onActiveTextEditorChanged(window.activeTextEditor); void this.onActiveTextEditorChanged(window.activeTextEditor);
} }
private async onConfigurationChanged(e: ConfigurationChangeEvent) {
private async onConfigurationChanged(e?: ConfigurationChangeEvent) {
// Only rest the cached state if we aren't initializing // Only rest the cached state if we aren't initializing
if ( if (
!configuration.initializing(e) &&
e != null &&
(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()) { for (const d of this._documentMap.values()) {

+ 3
- 3
src/views/viewBase.ts Ver arquivo

@ -149,7 +149,7 @@ export abstract class ViewBase<
this.initialize({ showCollapseAll: this.showCollapseAll }); this.initialize({ showCollapseAll: this.showCollapseAll });
setImmediate(() => this.onConfigurationChanged(configuration.initializingChangeEvent));
setImmediate(() => this.onConfigurationChanged());
} }
protected get showCollapseAll(): boolean { protected get showCollapseAll(): boolean {
@ -210,8 +210,8 @@ export abstract class ViewBase<
protected abstract getRoot(): RootNode; protected abstract getRoot(): RootNode;
protected abstract registerCommands(): void; protected abstract registerCommands(): void;
protected onConfigurationChanged(e: ConfigurationChangeEvent): void {
if (!configuration.initializing(e) && this.root != null) {
protected onConfigurationChanged(e?: ConfigurationChangeEvent): void {
if (e != null && this.root != null) {
void this.refresh(true); void this.refresh(true);
} }
} }

Carregando…
Cancelar
Salvar