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]>
Co-authored-by: Akos Kitta <[email protected]>
  • Loading branch information
vince-fugnitto and Akos Kitta committed Aug 11, 2021
1 parent 1dba014 commit 13618b2
Show file tree
Hide file tree
Showing 18 changed files with 231 additions and 112 deletions.
17 changes: 12 additions & 5 deletions packages/core/src/browser/core-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { interfaces } from 'inversify';
import { injectable, interfaces } from 'inversify';
import { createPreferenceProxy, PreferenceProxy, PreferenceService, PreferenceContribution, PreferenceSchema } from './preferences';
import { SUPPORTED_ENCODINGS } from './supported-encodings';
import { FrontendApplicationConfigProvider } from './frontend-application-config-provider';
Expand Down Expand Up @@ -117,14 +117,21 @@ export interface CoreConfiguration {
export const CorePreferences = Symbol('CorePreferences');
export type CorePreferences = PreferenceProxy<CoreConfiguration>;

export function createCorePreferences(preferences: PreferenceService): CorePreferences {
return createPreferenceProxy(preferences, corePreferenceSchema);
@injectable()
export class CorePreferenceContribution implements PreferenceContribution {
schema = 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).toSelf().inSingletonScope();
bind(PreferenceContribution).toService(CorePreferenceContribution);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { interfaces } from 'inversify';
import { injectable, interfaces } from 'inversify';
import { createPreferenceProxy, PreferenceContribution, PreferenceProxy, PreferenceSchema, PreferenceService } from '../../browser/preferences';

export namespace ZoomLevel {
Expand Down Expand Up @@ -48,15 +48,21 @@ export class ElectronWindowConfiguration {
export const ElectronWindowPreferences = Symbol('ElectronWindowPreferences');
export type ElectronWindowPreferences = PreferenceProxy<ElectronWindowConfiguration>;

export function createElectronWindowPreferences(preferences: PreferenceService): ElectronWindowPreferences {
return createPreferenceProxy(preferences, electronWindowPreferencesSchema);
@injectable()
export class ElectronWindowPreferenceContribution implements PreferenceContribution {
schema = 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).toSelf().inSingletonScope();
bind(PreferenceContribution).toService(ElectronWindowPreferenceContribution);
}
23 changes: 16 additions & 7 deletions packages/debug/src/browser/debug-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { PreferenceSchema, PreferenceProxy, PreferenceService, createPreferenceProxy, PreferenceContribution } from '@theia/core/lib/browser/preferences';
import { interfaces } from '@theia/core/shared/inversify';
import {
PreferenceSchema, PreferenceProxy, PreferenceService,
createPreferenceProxy, PreferenceContribution
} from '@theia/core/lib/browser/preferences';
import { injectable, interfaces } from '@theia/core/shared/inversify';

export const debugPreferencesSchema: PreferenceSchema = {
type: 'object',
Expand Down Expand Up @@ -65,15 +68,21 @@ export class DebugConfiguration {
export const DebugPreferences = Symbol('DebugPreferences');
export type DebugPreferences = PreferenceProxy<DebugConfiguration>;

export function createDebugPreferences(preferences: PreferenceService): DebugPreferences {
return createPreferenceProxy(preferences, debugPreferencesSchema);
@injectable()
export class DebugPreferenceContribution implements PreferenceContribution {
schema = 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).toSelf().inSingletonScope();
bind(PreferenceContribution).toService(DebugPreferenceContribution);
}
17 changes: 12 additions & 5 deletions packages/editor-preview/src/browser/editor-preview-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { interfaces } from '@theia/core/shared/inversify';
import { injectable, interfaces } from '@theia/core/shared/inversify';
import { createPreferenceProxy, PreferenceProxy, PreferenceService, PreferenceContribution, PreferenceSchema } from '@theia/core/lib/browser';

export const EditorPreviewConfigSchema: PreferenceSchema = {
Expand All @@ -35,14 +35,21 @@ export interface EditorPreviewConfiguration {
export const EditorPreviewPreferences = Symbol('EditorPreviewPreferences');
export type EditorPreviewPreferences = PreferenceProxy<EditorPreviewConfiguration>;

export function createEditorPreviewPreferences(preferences: PreferenceService): EditorPreviewPreferences {
return createPreferenceProxy(preferences, EditorPreviewConfigSchema);
@injectable()
export class EditorPreviewPreferenceContribution implements PreferenceContribution {
schema = 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).toSelf().inSingletonScope();
bind(PreferenceContribution).toService(EditorPreviewPreferenceContribution);
}
20 changes: 13 additions & 7 deletions packages/editor/src/browser/editor-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { interfaces } from '@theia/core/shared/inversify';
import { injectable, interfaces } from '@theia/core/shared/inversify';
import {
createPreferenceProxy,
PreferenceProxy,
PreferenceService,
PreferenceContribution,
PreferenceSchema,
PreferenceChangeEvent,
PreferenceSchemaProperties
PreferenceSchemaProperties,
} from '@theia/core/lib/browser/preferences';
import { isWindows, isOSX, OS } from '@theia/core/lib/common/os';

Expand Down Expand Up @@ -1552,15 +1552,21 @@ export type EditorPreferenceChange = PreferenceChangeEvent<EditorConfiguration>;
export const EditorPreferences = Symbol('EditorPreferences');
export type EditorPreferences = PreferenceProxy<EditorConfiguration>;

export function createEditorPreferences(preferences: PreferenceService): EditorPreferences {
return createPreferenceProxy(preferences, editorPreferenceSchema);
@injectable()
export class EditorPreferenceContribution implements PreferenceContribution {
schema = 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).toSelf().inSingletonScope();
bind(PreferenceContribution).toService(EditorPreferenceContribution);
}
18 changes: 12 additions & 6 deletions packages/filesystem/src/browser/filesystem-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { interfaces } from '@theia/core/shared/inversify';
import { injectable, interfaces } from '@theia/core/shared/inversify';
import {
createPreferenceProxy,
PreferenceProxy,
Expand Down Expand Up @@ -103,15 +103,21 @@ export interface FileSystemConfiguration {
export const FileSystemPreferences = Symbol('FileSystemPreferences');
export type FileSystemPreferences = PreferenceProxy<FileSystemConfiguration>;

export function createFileSystemPreferences(preferences: PreferenceService): FileSystemPreferences {
return createPreferenceProxy(preferences, filesystemPreferenceSchema);
@injectable()
export class FilesystemPreferenceContribution implements PreferenceContribution {
schema = 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).toSelf().inSingletonScope();
bind(PreferenceContribution).toService(FilesystemPreferenceContribution);
}
19 changes: 13 additions & 6 deletions packages/git/src/browser/git-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { interfaces } from '@theia/core/shared/inversify';
import { injectable, interfaces } from '@theia/core/shared/inversify';
import { createPreferenceProxy, PreferenceProxy, PreferenceService, PreferenceContribution, PreferenceSchema } from '@theia/core/lib/browser';

export const GitConfigSchema: PreferenceSchema = {
Expand Down Expand Up @@ -59,14 +59,21 @@ export interface GitConfiguration {
export const GitPreferences = Symbol('GitPreferences');
export type GitPreferences = PreferenceProxy<GitConfiguration>;

export function createGitPreferences(preferences: PreferenceService): GitPreferences {
return createPreferenceProxy(preferences, GitConfigSchema);
@injectable()
export class GitPreferenceContribution implements PreferenceContribution {
schema = 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).toSelf().inSingletonScope();
bind(PreferenceContribution).toService(GitPreferenceContribution);
}
20 changes: 14 additions & 6 deletions packages/markers/src/browser/problem/problem-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { interfaces } from '@theia/core/shared/inversify';
import { injectable, interfaces } from '@theia/core/shared/inversify';
import { createPreferenceProxy, PreferenceProxy, PreferenceService, PreferenceContribution, PreferenceSchema } from '@theia/core/lib/browser';

export const ProblemConfigSchema: PreferenceSchema = {
Expand Down Expand Up @@ -47,13 +47,21 @@ export interface ProblemConfiguration {
export const ProblemPreferences = Symbol('ProblemPreferences');
export type ProblemPreferences = PreferenceProxy<ProblemConfiguration>;

export const createProblemPreferences = (preferences: PreferenceService): ProblemPreferences =>
createPreferenceProxy(preferences, ProblemConfigSchema);
@injectable()
export class ProblemPreferenceContribution implements PreferenceContribution {
schema = 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).toSelf().inSingletonScope();
bind(PreferenceContribution).toService(ProblemPreferenceContribution);
};
20 changes: 13 additions & 7 deletions packages/messages/src/browser/notification-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { interfaces } from '@theia/core/shared/inversify';
import { injectable, interfaces } from '@theia/core/shared/inversify';
import {
createPreferenceProxy,
PreferenceProxy,
Expand All @@ -41,15 +41,21 @@ export interface NotificationConfiguration {
export const NotificationPreferences = Symbol('NotificationPreferences');
export type NotificationPreferences = PreferenceProxy<NotificationConfiguration>;

export function createNotificationPreferences(preferences: PreferenceService): NotificationPreferences {
return createPreferenceProxy(preferences, NotificationConfigSchema);
@injectable()
export class NotificationPreferenceContribution implements PreferenceContribution {
schema = 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).toSelf().inSingletonScope();
bind(PreferenceContribution).toService(NotificationPreferenceContribution);
}
20 changes: 13 additions & 7 deletions packages/navigator/src/browser/navigator-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { interfaces } from '@theia/core/shared/inversify';
import { injectable, interfaces } from '@theia/core/shared/inversify';
import { createPreferenceProxy, PreferenceProxy, PreferenceService, PreferenceContribution, PreferenceSchema } from '@theia/core/lib/browser';

export const FileNavigatorConfigSchema: PreferenceSchema = {
'type': 'object',
properties: {
Expand All @@ -35,14 +34,21 @@ export interface FileNavigatorConfiguration {
export const FileNavigatorPreferences = Symbol('NavigatorPreferences');
export type FileNavigatorPreferences = PreferenceProxy<FileNavigatorConfiguration>;

export function createNavigatorPreferences(preferences: PreferenceService): FileNavigatorPreferences {
return createPreferenceProxy(preferences, FileNavigatorConfigSchema);
@injectable()
export class FileNavigatorPreferenceContribution implements PreferenceContribution {
schema = 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).toSelf().inSingletonScope();
bind(PreferenceContribution).toService(FileNavigatorPreferenceContribution);
}
Loading

0 comments on commit 13618b2

Please sign in to comment.