@theia/preferences 1.45.0 → 1.46.0-next.72

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 (130) hide show
  1. package/README.md +81 -81
  2. package/lib/browser/abstract-resource-preference-provider.d.ts +47 -47
  3. package/lib/browser/abstract-resource-preference-provider.js +240 -240
  4. package/lib/browser/abstract-resource-preference-provider.spec.d.ts +1 -1
  5. package/lib/browser/abstract-resource-preference-provider.spec.js +83 -83
  6. package/lib/browser/folder-preference-provider.d.ts +20 -20
  7. package/lib/browser/folder-preference-provider.js +59 -59
  8. package/lib/browser/folders-preferences-provider.d.ts +27 -27
  9. package/lib/browser/folders-preferences-provider.js +245 -245
  10. package/lib/browser/index.d.ts +7 -7
  11. package/lib/browser/index.js +34 -34
  12. package/lib/browser/monaco-jsonc-editor.d.ts +9 -9
  13. package/lib/browser/monaco-jsonc-editor.js +80 -80
  14. package/lib/browser/package.spec.js +25 -25
  15. package/lib/browser/preference-bindings.d.ts +4 -4
  16. package/lib/browser/preference-bindings.js +63 -63
  17. package/lib/browser/preference-frontend-module.d.ts +6 -6
  18. package/lib/browser/preference-frontend-module.js +52 -52
  19. package/lib/browser/preference-open-handler.d.ts +9 -9
  20. package/lib/browser/preference-open-handler.js +64 -64
  21. package/lib/browser/preference-transaction-manager.d.ts +100 -100
  22. package/lib/browser/preference-transaction-manager.js +293 -293
  23. package/lib/browser/preference-tree-model.d.ts +60 -60
  24. package/lib/browser/preference-tree-model.js +243 -243
  25. package/lib/browser/preferences-contribution.d.ts +37 -37
  26. package/lib/browser/preferences-contribution.js +280 -280
  27. package/lib/browser/preferences-json-schema-contribution.d.ts +17 -17
  28. package/lib/browser/preferences-json-schema-contribution.js +91 -91
  29. package/lib/browser/preferences-monaco-contribution.d.ts +1 -1
  30. package/lib/browser/preferences-monaco-contribution.js +27 -27
  31. package/lib/browser/section-preference-provider.d.ts +21 -21
  32. package/lib/browser/section-preference-provider.js +96 -96
  33. package/lib/browser/user-configs-preference-provider.d.ts +22 -22
  34. package/lib/browser/user-configs-preference-provider.js +137 -137
  35. package/lib/browser/user-preference-provider.d.ts +13 -13
  36. package/lib/browser/user-preference-provider.js +41 -41
  37. package/lib/browser/util/preference-scope-command-manager.d.ts +17 -17
  38. package/lib/browser/util/preference-scope-command-manager.js +87 -87
  39. package/lib/browser/util/preference-tree-generator.d.ts +31 -31
  40. package/lib/browser/util/preference-tree-generator.js +237 -237
  41. package/lib/browser/util/preference-tree-label-provider.d.ts +11 -11
  42. package/lib/browser/util/preference-tree-label-provider.js +77 -77
  43. package/lib/browser/util/preference-tree-label-provider.spec.d.ts +1 -1
  44. package/lib/browser/util/preference-tree-label-provider.spec.js +87 -87
  45. package/lib/browser/util/preference-types.d.ts +62 -62
  46. package/lib/browser/util/preference-types.js +128 -128
  47. package/lib/browser/views/components/preference-array-input.d.ts +28 -28
  48. package/lib/browser/views/components/preference-array-input.js +180 -180
  49. package/lib/browser/views/components/preference-boolean-input.d.ts +17 -17
  50. package/lib/browser/views/components/preference-boolean-input.js +79 -79
  51. package/lib/browser/views/components/preference-file-input.d.ts +29 -29
  52. package/lib/browser/views/components/preference-file-input.js +110 -110
  53. package/lib/browser/views/components/preference-json-input.d.ts +19 -19
  54. package/lib/browser/views/components/preference-json-input.js +93 -93
  55. package/lib/browser/views/components/preference-markdown-renderer.d.ts +12 -12
  56. package/lib/browser/views/components/preference-markdown-renderer.js +81 -81
  57. package/lib/browser/views/components/preference-node-renderer-creator.d.ts +48 -48
  58. package/lib/browser/views/components/preference-node-renderer-creator.js +132 -132
  59. package/lib/browser/views/components/preference-node-renderer.d.ts +112 -112
  60. package/lib/browser/views/components/preference-node-renderer.js +441 -441
  61. package/lib/browser/views/components/preference-number-input.d.ts +34 -34
  62. package/lib/browser/views/components/preference-number-input.js +142 -142
  63. package/lib/browser/views/components/preference-select-input.d.ts +28 -28
  64. package/lib/browser/views/components/preference-select-input.js +138 -138
  65. package/lib/browser/views/components/preference-string-input.d.ts +17 -17
  66. package/lib/browser/views/components/preference-string-input.js +89 -89
  67. package/lib/browser/views/preference-editor-widget.d.ts +67 -67
  68. package/lib/browser/views/preference-editor-widget.js +363 -363
  69. package/lib/browser/views/preference-scope-tabbar-widget.d.ts +54 -54
  70. package/lib/browser/views/preference-scope-tabbar-widget.js +343 -343
  71. package/lib/browser/views/preference-searchbar-widget.d.ts +53 -53
  72. package/lib/browser/views/preference-searchbar-widget.js +173 -173
  73. package/lib/browser/views/preference-tree-widget.d.ts +17 -17
  74. package/lib/browser/views/preference-tree-widget.js +104 -104
  75. package/lib/browser/views/preference-widget-bindings.d.ts +3 -3
  76. package/lib/browser/views/preference-widget-bindings.js +87 -87
  77. package/lib/browser/views/preference-widget.d.ts +36 -36
  78. package/lib/browser/views/preference-widget.js +126 -126
  79. package/lib/browser/workspace-file-preference-provider.d.ts +23 -23
  80. package/lib/browser/workspace-file-preference-provider.js +110 -110
  81. package/lib/browser/workspace-preference-provider.d.ts +28 -28
  82. package/lib/browser/workspace-preference-provider.js +142 -142
  83. package/package.json +10 -10
  84. package/src/browser/abstract-resource-preference-provider.spec.ts +95 -95
  85. package/src/browser/abstract-resource-preference-provider.ts +232 -232
  86. package/src/browser/folder-preference-provider.ts +58 -58
  87. package/src/browser/folders-preferences-provider.ts +244 -244
  88. package/src/browser/index.ts +23 -23
  89. package/src/browser/monaco-jsonc-editor.ts +67 -67
  90. package/src/browser/package.spec.ts +28 -28
  91. package/src/browser/preference-bindings.ts +65 -65
  92. package/src/browser/preference-frontend-module.ts +57 -57
  93. package/src/browser/preference-open-handler.ts +53 -53
  94. package/src/browser/preference-transaction-manager.ts +287 -287
  95. package/src/browser/preference-tree-model.ts +250 -250
  96. package/src/browser/preferences-contribution.ts +263 -263
  97. package/src/browser/preferences-json-schema-contribution.ts +86 -86
  98. package/src/browser/preferences-monaco-contribution.ts +27 -27
  99. package/src/browser/section-preference-provider.ts +83 -83
  100. package/src/browser/style/index.css +506 -506
  101. package/src/browser/style/preference-array.css +94 -94
  102. package/src/browser/style/preference-context-menu.css +74 -74
  103. package/src/browser/style/preference-file.css +31 -31
  104. package/src/browser/style/preference-object.css +49 -49
  105. package/src/browser/style/search-input.css +66 -66
  106. package/src/browser/user-configs-preference-provider.ts +127 -127
  107. package/src/browser/user-preference-provider.ts +35 -35
  108. package/src/browser/util/preference-scope-command-manager.ts +75 -75
  109. package/src/browser/util/preference-tree-generator.ts +226 -226
  110. package/src/browser/util/preference-tree-label-provider.spec.ts +108 -108
  111. package/src/browser/util/preference-tree-label-provider.ts +64 -64
  112. package/src/browser/util/preference-types.ts +169 -169
  113. package/src/browser/views/components/preference-array-input.ts +174 -174
  114. package/src/browser/views/components/preference-boolean-input.ts +69 -69
  115. package/src/browser/views/components/preference-file-input.ts +104 -104
  116. package/src/browser/views/components/preference-json-input.ts +78 -78
  117. package/src/browser/views/components/preference-markdown-renderer.ts +68 -68
  118. package/src/browser/views/components/preference-node-renderer-creator.ts +141 -141
  119. package/src/browser/views/components/preference-node-renderer.ts +477 -477
  120. package/src/browser/views/components/preference-number-input.ts +147 -147
  121. package/src/browser/views/components/preference-select-input.ts +131 -131
  122. package/src/browser/views/components/preference-string-input.ts +76 -76
  123. package/src/browser/views/preference-editor-widget.ts +349 -349
  124. package/src/browser/views/preference-scope-tabbar-widget.tsx +344 -344
  125. package/src/browser/views/preference-searchbar-widget.tsx +183 -183
  126. package/src/browser/views/preference-tree-widget.tsx +93 -93
  127. package/src/browser/views/preference-widget-bindings.ts +102 -102
  128. package/src/browser/views/preference-widget.tsx +117 -117
  129. package/src/browser/workspace-file-preference-provider.ts +100 -100
  130. package/src/browser/workspace-preference-provider.ts +134 -134
