Skip to content

Commit

Permalink
preferences: improve extensibility of schemas
Browse files Browse the repository at this point in the history
The commit refactors the binding of preference schemas so they can be
easily rebinding by downstream extenders and applications if necessary.

Signed-off-by: vince-fugnitto <[email protected]>
  • Loading branch information
vince-fugnitto committed Aug 19, 2021
1 parent a6422c3 commit d648472
Show file tree
Hide file tree
Showing 18 changed files with 136 additions and 91 deletions.
11 changes: 7 additions & 4 deletions packages/core/src/browser/core-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,20 @@ export interface CoreConfiguration {
'workbench.tree.renderIndentGuides': 'onHover' | 'none' | 'always';
}

export const CorePreferenceContribution = Symbol('CorePreferenceContribution');
export const CorePreferences = Symbol('CorePreferences');
export type CorePreferences = PreferenceProxy<CoreConfiguration>;

export function createCorePreferences(preferences: PreferenceService): CorePreferences {
return createPreferenceProxy(preferences, corePreferenceSchema);
export function createCorePreferences(preferences: PreferenceService, schema: PreferenceSchema = corePreferenceSchema): CorePreferences {
return createPreferenceProxy(preferences, schema);
}

export function bindCorePreferences(bind: interfaces.Bind): void {
bind(CorePreferences).toDynamicValue(ctx => {
const preferences = ctx.container.get<PreferenceService>(PreferenceService);
return createCorePreferences(preferences);
const contribution = ctx.container.get<PreferenceContribution>(CorePreferenceContribution);
return createCorePreferences(preferences, contribution.schema);
}).inSingletonScope();
bind(PreferenceContribution).toConstantValue({ schema: corePreferenceSchema });
bind(CorePreferenceContribution).toConstantValue({ schema: corePreferenceSchema });
bind(PreferenceContribution).toService(CorePreferenceContribution);
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,20 @@ export class ElectronWindowConfiguration {
'window.zoomLevel': number;
}

export const ElectronWindowPreferenceContribution = Symbol('ElectronWindowPreferenceContribution');
export const ElectronWindowPreferences = Symbol('ElectronWindowPreferences');
export type ElectronWindowPreferences = PreferenceProxy<ElectronWindowConfiguration>;

export function createElectronWindowPreferences(preferences: PreferenceService): ElectronWindowPreferences {
return createPreferenceProxy(preferences, electronWindowPreferencesSchema);
export function createElectronWindowPreferences(preferences: PreferenceService, schema: PreferenceSchema = electronWindowPreferencesSchema): ElectronWindowPreferences {
return createPreferenceProxy(preferences, schema);
}

export function bindWindowPreferences(bind: interfaces.Bind): void {
bind(ElectronWindowPreferences).toDynamicValue(ctx => {
const preferences = ctx.container.get<PreferenceService>(PreferenceService);
return createElectronWindowPreferences(preferences);
const contribution = ctx.container.get<PreferenceContribution>(ElectronWindowPreferenceContribution);
return createElectronWindowPreferences(preferences, contribution.schema);
}).inSingletonScope();

bind(PreferenceContribution).toConstantValue({ schema: electronWindowPreferencesSchema });
bind(ElectronWindowPreferenceContribution).toConstantValue({ schema: electronWindowPreferencesSchema });
bind(PreferenceContribution).toService(ElectronWindowPreferenceContribution);
}
12 changes: 7 additions & 5 deletions packages/debug/src/browser/debug-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,20 @@ export class DebugConfiguration {
'debug.showInStatusBar': 'never' | 'always' | 'onFirstSessionStart';
}

export const DebugPreferenceContribution = Symbol('DebugPreferenceContribution');
export const DebugPreferences = Symbol('DebugPreferences');
export type DebugPreferences = PreferenceProxy<DebugConfiguration>;

export function createDebugPreferences(preferences: PreferenceService): DebugPreferences {
return createPreferenceProxy(preferences, debugPreferencesSchema);
export function createDebugPreferences(preferences: PreferenceService, schema: PreferenceSchema = debugPreferencesSchema): DebugPreferences {
return createPreferenceProxy(preferences, schema);
}

export function bindDebugPreferences(bind: interfaces.Bind): void {
bind(DebugPreferences).toDynamicValue(ctx => {
const preferences = ctx.container.get<PreferenceService>(PreferenceService);
return createDebugPreferences(preferences);
const contribution = ctx.container.get<PreferenceContribution>(DebugPreferenceContribution);
return createDebugPreferences(preferences, contribution.schema);
}).inSingletonScope();

bind(PreferenceContribution).toConstantValue({ schema: debugPreferencesSchema });
bind(DebugPreferenceContribution).toConstantValue({ schema: debugPreferencesSchema });
bind(PreferenceContribution).toService(DebugPreferenceContribution);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@ export interface EditorPreviewConfiguration {
'editor.enablePreview': boolean;
}

export const EditorPreviewPreferenceContribution = Symbol('EditorPreviewPreferenceContribution');
export const EditorPreviewPreferences = Symbol('EditorPreviewPreferences');
export type EditorPreviewPreferences = PreferenceProxy<EditorPreviewConfiguration>;

export function createEditorPreviewPreferences(preferences: PreferenceService): EditorPreviewPreferences {
return createPreferenceProxy(preferences, EditorPreviewConfigSchema);
export function createEditorPreviewPreferences(preferences: PreferenceService, schema: PreferenceSchema = EditorPreviewConfigSchema): EditorPreviewPreferences {
return createPreferenceProxy(preferences, schema);
}

export function bindEditorPreviewPreferences(bind: interfaces.Bind): void {
bind(EditorPreviewPreferences).toDynamicValue(ctx => {
const preferences = ctx.container.get<PreferenceService>(PreferenceService);
return createEditorPreviewPreferences(preferences);
const contribution = ctx.container.get<PreferenceContribution>(EditorPreviewPreferenceContribution);
return createEditorPreviewPreferences(preferences, contribution.schema);
}).inSingletonScope();
bind(PreferenceContribution).toConstantValue({ schema: EditorPreviewConfigSchema });
bind(EditorPreviewPreferenceContribution).toConstantValue({ schema: EditorPreviewConfigSchema });
bind(PreferenceContribution).toService(EditorPreviewPreferenceContribution);
}
12 changes: 7 additions & 5 deletions packages/editor/src/browser/editor-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1566,18 +1566,20 @@ export type EndOfLinePreference = '\n' | '\r\n' | 'auto';

export type EditorPreferenceChange = PreferenceChangeEvent<EditorConfiguration>;

export const EditorPreferenceContribution = Symbol('EditorPreferenceContribution');
export const EditorPreferences = Symbol('EditorPreferences');
export type EditorPreferences = PreferenceProxy<EditorConfiguration>;

export function createEditorPreferences(preferences: PreferenceService): EditorPreferences {
return createPreferenceProxy(preferences, editorPreferenceSchema);
export function createEditorPreferences(preferences: PreferenceService, schema: PreferenceSchema = editorPreferenceSchema): EditorPreferences {
return createPreferenceProxy(preferences, schema);
}

export function bindEditorPreferences(bind: interfaces.Bind): void {
bind(EditorPreferences).toDynamicValue(ctx => {
const preferences = ctx.container.get<PreferenceService>(PreferenceService);
return createEditorPreferences(preferences);
const contribution = ctx.container.get<PreferenceContribution>(EditorPreferenceContribution);
return createEditorPreferences(preferences, contribution.schema);
}).inSingletonScope();

bind(PreferenceContribution).toConstantValue({ schema: editorPreferenceSchema });
bind(EditorPreferenceContribution).toConstantValue({ schema: editorPreferenceSchema });
bind(PreferenceContribution).toService(EditorPreferenceContribution);
}
12 changes: 7 additions & 5 deletions packages/filesystem/src/browser/filesystem-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,20 @@ export interface FileSystemConfiguration {
'files.trimTrailingWhitespace': boolean;
}

export const FileSystemPreferenceContribution = Symbol('FilesystemPreferenceContribution');
export const FileSystemPreferences = Symbol('FileSystemPreferences');
export type FileSystemPreferences = PreferenceProxy<FileSystemConfiguration>;

export function createFileSystemPreferences(preferences: PreferenceService): FileSystemPreferences {
return createPreferenceProxy(preferences, filesystemPreferenceSchema);
export function createFileSystemPreferences(preferences: PreferenceService, schema: PreferenceSchema = filesystemPreferenceSchema): FileSystemPreferences {
return createPreferenceProxy(preferences, schema);
}

export function bindFileSystemPreferences(bind: interfaces.Bind): void {
bind(FileSystemPreferences).toDynamicValue(ctx => {
const preferences = ctx.container.get<PreferenceService>(PreferenceService);
return createFileSystemPreferences(preferences);
const contribution = ctx.container.get<PreferenceContribution>(FileSystemPreferenceContribution);
return createFileSystemPreferences(preferences, contribution.schema);
}).inSingletonScope();

bind(PreferenceContribution).toConstantValue({ schema: filesystemPreferenceSchema });
bind(FileSystemPreferenceContribution).toConstantValue({ schema: filesystemPreferenceSchema });
bind(PreferenceContribution).toService(FileSystemPreferenceContribution);
}
13 changes: 8 additions & 5 deletions packages/git/src/browser/git-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,20 @@ export interface GitConfiguration {
'git.alwaysSignOff': boolean
}

export const GitPreferenceContribution = Symbol('GitPreferenceContribution');
export const GitPreferences = Symbol('GitPreferences');
export type GitPreferences = PreferenceProxy<GitConfiguration>;

export function createGitPreferences(preferences: PreferenceService): GitPreferences {
return createPreferenceProxy(preferences, GitConfigSchema);
export function createGitPreferences(preferences: PreferenceService, schema: PreferenceSchema = GitConfigSchema): GitPreferences {
return createPreferenceProxy(preferences, schema);
}

export function bindGitPreferences(bind: interfaces.Bind): void {
bind(GitPreferences).toDynamicValue(ctx => {
const preferences = ctx.container.get<PreferenceService>(PreferenceService);
return createGitPreferences(preferences);
});
bind(PreferenceContribution).toConstantValue({ schema: GitConfigSchema });
const contribution = ctx.container.get<PreferenceContribution>(GitPreferenceContribution);
return createGitPreferences(preferences, contribution.schema);
}).inSingletonScope();
bind(GitPreferenceContribution).toConstantValue({ schema: GitConfigSchema });
bind(PreferenceContribution).toService(GitPreferenceContribution);
}
14 changes: 9 additions & 5 deletions packages/markers/src/browser/problem/problem-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,20 @@ export interface ProblemConfiguration {
'problems.autoReveal': boolean
}

export const ProblemPreferenceContribution = Symbol('ProblemPreferenceContribution');
export const ProblemPreferences = Symbol('ProblemPreferences');
export type ProblemPreferences = PreferenceProxy<ProblemConfiguration>;

export const createProblemPreferences = (preferences: PreferenceService): ProblemPreferences =>
createPreferenceProxy(preferences, ProblemConfigSchema);
export function createProblemPreferences(preferences: PreferenceService, schema: PreferenceSchema = ProblemConfigSchema): ProblemPreferences {
return createPreferenceProxy(preferences, schema);
}

export const bindProblemPreferences = (bind: interfaces.Bind): void => {
bind(ProblemPreferences).toDynamicValue(ctx => {
const preferences = ctx.container.get<PreferenceService>(PreferenceService);
return createProblemPreferences(preferences);
});
bind(PreferenceContribution).toConstantValue({ schema: ProblemConfigSchema });
const contribution = ctx.container.get<PreferenceContribution>(ProblemPreferenceContribution);
return createProblemPreferences(preferences, contribution.schema);
}).inSingletonScope();
bind(ProblemPreferenceContribution).toConstantValue({ schema: ProblemConfigSchema });
bind(PreferenceContribution).toService(ProblemPreferenceContribution);
};
14 changes: 8 additions & 6 deletions packages/messages/src/browser/notification-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,20 @@ export interface NotificationConfiguration {
'notification.timeout': number
}

export const NotificationPreferenceContribution = Symbol('NotificationPreferenceContribution');
export const NotificationPreferences = Symbol('NotificationPreferences');
export type NotificationPreferences = PreferenceProxy<NotificationConfiguration>;

export function createNotificationPreferences(preferences: PreferenceService): NotificationPreferences {
return createPreferenceProxy(preferences, NotificationConfigSchema);
export function createNotificationPreferences(preferences: PreferenceService, schema: PreferenceSchema = NotificationConfigSchema): NotificationPreferences {
return createPreferenceProxy(preferences, schema);
}

export function bindNotificationPreferences(bind: interfaces.Bind): void {
bind(NotificationPreferences).toDynamicValue(ctx => {
const preferences = ctx.container.get<PreferenceService>(PreferenceService);
return createNotificationPreferences(preferences);
});

bind(PreferenceContribution).toConstantValue({ schema: NotificationConfigSchema });
const contribution = ctx.container.get<PreferenceContribution>(NotificationPreferenceContribution);
return createNotificationPreferences(preferences, contribution.schema);
}).inSingletonScope();
bind(NotificationPreferenceContribution).toConstantValue({ schema: NotificationConfigSchema });
bind(PreferenceContribution).toService(NotificationPreferenceContribution);
}
13 changes: 8 additions & 5 deletions packages/navigator/src/browser/navigator-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@ export interface FileNavigatorConfiguration {
'explorer.autoReveal': boolean;
}

export const FileNavigatorPreferenceContribution = Symbol('FileNavigatorPreferenceContribution');
export const FileNavigatorPreferences = Symbol('NavigatorPreferences');
export type FileNavigatorPreferences = PreferenceProxy<FileNavigatorConfiguration>;

export function createNavigatorPreferences(preferences: PreferenceService): FileNavigatorPreferences {
return createPreferenceProxy(preferences, FileNavigatorConfigSchema);
export function createNavigatorPreferences(preferences: PreferenceService, schema: PreferenceSchema = FileNavigatorConfigSchema): FileNavigatorPreferences {
return createPreferenceProxy(preferences, schema);
}

export function bindFileNavigatorPreferences(bind: interfaces.Bind): void {
bind(FileNavigatorPreferences).toDynamicValue(ctx => {
const preferences = ctx.container.get<PreferenceService>(PreferenceService);
return createNavigatorPreferences(preferences);
});
bind(PreferenceContribution).toConstantValue({ schema: FileNavigatorConfigSchema });
const contribution = ctx.container.get<PreferenceContribution>(FileNavigatorPreferenceContribution);
return createNavigatorPreferences(preferences, contribution.schema);
}).inSingletonScope();
bind(FileNavigatorPreferenceContribution).toConstantValue({ schema: FileNavigatorConfigSchema });
bind(PreferenceContribution).toService(FileNavigatorPreferenceContribution);
}
14 changes: 8 additions & 6 deletions packages/output/src/common/output-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,20 @@ export interface OutputConfiguration {
'output.maxChannelHistory': number
}

export const OutputPreferenceContribution = Symbol('OutputPreferenceContribution');
export const OutputPreferences = Symbol('OutputPreferences');
export type OutputPreferences = PreferenceProxy<OutputConfiguration>;

export function createOutputPreferences(preferences: PreferenceService): OutputPreferences {
return createPreferenceProxy(preferences, OutputConfigSchema);
export function createOutputPreferences(preferences: PreferenceService, schema: PreferenceSchema = OutputConfigSchema): OutputPreferences {
return createPreferenceProxy(preferences, schema);
}

export function bindOutputPreferences(bind: interfaces.Bind): void {
bind(OutputPreferences).toDynamicValue(ctx => {
const preferences = ctx.container.get<PreferenceService>(PreferenceService);
return createOutputPreferences(preferences);
});

bind(PreferenceContribution).toConstantValue({ schema: OutputConfigSchema });
const contribution = ctx.container.get<PreferenceContribution>(OutputPreferenceContribution);
return createOutputPreferences(preferences, contribution.schema);
}).inSingletonScope();
bind(OutputPreferenceContribution).toConstantValue({ schema: OutputConfigSchema });
bind(PreferenceContribution).toService(OutputPreferenceContribution);
}
13 changes: 8 additions & 5 deletions packages/plugin-dev/src/browser/hosted-plugin-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,20 @@ export interface HostedPluginConfiguration {
'hosted-plugin.launchOutFiles': string[];
}

export const HostedPluginPreferenceContribution = Symbol('HostedPluginPreferenceContribution');
export const HostedPluginPreferences = Symbol('HostedPluginPreferences');
export type HostedPluginPreferences = PreferenceProxy<HostedPluginConfiguration>;

export function createNavigatorPreferences(preferences: PreferenceService): HostedPluginPreferences {
return createPreferenceProxy(preferences, HostedPluginConfigSchema);
export function createNavigatorPreferences(preferences: PreferenceService, schema: PreferenceSchema = HostedPluginConfigSchema): HostedPluginPreferences {
return createPreferenceProxy(preferences, schema);
}

export function bindHostedPluginPreferences(bind: interfaces.Bind): void {
bind(HostedPluginPreferences).toDynamicValue(ctx => {
const preferences = ctx.container.get<PreferenceService>(PreferenceService);
return createNavigatorPreferences(preferences);
});
bind(PreferenceContribution).toConstantValue({ schema: HostedPluginConfigSchema });
const contribution = ctx.container.get<PreferenceContribution>(HostedPluginPreferenceContribution);
return createNavigatorPreferences(preferences, contribution.schema);
}).inSingletonScope();
bind(HostedPluginPreferenceContribution).toConstantValue({ schema: HostedPluginConfigSchema });
bind(PreferenceContribution).toService(HostedPluginPreferenceContribution);
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,20 @@ export interface WebviewConfiguration {
'webview.warnIfUnsecure'?: boolean
}

export const WebviewPreferenceContribution = Symbol('WebviewPreferenceContribution');
export const WebviewPreferences = Symbol('WebviewPreferences');
export type WebviewPreferences = PreferenceProxy<WebviewConfiguration>;

export function createWebviewPreferences(preferences: PreferenceService): WebviewPreferences {
return createPreferenceProxy(preferences, WebviewConfigSchema);
export function createWebviewPreferences(preferences: PreferenceService, schema: PreferenceSchema = WebviewConfigSchema): WebviewPreferences {
return createPreferenceProxy(preferences, schema);
}

export function bindWebviewPreferences(bind: interfaces.Bind): void {
bind(WebviewPreferences).toDynamicValue(ctx => {
const preferences = ctx.container.get<PreferenceService>(PreferenceService);
return createWebviewPreferences(preferences);
});
bind(PreferenceContribution).toConstantValue({ schema: WebviewConfigSchema });
const contribution = ctx.container.get<PreferenceContribution>(WebviewPreferenceContribution);
return createWebviewPreferences(preferences, contribution.schema);
}).inSingletonScope();
bind(WebviewPreferenceContribution).toConstantValue({ schema: WebviewConfigSchema });
bind(PreferenceContribution).toService(WebviewPreferenceContribution);
}
Loading

0 comments on commit d648472

Please sign in to comment.