@theia/preferences 1.53.0-next.55 → 1.53.0-next.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +81 -81
  2. package/package.json +8 -8
  3. package/src/browser/abstract-resource-preference-provider.spec.ts +95 -95
  4. package/src/browser/abstract-resource-preference-provider.ts +232 -232
  5. package/src/browser/folder-preference-provider.ts +58 -58
  6. package/src/browser/folders-preferences-provider.ts +244 -244
  7. package/src/browser/index.ts +23 -23
  8. package/src/browser/monaco-jsonc-editor.ts +67 -67
  9. package/src/browser/package.spec.ts +28 -28
  10. package/src/browser/preference-bindings.ts +65 -65
  11. package/src/browser/preference-frontend-contribution.ts +38 -38
  12. package/src/browser/preference-frontend-module.ts +66 -66
  13. package/src/browser/preference-open-handler.ts +53 -53
  14. package/src/browser/preference-transaction-manager.ts +287 -287
  15. package/src/browser/preference-tree-model.ts +260 -260
  16. package/src/browser/preferences-contribution.ts +263 -263
  17. package/src/browser/preferences-json-schema-contribution.ts +86 -86
  18. package/src/browser/preferences-monaco-contribution.ts +27 -27
  19. package/src/browser/section-preference-provider.ts +83 -83
  20. package/src/browser/style/index.css +506 -506
  21. package/src/browser/style/preference-array.css +94 -94
  22. package/src/browser/style/preference-context-menu.css +74 -74
  23. package/src/browser/style/preference-file.css +31 -31
  24. package/src/browser/style/preference-object.css +49 -49
  25. package/src/browser/style/search-input.css +66 -66
  26. package/src/browser/user-configs-preference-provider.ts +127 -127
  27. package/src/browser/user-preference-provider.ts +35 -35
  28. package/src/browser/util/preference-layout.ts +381 -381
  29. package/src/browser/util/preference-scope-command-manager.ts +75 -75
  30. package/src/browser/util/preference-tree-generator.ts +260 -260
  31. package/src/browser/util/preference-tree-label-provider.spec.ts +110 -110
  32. package/src/browser/util/preference-tree-label-provider.ts +72 -72
  33. package/src/browser/util/preference-types.ts +177 -177
  34. package/src/browser/views/components/preference-array-input.ts +174 -174
  35. package/src/browser/views/components/preference-boolean-input.ts +69 -69
  36. package/src/browser/views/components/preference-file-input.ts +104 -104
  37. package/src/browser/views/components/preference-json-input.ts +78 -78
  38. package/src/browser/views/components/preference-markdown-renderer.ts +68 -68
  39. package/src/browser/views/components/preference-node-renderer-creator.ts +141 -141
  40. package/src/browser/views/components/preference-node-renderer.ts +477 -477
  41. package/src/browser/views/components/preference-number-input.ts +147 -147
  42. package/src/browser/views/components/preference-select-input.ts +131 -131
  43. package/src/browser/views/components/preference-string-input.ts +76 -76
  44. package/src/browser/views/preference-editor-widget.ts +349 -349
  45. package/src/browser/views/preference-scope-tabbar-widget.tsx +344 -344
  46. package/src/browser/views/preference-searchbar-widget.tsx +183 -183
  47. package/src/browser/views/preference-tree-widget.tsx +102 -102
  48. package/src/browser/views/preference-widget-bindings.ts +102 -102
  49. package/src/browser/views/preference-widget.tsx +118 -118
  50. package/src/browser/workspace-file-preference-provider.ts +100 -100
  51. package/src/browser/workspace-preference-provider.ts +134 -134
  52. package/src/common/cli-preferences.ts +22 -22
  53. package/src/node/preference-backend-module.ts +33 -33
  54. package/src/node/preference-cli-contribution.ts +48 -48