@@ -1,86 +1,86 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 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 { inject, injectable } from '@theia/core/shared/inversify';
18
- import URI from '@theia/core/lib/common/uri';
19
- import { InMemoryResources } from '@theia/core';
20
- import { JsonSchemaRegisterContext, JsonSchemaContribution } from '@theia/core/lib/browser/json-schema-store';
21
- import { PreferenceSchemaProvider } from '@theia/core/lib/browser/preferences/preference-contribution';
22
- import { PreferenceConfigurations } from '@theia/core/lib/browser/preferences/preference-configurations';
23
- import { PreferenceScope } from '@theia/core/lib/browser';
24
- import { WorkspaceService } from '@theia/workspace/lib/browser';
25
-
26
- const PREFERENCE_URI_PREFIX = 'vscode://schemas/settings/';
27
- const USER_STORAGE_PREFIX = 'user-storage:/';
28
-
29
- @injectable()
30
- export class PreferencesJsonSchemaContribution implements JsonSchemaContribution {
31
- private serializeSchema = (scope: PreferenceScope) => JSON.stringify(this.schemaProvider.getSchema(scope));
32
-
33
- @inject(PreferenceSchemaProvider)
34
- protected readonly schemaProvider: PreferenceSchemaProvider;
35
-
36
- @inject(InMemoryResources)
37
- protected readonly inmemoryResources: InMemoryResources;
38
-
39
- @inject(PreferenceConfigurations)
40
- protected readonly preferenceConfigurations: PreferenceConfigurations;
41
-
42
- @inject(WorkspaceService)
43
- protected readonly workspaceService: WorkspaceService;
44
-
45
- registerSchemas(context: JsonSchemaRegisterContext): void {
46
- this.registerSchema(PreferenceScope.Default, context);
47
- this.registerSchema(PreferenceScope.User, context);
48
- this.registerSchema(PreferenceScope.Workspace, context);
49
- this.registerSchema(PreferenceScope.Folder, context);
50
-
51
- this.workspaceService.updateSchema('settings', { $ref: this.getSchemaURIForScope(PreferenceScope.Workspace).toString() });
52
- this.schemaProvider.onDidPreferenceSchemaChanged(() => this.updateInMemoryResources());
53
- }
54
-
55
- private registerSchema(scope: PreferenceScope, context: JsonSchemaRegisterContext): void {
56
- const scopeStr = PreferenceScope[scope].toLowerCase();
57
- const uri = new URI(PREFERENCE_URI_PREFIX + scopeStr);
58
-
59
- this.inmemoryResources.add(uri, this.serializeSchema(scope));
60
-
61
- context.registerSchema({
62
- fileMatch: this.getFileMatch(scopeStr),
63
- url: uri.toString()
64
- });
65
- }
66
-
67
- private updateInMemoryResources(): void {
68
- this.inmemoryResources.update(this.getSchemaURIForScope(PreferenceScope.Default),
69
- this.serializeSchema(+PreferenceScope.Default));
70
- this.inmemoryResources.update(this.getSchemaURIForScope(PreferenceScope.User),
71
- this.serializeSchema(+PreferenceScope.User));
72
- this.inmemoryResources.update(this.getSchemaURIForScope(PreferenceScope.Workspace),
73
- this.serializeSchema(+PreferenceScope.Workspace));
74
- this.inmemoryResources.update(this.getSchemaURIForScope(PreferenceScope.Folder),
75
- this.serializeSchema(+PreferenceScope.Folder));
76
- }
77
-
78
- private getSchemaURIForScope(scope: PreferenceScope): URI {
79
- return new URI(PREFERENCE_URI_PREFIX + PreferenceScope[scope].toLowerCase());
80
- }
81
-
82
- private getFileMatch(scope: string): string[] {
83
- const baseName = this.preferenceConfigurations.getConfigName() + '.json';
84
- return [baseName, new URI(USER_STORAGE_PREFIX + scope).resolve(baseName).toString()];
85
- }
86
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 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 { inject, injectable } from '@theia/core/shared/inversify';
18
+ import URI from '@theia/core/lib/common/uri';
19
+ import { InMemoryResources } from '@theia/core';
20
+ import { JsonSchemaRegisterContext, JsonSchemaContribution } from '@theia/core/lib/browser/json-schema-store';
21
+ import { PreferenceSchemaProvider } from '@theia/core/lib/browser/preferences/preference-contribution';
22
+ import { PreferenceConfigurations } from '@theia/core/lib/browser/preferences/preference-configurations';
23
+ import { PreferenceScope } from '@theia/core/lib/browser';
24
+ import { WorkspaceService } from '@theia/workspace/lib/browser';
25
+
26
+ const PREFERENCE_URI_PREFIX = 'vscode://schemas/settings/';
27
+ const USER_STORAGE_PREFIX = 'user-storage:/';
28
+
29
+ @injectable()
30
+ export class PreferencesJsonSchemaContribution implements JsonSchemaContribution {
31
+ private serializeSchema = (scope: PreferenceScope) => JSON.stringify(this.schemaProvider.getSchema(scope));
32
+
33
+ @inject(PreferenceSchemaProvider)
34
+ protected readonly schemaProvider: PreferenceSchemaProvider;
35
+
36
+ @inject(InMemoryResources)
37
+ protected readonly inmemoryResources: InMemoryResources;
38
+
39
+ @inject(PreferenceConfigurations)
40
+ protected readonly preferenceConfigurations: PreferenceConfigurations;
41
+
42
+ @inject(WorkspaceService)
43
+ protected readonly workspaceService: WorkspaceService;
44
+
45
+ registerSchemas(context: JsonSchemaRegisterContext): void {
46
+ this.registerSchema(PreferenceScope.Default, context);
47
+ this.registerSchema(PreferenceScope.User, context);
48
+ this.registerSchema(PreferenceScope.Workspace, context);
49
+ this.registerSchema(PreferenceScope.Folder, context);
50
+
51
+ this.workspaceService.updateSchema('settings', { $ref: this.getSchemaURIForScope(PreferenceScope.Workspace).toString() });
52
+ this.schemaProvider.onDidPreferenceSchemaChanged(() => this.updateInMemoryResources());
53
+ }
54
+
55
+ private registerSchema(scope: PreferenceScope, context: JsonSchemaRegisterContext): void {
56
+ const scopeStr = PreferenceScope[scope].toLowerCase();
57
+ const uri = new URI(PREFERENCE_URI_PREFIX + scopeStr);
58
+
59
+ this.inmemoryResources.add(uri, this.serializeSchema(scope));
60
+
61
+ context.registerSchema({
62
+ fileMatch: this.getFileMatch(scopeStr),
63
+ url: uri.toString()
64
+ });
65
+ }
66
+
67
+ private updateInMemoryResources(): void {
68
+ this.inmemoryResources.update(this.getSchemaURIForScope(PreferenceScope.Default),
69
+ this.serializeSchema(+PreferenceScope.Default));
70
+ this.inmemoryResources.update(this.getSchemaURIForScope(PreferenceScope.User),
71
+ this.serializeSchema(+PreferenceScope.User));
72
+ this.inmemoryResources.update(this.getSchemaURIForScope(PreferenceScope.Workspace),
73
+ this.serializeSchema(+PreferenceScope.Workspace));
74
+ this.inmemoryResources.update(this.getSchemaURIForScope(PreferenceScope.Folder),
75
+ this.serializeSchema(+PreferenceScope.Folder));
76
+ }
77
+
78
+ private getSchemaURIForScope(scope: PreferenceScope): URI {
79
+ return new URI(PREFERENCE_URI_PREFIX + PreferenceScope[scope].toLowerCase());
80
+ }
81
+
82
+ private getFileMatch(scope: string): string[] {
83
+ const baseName = this.preferenceConfigurations.getConfigName() + '.json';
84
+ return [baseName, new URI(USER_STORAGE_PREFIX + scope).resolve(baseName).toString()];
85
+ }
86
+ }
@@ -1,27 +1,27 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 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 * as monaco from '@theia/monaco-editor-core';
18
-
19
- monaco.languages.register({
20
- id: 'jsonc',
21
- 'aliases': [
22
- 'JSON with Comments'
23
- ],
24
- 'filenames': [
25
- 'settings.json'
26
- ]
27
- });
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 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 * as monaco from '@theia/monaco-editor-core';
18
+
19
+ monaco.languages.register({
20
+ id: 'jsonc',
21
+ 'aliases': [
22
+ 'JSON with Comments'
23
+ ],
24
+ 'filenames': [
25
+ 'settings.json'
26
+ ]
27
+ });
@@ -1,83 +1,83 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2019 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
- import { inject, injectable } from '@theia/core/shared/inversify';
18
- import URI from '@theia/core/lib/common/uri';
19
- import { AbstractResourcePreferenceProvider } from './abstract-resource-preference-provider';
20
- import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
21
- import { PreferenceConfigurations } from '@theia/core/lib/browser/preferences/preference-configurations';
22
-
23
- export const SectionPreferenceProviderUri = Symbol('SectionPreferenceProviderUri');
24
- export const SectionPreferenceProviderSection = Symbol('SectionPreferenceProviderSection');
25
-
26
- /**
27
- * This class encapsulates the logic of using separate files for some workspace configuration like 'launch.json' or 'tasks.json'.
28
- * Anything that is not a contributed section will be in the main config file.
29
- */
30
- @injectable()
31
- export abstract class SectionPreferenceProvider extends AbstractResourcePreferenceProvider {
32
-
33
- @inject(WorkspaceService)
34
- protected readonly workspaceService: WorkspaceService;
35
- @inject(SectionPreferenceProviderUri)
36
- protected readonly uri: URI;
37
- @inject(SectionPreferenceProviderSection)
38
- protected readonly section: string;
39
- @inject(PreferenceConfigurations)
40
- protected readonly preferenceConfigurations: PreferenceConfigurations;
41
-
42
- private _isSection?: boolean;
43
-
44
- private get isSection(): boolean {
45
- if (typeof this._isSection === 'undefined') {
46
- this._isSection = this.preferenceConfigurations.isSectionName(this.section);
47
- }
48
- return this._isSection;
49
- }
50
-
51
- protected getUri(): URI {
52
- return this.uri;
53
- }
54
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
- protected override parse(content: string): any {
56
- const prefs = super.parse(content);
57
- if (this.isSection) {
58
- if (prefs === undefined) {
59
- return undefined;
60
- }
61
- const result: { [k: string]: unknown } = {
62
-
63
- };
64
- result[this.section] = { ...prefs };
65
- return result;
66
- } else {
67
- return prefs;
68
- }
69
- }
70
-
71
- protected override getPath(preferenceName: string): string[] | undefined {
72
- if (!this.isSection) {
73
- return super.getPath(preferenceName);
74
- }
75
- if (preferenceName === this.section) {
76
- return [];
77
- }
78
- if (preferenceName.startsWith(`${this.section}.`)) {
79
- return [preferenceName.slice(this.section.length + 1)];
80
- }
81
- return undefined;
82
- }
83
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2019 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
+ import { inject, injectable } from '@theia/core/shared/inversify';
18
+ import URI from '@theia/core/lib/common/uri';
19
+ import { AbstractResourcePreferenceProvider } from './abstract-resource-preference-provider';
20
+ import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
21
+ import { PreferenceConfigurations } from '@theia/core/lib/browser/preferences/preference-configurations';
22
+
23
+ export const SectionPreferenceProviderUri = Symbol('SectionPreferenceProviderUri');
24
+ export const SectionPreferenceProviderSection = Symbol('SectionPreferenceProviderSection');
25
+
26
+ /**
27
+ * This class encapsulates the logic of using separate files for some workspace configuration like 'launch.json' or 'tasks.json'.
28
+ * Anything that is not a contributed section will be in the main config file.
29
+ */
30
+ @injectable()
31
+ export abstract class SectionPreferenceProvider extends AbstractResourcePreferenceProvider {
32
+
33
+ @inject(WorkspaceService)
34
+ protected readonly workspaceService: WorkspaceService;
35
+ @inject(SectionPreferenceProviderUri)
36
+ protected readonly uri: URI;
37
+ @inject(SectionPreferenceProviderSection)
38
+ protected readonly section: string;
39
+ @inject(PreferenceConfigurations)
40
+ protected readonly preferenceConfigurations: PreferenceConfigurations;
41
+
42
+ private _isSection?: boolean;
43
+
44
+ private get isSection(): boolean {
45
+ if (typeof this._isSection === 'undefined') {
46
+ this._isSection = this.preferenceConfigurations.isSectionName(this.section);
47
+ }
48
+ return this._isSection;
49
+ }
50
+
51
+ protected getUri(): URI {
52
+ return this.uri;
53
+ }
54
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
+ protected override parse(content: string): any {
56
+ const prefs = super.parse(content);
57
+ if (this.isSection) {
58
+ if (prefs === undefined) {
59
+ return undefined;
60
+ }
61
+ const result: { [k: string]: unknown } = {
62
+
63
+ };
64
+ result[this.section] = { ...prefs };
65
+ return result;
66
+ } else {
67
+ return prefs;
68
+ }
69
+ }
70
+
71
+ protected override getPath(preferenceName: string): string[] | undefined {
72
+ if (!this.isSection) {
73
+ return super.getPath(preferenceName);
74
+ }
75
+ if (preferenceName === this.section) {
76
+ return [];
77
+ }
78
+ if (preferenceName.startsWith(`${this.section}.`)) {
79
+ return [preferenceName.slice(this.section.length + 1)];
80
+ }
81
+ return undefined;
82
+ }
83
+ }