@@ -1,134 +1,134 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 Ericsson and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- /* eslint-disable @typescript-eslint/no-explicit-any */
18
-
19
- import { inject, injectable, postConstruct, named } from '@theia/core/shared/inversify';
20
- import URI from '@theia/core/lib/common/uri';
21
- import { DisposableCollection } from '@theia/core/lib/common/disposable';
22
- import { PreferenceScope, PreferenceProvider } from '@theia/core/lib/browser/preferences';
23
- import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
24
- import { WorkspaceFilePreferenceProviderFactory, WorkspaceFilePreferenceProvider } from './workspace-file-preference-provider';
25
-
26
- @injectable()
27
- export class WorkspacePreferenceProvider extends PreferenceProvider {
28
-
29
- @inject(WorkspaceService)
30
- protected readonly workspaceService: WorkspaceService;
31
-
32
- @inject(WorkspaceFilePreferenceProviderFactory)
33
- protected readonly workspaceFileProviderFactory: WorkspaceFilePreferenceProviderFactory;
34
-
35
- @inject(PreferenceProvider) @named(PreferenceScope.Folder)
36
- protected readonly folderPreferenceProvider: PreferenceProvider;
37
-
38
- protected readonly toDisposeOnEnsureDelegateUpToDate = new DisposableCollection();
39
-
40
- @postConstruct()
41
- protected init(): void {
42
- this.workspaceService.ready.then(() => {
43
- // If there is no workspace after the workspace service is initialized, then no more work is needed for this provider to be ready.
44
- // If there is a workspace, then we wait for the new delegate to be ready before declaring this provider ready.
45
- if (!this.workspaceService.workspace) {
46
- this._ready.resolve();
47
- }
48
- });
49
- this.workspaceService.onWorkspaceLocationChanged(() => this.ensureDelegateUpToDate());
50
- this.workspaceService.onWorkspaceChanged(() => this.ensureDelegateUpToDate());
51
- }
52
-
53
- override getConfigUri(resourceUri: string | undefined = this.ensureResourceUri(), sectionName?: string): URI | undefined {
54
- return this.delegate?.getConfigUri(resourceUri, sectionName);
55
- }
56
-
57
- override getContainingConfigUri(resourceUri: string | undefined = this.ensureResourceUri(), sectionName?: string): URI | undefined {
58
- return this.delegate?.getContainingConfigUri?.(resourceUri, sectionName);
59
- }
60
-
61
- protected _delegate: PreferenceProvider | undefined;
62
- protected get delegate(): PreferenceProvider | undefined {
63
- return this._delegate;
64
- }
65
-
66
- protected ensureDelegateUpToDate(): void {
67
- const delegate = this.createDelegate();
68
- if (this._delegate !== delegate) {
69
- this.toDisposeOnEnsureDelegateUpToDate.dispose();
70
- this.toDispose.push(this.toDisposeOnEnsureDelegateUpToDate);
71
-
72
- this._delegate = delegate;
73
-
74
- if (delegate) {
75
- // If this provider has not yet declared itself ready, it should do so when the new delegate is ready.
76
- delegate.ready.then(() => this._ready.resolve(), () => { });
77
- }
78
-
79
- if (delegate instanceof WorkspaceFilePreferenceProvider) {
80
- this.toDisposeOnEnsureDelegateUpToDate.pushAll([
81
- delegate,
82
- delegate.onDidPreferencesChanged(changes => this.onDidPreferencesChangedEmitter.fire(changes))
83
- ]);
84
- }
85
- }
86
- }
87
-
88
- protected createDelegate(): PreferenceProvider | undefined {
89
- const workspace = this.workspaceService.workspace;
90
- if (!workspace) {
91
- return undefined;
92
- }
93
- if (!this.workspaceService.isMultiRootWorkspaceOpened) {
94
- return this.folderPreferenceProvider;
95
- }
96
- if (this._delegate instanceof WorkspaceFilePreferenceProvider && this._delegate.getConfigUri().isEqual(workspace.resource)) {
97
- return this._delegate;
98
- }
99
- return this.workspaceFileProviderFactory({
100
- workspaceUri: workspace.resource
101
- });
102
- }
103
-
104
- override get<T>(preferenceName: string, resourceUri: string | undefined = this.ensureResourceUri()): T | undefined {
105
- const delegate = this.delegate;
106
- return delegate ? delegate.get<T>(preferenceName, resourceUri) : undefined;
107
- }
108
-
109
- override resolve<T>(preferenceName: string, resourceUri: string | undefined = this.ensureResourceUri()): { value?: T, configUri?: URI } {
110
- const delegate = this.delegate;
111
- return delegate ? delegate.resolve<T>(preferenceName, resourceUri) : {};
112
- }
113
-
114
- getPreferences(resourceUri: string | undefined = this.ensureResourceUri()): { [p: string]: any } {
115
- const delegate = this.delegate;
116
- return delegate ? delegate.getPreferences(resourceUri) : {};
117
- }
118
-
119
- async setPreference(preferenceName: string, value: any, resourceUri: string | undefined = this.ensureResourceUri()): Promise<boolean> {
120
- const delegate = this.delegate;
121
- if (delegate) {
122
- return delegate.setPreference(preferenceName, value, resourceUri);
123
- }
124
- return false;
125
- }
126
-
127
- protected ensureResourceUri(): string | undefined {
128
- if (this.workspaceService.workspace && !this.workspaceService.isMultiRootWorkspaceOpened) {
129
- return this.workspaceService.workspace.resource.toString();
130
- }
131
- return undefined;
132
- }
133
-
134
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 Ericsson and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ /* eslint-disable @typescript-eslint/no-explicit-any */
18
+
19
+ import { inject, injectable, postConstruct, named } from '@theia/core/shared/inversify';
20
+ import URI from '@theia/core/lib/common/uri';
21
+ import { DisposableCollection } from '@theia/core/lib/common/disposable';
22
+ import { PreferenceScope, PreferenceProvider } from '@theia/core/lib/browser/preferences';
23
+ import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
24
+ import { WorkspaceFilePreferenceProviderFactory, WorkspaceFilePreferenceProvider } from './workspace-file-preference-provider';
25
+
26
+ @injectable()
27
+ export class WorkspacePreferenceProvider extends PreferenceProvider {
28
+
29
+ @inject(WorkspaceService)
30
+ protected readonly workspaceService: WorkspaceService;
31
+
32
+ @inject(WorkspaceFilePreferenceProviderFactory)
33
+ protected readonly workspaceFileProviderFactory: WorkspaceFilePreferenceProviderFactory;
34
+
35
+ @inject(PreferenceProvider) @named(PreferenceScope.Folder)
36
+ protected readonly folderPreferenceProvider: PreferenceProvider;
37
+
38
+ protected readonly toDisposeOnEnsureDelegateUpToDate = new DisposableCollection();
39
+
40
+ @postConstruct()
41
+ protected init(): void {
42
+ this.workspaceService.ready.then(() => {
43
+ // If there is no workspace after the workspace service is initialized, then no more work is needed for this provider to be ready.
44
+ // If there is a workspace, then we wait for the new delegate to be ready before declaring this provider ready.
45
+ if (!this.workspaceService.workspace) {
46
+ this._ready.resolve();
47
+ }
48
+ });
49
+ this.workspaceService.onWorkspaceLocationChanged(() => this.ensureDelegateUpToDate());
50
+ this.workspaceService.onWorkspaceChanged(() => this.ensureDelegateUpToDate());
51
+ }
52
+
53
+ override getConfigUri(resourceUri: string | undefined = this.ensureResourceUri(), sectionName?: string): URI | undefined {
54
+ return this.delegate?.getConfigUri(resourceUri, sectionName);
55
+ }
56
+
57
+ override getContainingConfigUri(resourceUri: string | undefined = this.ensureResourceUri(), sectionName?: string): URI | undefined {
58
+ return this.delegate?.getContainingConfigUri?.(resourceUri, sectionName);
59
+ }
60
+
61
+ protected _delegate: PreferenceProvider | undefined;
62
+ protected get delegate(): PreferenceProvider | undefined {
63
+ return this._delegate;
64
+ }
65
+
66
+ protected ensureDelegateUpToDate(): void {
67
+ const delegate = this.createDelegate();
68
+ if (this._delegate !== delegate) {
69
+ this.toDisposeOnEnsureDelegateUpToDate.dispose();
70
+ this.toDispose.push(this.toDisposeOnEnsureDelegateUpToDate);
71
+
72
+ this._delegate = delegate;
73
+
74
+ if (delegate) {
75
+ // If this provider has not yet declared itself ready, it should do so when the new delegate is ready.
76
+ delegate.ready.then(() => this._ready.resolve(), () => { });
77
+ }
78
+
79
+ if (delegate instanceof WorkspaceFilePreferenceProvider) {
80
+ this.toDisposeOnEnsureDelegateUpToDate.pushAll([
81
+ delegate,
82
+ delegate.onDidPreferencesChanged(changes => this.onDidPreferencesChangedEmitter.fire(changes))
83
+ ]);
84
+ }
85
+ }
86
+ }
87
+
88
+ protected createDelegate(): PreferenceProvider | undefined {
89
+ const workspace = this.workspaceService.workspace;
90
+ if (!workspace) {
91
+ return undefined;
92
+ }
93
+ if (!this.workspaceService.isMultiRootWorkspaceOpened) {
94
+ return this.folderPreferenceProvider;
95
+ }
96
+ if (this._delegate instanceof WorkspaceFilePreferenceProvider && this._delegate.getConfigUri().isEqual(workspace.resource)) {
97
+ return this._delegate;
98
+ }
99
+ return this.workspaceFileProviderFactory({
100
+ workspaceUri: workspace.resource
101
+ });
102
+ }
103
+
104
+ override get<T>(preferenceName: string, resourceUri: string | undefined = this.ensureResourceUri()): T | undefined {
105
+ const delegate = this.delegate;
106
+ return delegate ? delegate.get<T>(preferenceName, resourceUri) : undefined;
107
+ }
108
+
109
+ override resolve<T>(preferenceName: string, resourceUri: string | undefined = this.ensureResourceUri()): { value?: T, configUri?: URI } {
110
+ const delegate = this.delegate;
111
+ return delegate ? delegate.resolve<T>(preferenceName, resourceUri) : {};
112
+ }
113
+
114
+ getPreferences(resourceUri: string | undefined = this.ensureResourceUri()): { [p: string]: any } {
115
+ const delegate = this.delegate;
116
+ return delegate ? delegate.getPreferences(resourceUri) : {};
117
+ }
118
+
119
+ async setPreference(preferenceName: string, value: any, resourceUri: string | undefined = this.ensureResourceUri()): Promise<boolean> {
120
+ const delegate = this.delegate;
121
+ if (delegate) {
122
+ return delegate.setPreference(preferenceName, value, resourceUri);
123
+ }
124
+ return false;
125
+ }
126
+
127
+ protected ensureResourceUri(): string | undefined {
128
+ if (this.workspaceService.workspace && !this.workspaceService.isMultiRootWorkspaceOpened) {
129
+ return this.workspaceService.workspace.resource.toString();
130
+ }
131
+ return undefined;
132
+ }
133
+
134
+ }
@@ -1,22 +1,22 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2024 Typefox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- export const CliPreferences = Symbol('CliPreferences');
18
- export const CliPreferencesPath = '/services/cli-preferences';
19
-
20
- export interface CliPreferences {
21
- getPreferences(): Promise<[string, unknown][]>;
22
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2024 Typefox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ export const CliPreferences = Symbol('CliPreferences');
18
+ export const CliPreferencesPath = '/services/cli-preferences';
19
+
20
+ export interface CliPreferences {
21
+ getPreferences(): Promise<[string, unknown][]>;
22
+ }
@@ -1,33 +1,33 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2024 Typefox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { ContainerModule } from '@theia/core/shared/inversify';
18
- import { CliContribution } from '@theia/core/lib/node/cli';
19
- import { PreferenceCliContribution } from './preference-cli-contribution';
20
- import { ConnectionContainerModule } from '@theia/core/lib/node/messaging/connection-container-module';
21
- import { CliPreferences, CliPreferencesPath } from '../common/cli-preferences';
22
-
23
- const preferencesConnectionModule = ConnectionContainerModule.create(({ bind, bindBackendService }) => {
24
- bindBackendService(CliPreferencesPath, CliPreferences);
25
- });
26
-
27
- export default new ContainerModule(bind => {
28
- bind(PreferenceCliContribution).toSelf().inSingletonScope();
29
- bind(CliPreferences).toService(PreferenceCliContribution);
30
- bind(CliContribution).toService(PreferenceCliContribution);
31
-
32
- bind(ConnectionContainerModule).toConstantValue(preferencesConnectionModule);
33
- });
1
+ // *****************************************************************************
2
+ // Copyright (C) 2024 Typefox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { ContainerModule } from '@theia/core/shared/inversify';
18
+ import { CliContribution } from '@theia/core/lib/node/cli';
19
+ import { PreferenceCliContribution } from './preference-cli-contribution';
20
+ import { ConnectionContainerModule } from '@theia/core/lib/node/messaging/connection-container-module';
21
+ import { CliPreferences, CliPreferencesPath } from '../common/cli-preferences';
22
+
23
+ const preferencesConnectionModule = ConnectionContainerModule.create(({ bind, bindBackendService }) => {
24
+ bindBackendService(CliPreferencesPath, CliPreferences);
25
+ });
26
+
27
+ export default new ContainerModule(bind => {
28
+ bind(PreferenceCliContribution).toSelf().inSingletonScope();
29
+ bind(CliPreferences).toService(PreferenceCliContribution);
30
+ bind(CliContribution).toService(PreferenceCliContribution);
31
+
32
+ bind(ConnectionContainerModule).toConstantValue(preferencesConnectionModule);
33
+ });
@@ -1,48 +1,48 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2024 Typefox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { injectable } from '@theia/core/shared/inversify';
18
- import { Argv } from '@theia/core/shared/yargs';
19
- import { CliContribution } from '@theia/core/lib/node/cli';
20
- import { CliPreferences } from '../common/cli-preferences';
21
-
22
- @injectable()
23
- export class PreferenceCliContribution implements CliContribution, CliPreferences {
24
-
25
- protected preferences: [string, unknown][] = [];
26
-
27
- configure(conf: Argv<{}>): void {
28
- conf.option('set-preference', {
29
- nargs: 1,
30
- desc: 'sets the specified preference'
31
- });
32
- }
33
-
34
- setArguments(args: Record<string, unknown>): void {
35
- if (args.setPreference) {
36
- const preferences: string[] = args.setPreference instanceof Array ? args.setPreference : [args.setPreference];
37
- for (const preference of preferences) {
38
- const firstEqualIndex = preference.indexOf('=');
39
- this.preferences.push([preference.substring(0, firstEqualIndex), JSON.parse(preference.substring(firstEqualIndex + 1))]);
40
- }
41
- }
42
- }
43
-
44
- async getPreferences(): Promise<[string, unknown][]> {
45
- return this.preferences;
46
- }
47
-
48
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2024 Typefox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { injectable } from '@theia/core/shared/inversify';
18
+ import { Argv } from '@theia/core/shared/yargs';
19
+ import { CliContribution } from '@theia/core/lib/node/cli';
20
+ import { CliPreferences } from '../common/cli-preferences';
21
+
22
+ @injectable()
23
+ export class PreferenceCliContribution implements CliContribution, CliPreferences {
24
+
25
+ protected preferences: [string, unknown][] = [];
26
+
27
+ configure(conf: Argv<{}>): void {
28
+ conf.option('set-preference', {
29
+ nargs: 1,
30
+ desc: 'sets the specified preference'
31
+ });
32
+ }
33
+
34
+ setArguments(args: Record<string, unknown>): void {
35
+ if (args.setPreference) {
36
+ const preferences: string[] = args.setPreference instanceof Array ? args.setPreference : [args.setPreference];
37
+ for (const preference of preferences) {
38
+ const firstEqualIndex = preference.indexOf('=');
39
+ this.preferences.push([preference.substring(0, firstEqualIndex), JSON.parse(preference.substring(firstEqualIndex + 1))]);
40
+ }
41
+ }
42
+ }
43
+
44
+ async getPreferences(): Promise<[string, unknown][]> {
45
+ return this.preferences;
46
+ }
47
+
48
+ }