@opensumi/ide-core-browser 2.21.8-rc-1670567192.0 → 2.21.8
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.
- package/lib/components/actions/index.d.ts.map +1 -1
- package/lib/components/actions/index.js +22 -2
- package/lib/components/actions/index.js.map +1 -1
- package/lib/components/tree/tree.module.less +0 -1
- package/lib/contextkey/testing.d.ts +0 -1
- package/lib/contextkey/testing.d.ts.map +1 -1
- package/lib/contextkey/testing.js +1 -2
- package/lib/contextkey/testing.js.map +1 -1
- package/lib/menu/next/menu.contrib.interface.d.ts +2 -3
- package/lib/menu/next/menu.contrib.interface.d.ts.map +1 -1
- package/lib/menu/next/menu.contrib.interface.js.map +1 -1
- package/lib/preferences/preference-configurations.js +1 -1
- package/lib/preferences/preference-configurations.js.map +1 -1
- package/lib/react-providers/config-provider.d.ts +0 -4
- package/lib/react-providers/config-provider.d.ts.map +1 -1
- package/lib/react-providers/config-provider.js.map +1 -1
- package/lib/services/storage-service.d.ts.map +1 -1
- package/lib/services/storage-service.js +1 -7
- package/lib/services/storage-service.js.map +1 -1
- package/lib/utils/label.d.ts.map +1 -1
- package/lib/utils/label.js +9 -16
- package/lib/utils/label.js.map +1 -1
- package/package.json +6 -7
- package/src/application/application-state-service.ts +0 -54
- package/src/application/application.service.ts +0 -51
- package/src/application/index.ts +0 -2
- package/src/authentication/authentication.contribution.ts +0 -35
- package/src/authentication/authentication.service.ts +0 -517
- package/src/bootstrap/app.ts +0 -745
- package/src/bootstrap/app.view.tsx +0 -88
- package/src/bootstrap/connection.ts +0 -116
- package/src/bootstrap/index.ts +0 -3
- package/src/bootstrap/inner-providers.ts +0 -297
- package/src/bootstrap/lifecycle.service.ts +0 -19
- package/src/browser-module.ts +0 -24
- package/src/common/common.command.ts +0 -977
- package/src/common/common.contribution.ts +0 -343
- package/src/common/common.define.ts +0 -55
- package/src/common/common.module.ts +0 -33
- package/src/common/common.storage.ts +0 -22
- package/src/common/container-id.ts +0 -12
- package/src/common/index.ts +0 -4
- package/src/components/actions/index.tsx +0 -486
- package/src/components/actions/placements.ts +0 -47
- package/src/components/actions/styles.module.less +0 -144
- package/src/components/badge/index.tsx +0 -1
- package/src/components/index.ts +0 -26
- package/src/components/layout/box-panel.tsx +0 -88
- package/src/components/layout/default-layout.tsx +0 -61
- package/src/components/layout/index.ts +0 -4
- package/src/components/layout/layout.ts +0 -80
- package/src/components/layout/split-panel.service.ts +0 -56
- package/src/components/layout/split-panel.tsx +0 -296
- package/src/components/layout/styles.module.less +0 -21
- package/src/components/loading/index.ts +0 -1
- package/src/components/loading/loading.less +0 -14
- package/src/components/loading/loading.view.tsx +0 -7
- package/src/components/loading/media/loading-dark.svg +0 -52
- package/src/components/loading/media/loading-hc.svg +0 -52
- package/src/components/loading/media/loading.svg +0 -52
- package/src/components/popover/styles.module.less +0 -81
- package/src/components/portal/index.tsx +0 -13
- package/src/components/progressbar/index.tsx +0 -16
- package/src/components/progressbar/styles.module.less +0 -31
- package/src/components/recycle-tree/index.ts +0 -1
- package/src/components/recycle-tree/recycle-tree.view.tsx +0 -368
- package/src/components/resize/resize.module.less +0 -78
- package/src/components/resize/resize.tsx +0 -663
- package/src/components/scroll/index.tsx +0 -386
- package/src/components/scroll/scroll.module.less +0 -108
- package/src/components/scrollbar/index.ts +0 -1
- package/src/components/scrollbar/scrollbar.less +0 -36
- package/src/components/scrollbar/scrollbar.view.ts +0 -8
- package/src/components/select/index.tsx +0 -12
- package/src/components/select/styles.less +0 -6
- package/src/components/tree/index.ts +0 -3
- package/src/components/tree/tree-node.view.tsx +0 -546
- package/src/components/tree/tree.module.less +0 -297
- package/src/components/tree/tree.view.tsx +0 -486
- package/src/context-key.ts +0 -48
- package/src/contextkey/dialog.ts +0 -3
- package/src/contextkey/explorer.ts +0 -26
- package/src/contextkey/index.ts +0 -6
- package/src/contextkey/outline.ts +0 -4
- package/src/contextkey/resource.ts +0 -61
- package/src/contextkey/terminal.ts +0 -7
- package/src/contextkey/testing.ts +0 -9
- package/src/contextkey/workspace.ts +0 -7
- package/src/core-preferences.ts +0 -318
- package/src/dom/index.ts +0 -176
- package/src/encoding-registry.ts +0 -83
- package/src/extensions/extensions-point.service.ts +0 -78
- package/src/extensions/index.ts +0 -3
- package/src/extensions/schema/browserViews.ts +0 -96
- package/src/extensions/schema/menu.ts +0 -245
- package/src/extensions/schema/opensumiExtensionPackageSchema.ts +0 -12
- package/src/extensions/schema/toolbar.ts +0 -338
- package/src/extensions/schema/vscodeExtensionPackageSchema.ts +0 -330
- package/src/fs/index.ts +0 -12
- package/src/hash-calculate/hash-calculate.contribution.ts +0 -19
- package/src/index.ts +0 -42
- package/src/keybinding/index.ts +0 -1
- package/src/keybinding/keybinding.ts +0 -908
- package/src/keyboard/index.ts +0 -3
- package/src/keyboard/keyboard-layout-provider.ts +0 -412
- package/src/keyboard/keyboard-layout-service.ts +0 -449
- package/src/keyboard/keys.ts +0 -748
- package/src/keyboard/layouts/_.contribution.ts +0 -24
- package/src/keyboard/layouts/cz.win.ts +0 -168
- package/src/keyboard/layouts/de-swiss.win.ts +0 -168
- package/src/keyboard/layouts/de.darwin.ts +0 -131
- package/src/keyboard/layouts/de.linux.ts +0 -186
- package/src/keyboard/layouts/de.win.ts +0 -168
- package/src/keyboard/layouts/dk.win.ts +0 -168
- package/src/keyboard/layouts/dvorak.darwin.ts +0 -131
- package/src/keyboard/layouts/en-belgian.win.ts +0 -168
- package/src/keyboard/layouts/en-ext.darwin.ts +0 -131
- package/src/keyboard/layouts/en-in.win.ts +0 -168
- package/src/keyboard/layouts/en-intl.darwin.ts +0 -131
- package/src/keyboard/layouts/en-intl.win.ts +0 -168
- package/src/keyboard/layouts/en-uk.darwin.ts +0 -131
- package/src/keyboard/layouts/en-uk.win.ts +0 -168
- package/src/keyboard/layouts/en.darwin.ts +0 -139
- package/src/keyboard/layouts/en.linux.ts +0 -186
- package/src/keyboard/layouts/en.win.ts +0 -173
- package/src/keyboard/layouts/es-latin.win.ts +0 -168
- package/src/keyboard/layouts/es.darwin.ts +0 -131
- package/src/keyboard/layouts/es.linux.ts +0 -186
- package/src/keyboard/layouts/es.win.ts +0 -168
- package/src/keyboard/layouts/fr.darwin.ts +0 -131
- package/src/keyboard/layouts/fr.linux.ts +0 -186
- package/src/keyboard/layouts/fr.win.ts +0 -168
- package/src/keyboard/layouts/hu.win.ts +0 -168
- package/src/keyboard/layouts/it.darwin.ts +0 -131
- package/src/keyboard/layouts/it.win.ts +0 -168
- package/src/keyboard/layouts/jp-roman.darwin.ts +0 -131
- package/src/keyboard/layouts/jp.darwin.ts +0 -131
- package/src/keyboard/layouts/ko.darwin.ts +0 -131
- package/src/keyboard/layouts/layout.contribution.darwin.ts +0 -23
- package/src/keyboard/layouts/layout.contribution.linux.ts +0 -12
- package/src/keyboard/layouts/layout.contribution.ts +0 -9
- package/src/keyboard/layouts/layout.contribution.win.ts +0 -29
- package/src/keyboard/layouts/no.win.ts +0 -168
- package/src/keyboard/layouts/pl.darwin.ts +0 -131
- package/src/keyboard/layouts/pl.win.ts +0 -168
- package/src/keyboard/layouts/pt-br.win.ts +0 -169
- package/src/keyboard/layouts/pt.darwin.ts +0 -131
- package/src/keyboard/layouts/pt.win.ts +0 -168
- package/src/keyboard/layouts/ru.darwin.ts +0 -131
- package/src/keyboard/layouts/ru.linux.ts +0 -186
- package/src/keyboard/layouts/ru.win.ts +0 -168
- package/src/keyboard/layouts/sv.darwin.ts +0 -131
- package/src/keyboard/layouts/sv.win.ts +0 -168
- package/src/keyboard/layouts/thai.win.ts +0 -168
- package/src/keyboard/layouts/tr.win.ts +0 -168
- package/src/keyboard/layouts/zh-hans.darwin.ts +0 -131
- package/src/layout/accordion/tab-bar-toolbar.tsx +0 -59
- package/src/layout/accordion/view-context-key.registry.ts +0 -34
- package/src/layout/constants.ts +0 -7
- package/src/layout/index.ts +0 -5
- package/src/layout/layout-hooks.ts +0 -68
- package/src/layout/layout-state.ts +0 -107
- package/src/layout/layout.interface.ts +0 -101
- package/src/layout/layout.ts +0 -80
- package/src/layout/view-id.ts +0 -18
- package/src/logger/browser-logger.ts +0 -51
- package/src/logger/index.ts +0 -1
- package/src/markdown/index.tsx +0 -62
- package/src/menu/next/base.ts +0 -513
- package/src/menu/next/ctxmenu-service.ts +0 -188
- package/src/menu/next/index.ts +0 -10
- package/src/menu/next/menu-id.ts +0 -86
- package/src/menu/next/menu-service.ts +0 -252
- package/src/menu/next/menu-util.ts +0 -77
- package/src/menu/next/menu.contrib.interface.ts +0 -79
- package/src/menu/next/menu.interface.ts +0 -253
- package/src/menu/next/menubar-service.ts +0 -211
- package/src/menu/next/renderer/ctxmenu/base.ts +0 -18
- package/src/menu/next/renderer/ctxmenu/browser.ts +0 -45
- package/src/menu/next/renderer/ctxmenu/electron.ts +0 -207
- package/src/menu/next/toolbar-action.service.ts +0 -132
- package/src/monaco/index.ts +0 -128
- package/src/opener/command-opener.ts +0 -42
- package/src/opener/default-opener.ts +0 -31
- package/src/opener/http-opener.ts +0 -25
- package/src/opener/index.ts +0 -19
- package/src/opener/opener.contribution.ts +0 -57
- package/src/opener/opener.service.ts +0 -66
- package/src/preferences/early-preferences.ts +0 -117
- package/src/preferences/index.ts +0 -9
- package/src/preferences/preference-configurations.ts +0 -77
- package/src/preferences/preference-contribution.ts +0 -401
- package/src/preferences/preference-provider.ts +0 -414
- package/src/preferences/preference-proxy.ts +0 -292
- package/src/preferences/preference-scope.ts +0 -3
- package/src/preferences/preference-service.ts +0 -571
- package/src/preferences/settings.ts +0 -53
- package/src/preferences/types.ts +0 -111
- package/src/progress/index.ts +0 -58
- package/src/progress/progress-bar.tsx +0 -22
- package/src/progress/progress-indicator.ts +0 -90
- package/src/progress/progress.module.less +0 -46
- package/src/progress/progress.service.tsx +0 -429
- package/src/quick-open/index.ts +0 -655
- package/src/quick-open/recent-files.ts +0 -68
- package/src/raw-context-key.ts +0 -116
- package/src/react-hooks/event.tsx +0 -80
- package/src/react-hooks/hot-key.tsx +0 -58
- package/src/react-hooks/index.ts +0 -3
- package/src/react-hooks/injectable-hooks.tsx +0 -35
- package/src/react-hooks/portal-hooks.tsx +0 -38
- package/src/react-providers/config-provider.tsx +0 -263
- package/src/react-providers/index.tsx +0 -2
- package/src/react-providers/slot.module.less +0 -19
- package/src/react-providers/slot.tsx +0 -242
- package/src/services/clipboard.service.ts +0 -97
- package/src/services/credentials-service.ts +0 -91
- package/src/services/crypto-service.ts +0 -23
- package/src/services/external-uri.service.ts +0 -68
- package/src/services/index.ts +0 -7
- package/src/services/label-service.ts +0 -386
- package/src/services/status-bar-service.ts +0 -108
- package/src/services/storage-service.ts +0 -197
- package/src/style/codicons/README.md +0 -22
- package/src/style/codicons/codicon-animations.css +0 -15
- package/src/style/codicons/generator.js +0 -15
- package/src/style/entry.less +0 -25
- package/src/style/icon/fileicons/file-default.svg +0 -1
- package/src/style/icon/fileicons/folder-default.svg +0 -1
- package/src/style/icon/fileicons.less +0 -20
- package/src/style/icon/icon.ts +0 -543
- package/src/style/icon/ide-iconfont.ts +0 -13
- package/src/style/icon/index.less +0 -54
- package/src/style/icon/seti.woff +0 -0
- package/src/style/icon/symbol-icons/boolean-dark.svg +0 -3
- package/src/style/icon/symbol-icons/boolean-light.svg +0 -3
- package/src/style/icon/symbol-icons/class-dark.svg +0 -3
- package/src/style/icon/symbol-icons/class-light.svg +0 -3
- package/src/style/icon/symbol-icons/constant-dark.svg +0 -4
- package/src/style/icon/symbol-icons/constant-light.svg +0 -4
- package/src/style/icon/symbol-icons/enumerator-dark.svg +0 -3
- package/src/style/icon/symbol-icons/enumerator-item-dark.svg +0 -3
- package/src/style/icon/symbol-icons/enumerator-item-light.svg +0 -3
- package/src/style/icon/symbol-icons/enumerator-light.svg +0 -3
- package/src/style/icon/symbol-icons/event-dark.svg +0 -3
- package/src/style/icon/symbol-icons/event-light.svg +0 -3
- package/src/style/icon/symbol-icons/field-dark.svg +0 -3
- package/src/style/icon/symbol-icons/field-light.svg +0 -3
- package/src/style/icon/symbol-icons/file-dark.svg +0 -3
- package/src/style/icon/symbol-icons/file-light.svg +0 -3
- package/src/style/icon/symbol-icons/indexer-dark.svg +0 -3
- package/src/style/icon/symbol-icons/indexer-light.svg +0 -3
- package/src/style/icon/symbol-icons/interface-dark.svg +0 -3
- package/src/style/icon/symbol-icons/interface-light.svg +0 -3
- package/src/style/icon/symbol-icons/keyword-dark.svg +0 -3
- package/src/style/icon/symbol-icons/keyword-light.svg +0 -3
- package/src/style/icon/symbol-icons/method-dark.svg +0 -3
- package/src/style/icon/symbol-icons/method-light.svg +0 -3
- package/src/style/icon/symbol-icons/namespace-dark.svg +0 -3
- package/src/style/icon/symbol-icons/namespace-light.svg +0 -3
- package/src/style/icon/symbol-icons/numeric-dark.svg +0 -3
- package/src/style/icon/symbol-icons/numeric-light.svg +0 -3
- package/src/style/icon/symbol-icons/operator-dark.svg +0 -3
- package/src/style/icon/symbol-icons/operator-light.svg +0 -3
- package/src/style/icon/symbol-icons/property-dark.svg +0 -3
- package/src/style/icon/symbol-icons/property-light.svg +0 -3
- package/src/style/icon/symbol-icons/snippet-dark.svg +0 -3
- package/src/style/icon/symbol-icons/snippet-light.svg +0 -3
- package/src/style/icon/symbol-icons/string-dark.svg +0 -3
- package/src/style/icon/symbol-icons/string-light.svg +0 -3
- package/src/style/icon/symbol-icons/structure-dark.svg +0 -3
- package/src/style/icon/symbol-icons/structure-light.svg +0 -3
- package/src/style/icon/symbol-icons/symbol-icons.css +0 -284
- package/src/style/icon/symbol-icons/template-dark.svg +0 -3
- package/src/style/icon/symbol-icons/template-light.svg +0 -3
- package/src/style/icon/symbol-icons/variable-dark.svg +0 -3
- package/src/style/icon/symbol-icons/variable-light.svg +0 -3
- package/src/style/icon.less +0 -8
- package/src/style/index.less +0 -14
- package/src/style/monaco-override.less +0 -116
- package/src/style/normalize.less +0 -92
- package/src/style/octicons/octicons-cdn.css +0 -720
- package/src/style/octicons/octicons.css +0 -714
- package/src/style/octicons/octicons.html +0 -1882
- package/src/style/octicons/octicons.svg +0 -582
- package/src/style/octicons/octicons.ttf +0 -0
- package/src/style/override.less +0 -97
- package/src/style/toolbar.less +0 -199
- package/src/style/utilities.less +0 -8
- package/src/style/variable.less +0 -8
- package/src/terminal/index.ts +0 -7
- package/src/toolbar/components/auto-complete.tsx +0 -0
- package/src/toolbar/components/button.tsx +0 -440
- package/src/toolbar/components/index.ts +0 -2
- package/src/toolbar/components/select.tsx +0 -189
- package/src/toolbar/index.ts +0 -3
- package/src/toolbar/toolbar.popover.registry.ts +0 -32
- package/src/toolbar/toolbar.registry.ts +0 -352
- package/src/toolbar/toolbar.tsx +0 -710
- package/src/toolbar/types.ts +0 -383
- package/src/tree/index.ts +0 -3
- package/src/tree/tree-expansion.ts +0 -25
- package/src/tree/tree-selection.ts +0 -89
- package/src/tree/tree.ts +0 -294
- package/src/utils/create-overlay.tsx +0 -53
- package/src/utils/electron.ts +0 -92
- package/src/utils/env.ts +0 -26
- package/src/utils/icon.ts +0 -13
- package/src/utils/index.ts +0 -7
- package/src/utils/json.ts +0 -251
- package/src/utils/label.tsx +0 -36
- package/src/utils/parse.ts +0 -72
- package/src/utils/react-hooks.ts +0 -118
- package/src/variable/index.ts +0 -1
- package/src/variable/variable.ts +0 -84
- package/src/window/index.ts +0 -34
- package/src/window/window.service.ts +0 -100
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { Injectable, Autowired } from '@opensumi/di';
|
|
2
|
-
import { URI, ILogger } from '@opensumi/ide-core-common';
|
|
3
|
-
|
|
4
|
-
import { DefaultOpener } from './default-opener';
|
|
5
|
-
|
|
6
|
-
import { IOpenerService, IOpener } from '.';
|
|
7
|
-
|
|
8
|
-
@Injectable()
|
|
9
|
-
export class OpenerService implements IOpenerService {
|
|
10
|
-
@Autowired(ILogger)
|
|
11
|
-
private logger: ILogger;
|
|
12
|
-
|
|
13
|
-
@Autowired(DefaultOpener)
|
|
14
|
-
private defaultOpener: IOpener;
|
|
15
|
-
|
|
16
|
-
private openers: IOpener[] = [];
|
|
17
|
-
|
|
18
|
-
private async getOpeners(uri: URI) {
|
|
19
|
-
const filterResults = await Promise.all(
|
|
20
|
-
this.openers.map(async (opener) => {
|
|
21
|
-
try {
|
|
22
|
-
if (opener.handleURI) {
|
|
23
|
-
return await opener.handleURI(uri);
|
|
24
|
-
}
|
|
25
|
-
return await opener.handleScheme(uri.scheme);
|
|
26
|
-
} catch (e) {
|
|
27
|
-
this.logger.error(e);
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
}),
|
|
31
|
-
);
|
|
32
|
-
return this.openers.filter((_, index) => filterResults[index]);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public registerOpener(opener: IOpener) {
|
|
36
|
-
this.openers.push(opener);
|
|
37
|
-
return {
|
|
38
|
-
dispose: () => {
|
|
39
|
-
const index = this.openers.indexOf(opener);
|
|
40
|
-
if (index !== -1) {
|
|
41
|
-
this.openers.splice(index, 1);
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async open(uri: URI | string): Promise<boolean> {
|
|
48
|
-
if (typeof uri === 'string') {
|
|
49
|
-
uri = URI.parse(uri);
|
|
50
|
-
}
|
|
51
|
-
const openers = await this.getOpeners(uri);
|
|
52
|
-
|
|
53
|
-
for (const opener of openers) {
|
|
54
|
-
const handled = await opener.open(uri);
|
|
55
|
-
if (handled) {
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return this.defaultOpener.open(uri);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
dispose() {
|
|
64
|
-
this.openers = [];
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { PreferenceItem, Event, GeneralSettingsId, getLanguageId } from '@opensumi/ide-core-common';
|
|
2
|
-
|
|
3
|
-
import { IPreferences } from '../bootstrap';
|
|
4
|
-
|
|
5
|
-
import { PreferenceProvider } from './preference-provider';
|
|
6
|
-
import { PreferenceScope } from './preference-scope';
|
|
7
|
-
|
|
8
|
-
// 这些设置选项生效时间太早,并且可能在 app 生命周期外生效,不能只由 preference 服务进行管理
|
|
9
|
-
export interface IExternalPreferenceProvider<T = any> {
|
|
10
|
-
get(scope: PreferenceScope): T | undefined;
|
|
11
|
-
set(value: T, scope: PreferenceScope): void;
|
|
12
|
-
onDidChange?: Event<{ newValue?: T; oldValue?: T; scope: PreferenceScope }>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const providers = new Map<string, IExternalPreferenceProvider>();
|
|
16
|
-
|
|
17
|
-
export function registerExternalPreferenceProvider<T>(name: string, provider: IExternalPreferenceProvider<T>) {
|
|
18
|
-
if (providers.get(name)) {
|
|
19
|
-
return; // 不可覆盖,先注册的生效
|
|
20
|
-
}
|
|
21
|
-
providers.set(name, provider);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function getExternalPreferenceProvider(name: string) {
|
|
25
|
-
let provider = providers.get(name);
|
|
26
|
-
if (!provider) {
|
|
27
|
-
// 尝试使用delegate的配置名获取
|
|
28
|
-
const delegate = PreferenceProvider.PreferenceDelegates[name];
|
|
29
|
-
if (delegate) {
|
|
30
|
-
provider = providers.get(delegate.delegateTo);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return provider;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function getPreferenceThemeId(): string {
|
|
37
|
-
return getExternalPreference<string>(GeneralSettingsId.Theme).value as string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function getPreferenceIconThemeId(): string {
|
|
41
|
-
return getExternalPreference<string>(GeneralSettingsId.Icon).value as string;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* 如果要判断当前语言,请使用 `getLanguageId` 来判断。
|
|
46
|
-
* 因为集成方可能会在集成后自己设置后调用 `setLanguageId` 来更新默认语言,所以统一收口到 `getLanguageId`。
|
|
47
|
-
*/
|
|
48
|
-
export function getPreferenceLanguageId(defaultPreferences?: IPreferences): string {
|
|
49
|
-
// 因为语言加载的时机比较早,因此会优先从 defaultPreferences 里面读取
|
|
50
|
-
const langFromDefaultPreferences = defaultPreferences && defaultPreferences[GeneralSettingsId.Language];
|
|
51
|
-
return (
|
|
52
|
-
langFromDefaultPreferences || getExternalPreference<string>(GeneralSettingsId.Language).value || getLanguageId()
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// 默认使用 localStorage
|
|
57
|
-
export function registerLocalStorageProvider(key: string, workspaceFolder?: string) {
|
|
58
|
-
function getScopePrefix(scope: PreferenceScope) {
|
|
59
|
-
if (scope === PreferenceScope.Workspace) {
|
|
60
|
-
return workspaceFolder;
|
|
61
|
-
}
|
|
62
|
-
return scope;
|
|
63
|
-
}
|
|
64
|
-
registerExternalPreferenceProvider<string>(key, {
|
|
65
|
-
set: (value, scope) => {
|
|
66
|
-
if (scope >= PreferenceScope.Folder) {
|
|
67
|
-
// earlyPreference不支持针对作用域大于等于Folder的值设置
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (!workspaceFolder && scope > PreferenceScope.Default) {
|
|
72
|
-
// 不传入 workspaceDir 则只支持全局设置
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if ((global as any).localStorage) {
|
|
77
|
-
if (value !== undefined) {
|
|
78
|
-
localStorage.setItem(getScopePrefix(scope) + `:${key}`, value);
|
|
79
|
-
} else {
|
|
80
|
-
localStorage.removeItem(getScopePrefix(scope) + `:${key}`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
get: (scope) => {
|
|
85
|
-
if ((global as any).localStorage) {
|
|
86
|
-
return localStorage.getItem(getScopePrefix(scope) + `:${key}`) || undefined;
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function getExternalPreference<T>(
|
|
93
|
-
preferenceName: string,
|
|
94
|
-
schema?: PreferenceItem,
|
|
95
|
-
untilScope?: PreferenceScope,
|
|
96
|
-
): { value: T | undefined; scope: PreferenceScope } {
|
|
97
|
-
const scopes = untilScope
|
|
98
|
-
? PreferenceScope.getReversedScopes().filter((s) => s <= untilScope)
|
|
99
|
-
: PreferenceScope.getReversedScopes();
|
|
100
|
-
for (const scope of scopes) {
|
|
101
|
-
const value = providers.get(preferenceName)?.get(scope);
|
|
102
|
-
if (value !== undefined) {
|
|
103
|
-
return {
|
|
104
|
-
value,
|
|
105
|
-
scope,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return {
|
|
110
|
-
value: schema && schema.default,
|
|
111
|
-
scope: PreferenceScope.Default,
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export function getAllExternalProviders(): Array<[string, IExternalPreferenceProvider]> {
|
|
116
|
-
return Array.from(providers.entries());
|
|
117
|
-
}
|
package/src/preferences/index.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './preference-configurations';
|
|
2
|
-
export * from './preference-contribution';
|
|
3
|
-
export * from './preference-provider';
|
|
4
|
-
export * from './preference-scope';
|
|
5
|
-
export * from './preference-service';
|
|
6
|
-
export * from './preference-proxy';
|
|
7
|
-
export * from './early-preferences';
|
|
8
|
-
export * from './types';
|
|
9
|
-
export * from './settings';
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { Injectable, Autowired, Injector } from '@opensumi/di';
|
|
2
|
-
import { URI, createContributionProvider } from '@opensumi/ide-core-common';
|
|
3
|
-
import { ContributionProvider, DEFAULT_WORKSPACE_CONFIGURATION_DIR_NAME } from '@opensumi/ide-core-common';
|
|
4
|
-
|
|
5
|
-
import { AppConfig } from '../react-providers/config-provider';
|
|
6
|
-
|
|
7
|
-
export const PreferenceConfiguration = Symbol('PreferenceConfiguration');
|
|
8
|
-
|
|
9
|
-
export interface PreferenceConfiguration {
|
|
10
|
-
name: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function injectPreferenceConfigurations(injector: Injector): void {
|
|
14
|
-
createContributionProvider(injector, PreferenceConfiguration);
|
|
15
|
-
injector.addProviders({
|
|
16
|
-
token: PreferenceConfigurations,
|
|
17
|
-
useClass: PreferenceConfigurations,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
@Injectable()
|
|
22
|
-
export class PreferenceConfigurations {
|
|
23
|
-
@Autowired(AppConfig)
|
|
24
|
-
private readonly appConfig: AppConfig;
|
|
25
|
-
|
|
26
|
-
@Autowired(PreferenceConfiguration)
|
|
27
|
-
private readonly preferenceConfigurationProvider: ContributionProvider<PreferenceConfiguration>;
|
|
28
|
-
|
|
29
|
-
getPaths(): string[] {
|
|
30
|
-
if (this.appConfig.workspacePreferenceDirName) {
|
|
31
|
-
return [this.appConfig.workspacePreferenceDirName];
|
|
32
|
-
} else if (this.appConfig.preferenceDirName) {
|
|
33
|
-
return [this.appConfig.preferenceDirName];
|
|
34
|
-
}
|
|
35
|
-
return [DEFAULT_WORKSPACE_CONFIGURATION_DIR_NAME];
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public getConfigName(): string {
|
|
39
|
-
return 'settings';
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
protected sectionNames: string[] | undefined;
|
|
43
|
-
public getSectionNames(): string[] {
|
|
44
|
-
if (!this.sectionNames) {
|
|
45
|
-
this.sectionNames = this.preferenceConfigurationProvider.getContributions().map((p) => p.name);
|
|
46
|
-
}
|
|
47
|
-
return this.sectionNames;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public isSectionName(name: string): boolean {
|
|
51
|
-
return this.getSectionNames().indexOf(name) !== -1;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public isSectionUri(configUri: URI | undefined): boolean {
|
|
55
|
-
return !!configUri && this.isSectionName(this.getName(configUri));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public isConfigUri(configUri: URI | undefined): boolean {
|
|
59
|
-
return !!configUri && this.getName(configUri) === this.getConfigName();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
public getName(configUri: URI): string {
|
|
63
|
-
return configUri.path.name;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
public getPath(configUri: URI): string {
|
|
67
|
-
return configUri.parent.path.base;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public createUri(
|
|
71
|
-
folder: URI,
|
|
72
|
-
configPath: string = this.getPaths()[0],
|
|
73
|
-
configName: string = this.getConfigName(),
|
|
74
|
-
): URI {
|
|
75
|
-
return folder.resolve(configPath).resolve(configName + '.json');
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,401 +0,0 @@
|
|
|
1
|
-
import Ajv from 'ajv';
|
|
2
|
-
|
|
3
|
-
import { Injectable, Autowired, Injector } from '@opensumi/di';
|
|
4
|
-
import {
|
|
5
|
-
Mutable,
|
|
6
|
-
ContributionProvider,
|
|
7
|
-
Emitter,
|
|
8
|
-
Event,
|
|
9
|
-
ILogger,
|
|
10
|
-
Disposable,
|
|
11
|
-
IDisposable,
|
|
12
|
-
} from '@opensumi/ide-core-common';
|
|
13
|
-
import {
|
|
14
|
-
PreferenceSchema,
|
|
15
|
-
PreferenceSchemaProperties,
|
|
16
|
-
PreferenceDataSchema,
|
|
17
|
-
PreferenceItem,
|
|
18
|
-
PreferenceSchemaProperty,
|
|
19
|
-
PreferenceDataProperty,
|
|
20
|
-
JsonType,
|
|
21
|
-
} from '@opensumi/ide-core-common/lib/preferences/preference-schema';
|
|
22
|
-
|
|
23
|
-
import { AppConfig } from '../react-providers/config-provider';
|
|
24
|
-
|
|
25
|
-
import { PreferenceConfigurations, injectPreferenceConfigurations } from './preference-configurations';
|
|
26
|
-
import { PreferenceProvider, PreferenceProviderDataChange, IResolvedPreferences } from './preference-provider';
|
|
27
|
-
import { PreferenceScope } from './preference-scope';
|
|
28
|
-
|
|
29
|
-
export {
|
|
30
|
-
PreferenceSchema,
|
|
31
|
-
PreferenceSchemaProperties,
|
|
32
|
-
PreferenceDataSchema,
|
|
33
|
-
PreferenceItem,
|
|
34
|
-
PreferenceSchemaProperty,
|
|
35
|
-
PreferenceDataProperty,
|
|
36
|
-
JsonType,
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const PreferenceContribution = Symbol('PreferenceContribution');
|
|
40
|
-
export interface PreferenceContribution {
|
|
41
|
-
readonly schema: PreferenceSchema;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function injectPreferenceSchemaProvider(injector: Injector): void {
|
|
45
|
-
injectPreferenceConfigurations(injector);
|
|
46
|
-
injector.addProviders({
|
|
47
|
-
token: PreferenceSchemaProvider,
|
|
48
|
-
useClass: PreferenceSchemaProvider,
|
|
49
|
-
});
|
|
50
|
-
injector.addProviders({
|
|
51
|
-
token: PreferenceProvider,
|
|
52
|
-
tag: PreferenceScope.Default,
|
|
53
|
-
useClass: DefaultPreferenceProvider,
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface OverridePreferenceName {
|
|
58
|
-
preferenceName: string;
|
|
59
|
-
overrideIdentifier: string;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export namespace OverridePreferenceName {
|
|
63
|
-
export function is(arg: any): arg is OverridePreferenceName {
|
|
64
|
-
return !!arg && typeof arg === 'object' && 'preferenceName' in arg && 'overrideIdentifier' in arg;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const OVERRIDE_PROPERTY = '\\[(.*)\\]$';
|
|
69
|
-
export const OVERRIDE_PROPERTY_PATTERN = new RegExp(OVERRIDE_PROPERTY);
|
|
70
|
-
|
|
71
|
-
@Injectable()
|
|
72
|
-
export class PreferenceSchemaProvider extends PreferenceProvider {
|
|
73
|
-
@Autowired(PreferenceContribution)
|
|
74
|
-
protected readonly preferenceContributions: ContributionProvider<PreferenceContribution>;
|
|
75
|
-
private _validateFunction: Ajv.ValidateFunction | undefined;
|
|
76
|
-
|
|
77
|
-
@Autowired(PreferenceConfigurations)
|
|
78
|
-
protected readonly configurations: PreferenceConfigurations;
|
|
79
|
-
|
|
80
|
-
@Autowired(ILogger)
|
|
81
|
-
protected readonly logger: ILogger;
|
|
82
|
-
|
|
83
|
-
@Autowired(AppConfig)
|
|
84
|
-
protected readonly appConfig: AppConfig;
|
|
85
|
-
|
|
86
|
-
protected preferences: { [name: string]: any } = {};
|
|
87
|
-
protected combinedSchema: PreferenceDataSchema = { properties: {}, patternProperties: {} };
|
|
88
|
-
protected readonly onDidPreferenceSchemaChangedEmitter = new Emitter<void>();
|
|
89
|
-
public readonly onDidPreferenceSchemaChanged: Event<void> = this.onDidPreferenceSchemaChangedEmitter.event;
|
|
90
|
-
|
|
91
|
-
private validationFunctions = new Map<string, Ajv.ValidateFunction>();
|
|
92
|
-
|
|
93
|
-
protected fireDidPreferenceSchemaChanged(): void {
|
|
94
|
-
this.onDidPreferenceSchemaChangedEmitter.fire(undefined);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
protected get validateFunction(): Ajv.ValidateFunction {
|
|
98
|
-
if (!this._validateFunction) {
|
|
99
|
-
this.doUpdateValidate();
|
|
100
|
-
}
|
|
101
|
-
return this._validateFunction!;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
constructor() {
|
|
105
|
-
super();
|
|
106
|
-
this.init();
|
|
107
|
-
|
|
108
|
-
this.toDispose.push(
|
|
109
|
-
Disposable.create(() => {
|
|
110
|
-
this.preferences = {};
|
|
111
|
-
this.validationFunctions.clear();
|
|
112
|
-
this.combinedSchema = { properties: {}, patternProperties: {} };
|
|
113
|
-
}),
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
this.toDispose.push(this.onDidPreferenceSchemaChangedEmitter);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
protected init(): void {
|
|
120
|
-
this.preferenceContributions?.getContributions().forEach((contrib) => {
|
|
121
|
-
this.doSetSchema(contrib.schema);
|
|
122
|
-
});
|
|
123
|
-
this.combinedSchema.additionalProperties = false;
|
|
124
|
-
this.updateValidate();
|
|
125
|
-
this.onDidPreferencesChanged(() => this.updateValidate());
|
|
126
|
-
this._ready.resolve();
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
protected doUnsetSchema(changes: PreferenceProviderDataChange[]): PreferenceProviderDataChange[] {
|
|
130
|
-
const inverseChanges: PreferenceProviderDataChange[] = [];
|
|
131
|
-
for (const change of changes) {
|
|
132
|
-
const preferenceName = change.preferenceName;
|
|
133
|
-
const newValue = change.oldValue;
|
|
134
|
-
const oldValue = change.newValue;
|
|
135
|
-
const { scope, domain } = change;
|
|
136
|
-
const inverseChange: Mutable<PreferenceProviderDataChange> = { preferenceName, oldValue, scope, domain };
|
|
137
|
-
|
|
138
|
-
delete this.combinedSchema.properties[preferenceName];
|
|
139
|
-
|
|
140
|
-
if (typeof newValue === undefined) {
|
|
141
|
-
delete this.preferences[preferenceName];
|
|
142
|
-
} else {
|
|
143
|
-
inverseChange.newValue = newValue;
|
|
144
|
-
this.preferences[preferenceName] = newValue;
|
|
145
|
-
}
|
|
146
|
-
inverseChanges.push(inverseChange);
|
|
147
|
-
}
|
|
148
|
-
return inverseChanges;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
protected doSetSchema(schema: PreferenceSchema, override?: boolean): PreferenceProviderDataChange[] {
|
|
152
|
-
const scope = PreferenceScope.Default;
|
|
153
|
-
const domain = this.getDomain();
|
|
154
|
-
const changes: PreferenceProviderDataChange[] = [];
|
|
155
|
-
const defaultScope = PreferenceSchema.getDefaultScope(schema);
|
|
156
|
-
const overridable = schema.overridable || false;
|
|
157
|
-
for (const preferenceName of Object.keys(schema.properties)) {
|
|
158
|
-
if (this.combinedSchema.properties[preferenceName] && !override) {
|
|
159
|
-
this.logger.warn('Preference name collision detected in the schema for property: ' + preferenceName);
|
|
160
|
-
continue;
|
|
161
|
-
} else {
|
|
162
|
-
const schemaProps = PreferenceDataProperty.fromPreferenceSchemaProperty(
|
|
163
|
-
schema.properties[preferenceName],
|
|
164
|
-
defaultScope,
|
|
165
|
-
);
|
|
166
|
-
if (typeof schemaProps.overridable !== 'boolean' && overridable) {
|
|
167
|
-
schemaProps.overridable = true;
|
|
168
|
-
}
|
|
169
|
-
this.combinedSchema.properties[preferenceName] = schemaProps;
|
|
170
|
-
this.unsupportedPreferences.delete(preferenceName);
|
|
171
|
-
|
|
172
|
-
const value = (schemaProps.defaultValue = this.getDefaultValue(schemaProps, preferenceName));
|
|
173
|
-
changes.push(this.doSetPreferenceValue(preferenceName, value, { scope, domain }));
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return changes;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
protected doSetPreferenceValue(
|
|
180
|
-
preferenceName: string,
|
|
181
|
-
newValue: any,
|
|
182
|
-
{
|
|
183
|
-
scope,
|
|
184
|
-
domain,
|
|
185
|
-
}: {
|
|
186
|
-
scope: PreferenceScope;
|
|
187
|
-
domain?: string[];
|
|
188
|
-
},
|
|
189
|
-
): PreferenceProviderDataChange {
|
|
190
|
-
const oldValue = this.preferences[preferenceName];
|
|
191
|
-
this.preferences[preferenceName] = newValue;
|
|
192
|
-
return { preferenceName, oldValue, newValue, scope, domain };
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
protected getDefaultValue(property: PreferenceItem): any;
|
|
196
|
-
// eslint-disable-next-line @typescript-eslint/unified-signatures
|
|
197
|
-
protected getDefaultValue(property: PreferenceItem, preferenceName: string): any;
|
|
198
|
-
protected getDefaultValue(property: PreferenceItem, preferenceName?: string): any {
|
|
199
|
-
if (preferenceName && this.appConfig.defaultPreferences && preferenceName in this.appConfig.defaultPreferences) {
|
|
200
|
-
return this.appConfig.defaultPreferences[preferenceName];
|
|
201
|
-
}
|
|
202
|
-
if (property.defaultValue !== undefined) {
|
|
203
|
-
return property.defaultValue;
|
|
204
|
-
}
|
|
205
|
-
if (property.default !== undefined) {
|
|
206
|
-
return property.default;
|
|
207
|
-
}
|
|
208
|
-
const type = Array.isArray(property.type) ? property.type[0] : property.type;
|
|
209
|
-
switch (type) {
|
|
210
|
-
case 'boolean':
|
|
211
|
-
return false;
|
|
212
|
-
case 'integer':
|
|
213
|
-
case 'number':
|
|
214
|
-
return 0;
|
|
215
|
-
case 'string':
|
|
216
|
-
return '';
|
|
217
|
-
case 'array':
|
|
218
|
-
return [];
|
|
219
|
-
case 'object':
|
|
220
|
-
return {};
|
|
221
|
-
}
|
|
222
|
-
return null;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
protected updateValidate(): void {
|
|
226
|
-
this._validateFunction = undefined;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
private doUpdateValidate(): void {
|
|
230
|
-
const schema = {
|
|
231
|
-
...this.combinedSchema,
|
|
232
|
-
properties: {
|
|
233
|
-
...this.combinedSchema.properties,
|
|
234
|
-
},
|
|
235
|
-
};
|
|
236
|
-
for (const sectionName of this.configurations.getSectionNames()) {
|
|
237
|
-
delete schema.properties[sectionName];
|
|
238
|
-
}
|
|
239
|
-
this._validateFunction = new Ajv().compile(schema);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
protected readonly unsupportedPreferences = new Set<string>();
|
|
243
|
-
|
|
244
|
-
public validate(name: string, value: any): { valid: boolean; reason?: string } {
|
|
245
|
-
if (this.configurations.isSectionName(name)) {
|
|
246
|
-
return { valid: true };
|
|
247
|
-
}
|
|
248
|
-
// 对于不存在的先过
|
|
249
|
-
if (!this.getPreferenceProperty(name)) {
|
|
250
|
-
return { valid: true };
|
|
251
|
-
}
|
|
252
|
-
if (!this.validationFunctions.has(name)) {
|
|
253
|
-
this.validationFunctions.set(name, new Ajv().compile(this.getPreferenceProperty(name)!));
|
|
254
|
-
}
|
|
255
|
-
// 验证是否合并schema配置
|
|
256
|
-
const validationFn = this.validationFunctions.get(name)!;
|
|
257
|
-
const result = validationFn(value) as boolean;
|
|
258
|
-
if (!result && !(name in this.combinedSchema.properties)) {
|
|
259
|
-
// 避免每次发生变化时重复提示警告
|
|
260
|
-
if (!this.unsupportedPreferences.has(name)) {
|
|
261
|
-
this.unsupportedPreferences.add(name);
|
|
262
|
-
this.logger.warn(`"${name}" preference is not supported`);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
const errorReason =
|
|
266
|
-
validationFn.errors && validationFn.errors[0] ? normalizeAjvValidationError(validationFn.errors[0]) : undefined;
|
|
267
|
-
return { valid: result, reason: errorReason };
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
public getCombinedSchema(): PreferenceDataSchema {
|
|
271
|
-
return this.combinedSchema;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
public setSchema(schema: PreferenceSchema, override?: boolean): IDisposable {
|
|
275
|
-
const changes = this.doSetSchema(schema, override);
|
|
276
|
-
|
|
277
|
-
if (!changes.length) {
|
|
278
|
-
return Disposable.NULL;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
this.fireDidPreferenceSchemaChanged();
|
|
282
|
-
this.emitPreferencesChangedEvent(changes);
|
|
283
|
-
|
|
284
|
-
return Disposable.create(() => {
|
|
285
|
-
const inverseChanges = this.doUnsetSchema(changes);
|
|
286
|
-
if (!inverseChanges.length) {
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
this.fireDidPreferenceSchemaChanged();
|
|
290
|
-
this.emitPreferencesChangedEvent(inverseChanges);
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
public getPreferences(): { [name: string]: any } {
|
|
295
|
-
return this.preferences;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
getLanguagePreferences(resourceUri?: string) {
|
|
299
|
-
return {};
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
public async doSetPreference(): Promise<boolean> {
|
|
303
|
-
return false;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
public isValidInScope(preferenceName: string, scope: PreferenceScope): boolean {
|
|
307
|
-
const preference = this.getPreferenceProperty(preferenceName);
|
|
308
|
-
if (preference) {
|
|
309
|
-
return preference.scope! >= scope;
|
|
310
|
-
}
|
|
311
|
-
return false;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
public *getPreferenceNames(): IterableIterator<string> {
|
|
315
|
-
// eslint-disable-next-line guard-for-in
|
|
316
|
-
for (const preferenceName in this.combinedSchema.properties) {
|
|
317
|
-
yield preferenceName;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
public getPreferenceProperty(preferenceName: string): PreferenceItem | undefined {
|
|
322
|
-
return this.combinedSchema.properties[preferenceName];
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
@Injectable()
|
|
327
|
-
export class DefaultPreferenceProvider extends PreferenceProvider {
|
|
328
|
-
@Autowired(PreferenceSchemaProvider)
|
|
329
|
-
public preferenceSchemaProvider: PreferenceSchemaProvider;
|
|
330
|
-
|
|
331
|
-
private preferences: IResolvedPreferences = {
|
|
332
|
-
default: {},
|
|
333
|
-
languageSpecific: {},
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
constructor() {
|
|
337
|
-
super();
|
|
338
|
-
this.init();
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
protected async init() {
|
|
342
|
-
this._ready.resolve();
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
public getPreferences(resourceUri?: string, language?: string) {
|
|
346
|
-
if (!language) {
|
|
347
|
-
return {
|
|
348
|
-
...this.preferenceSchemaProvider.getPreferences(),
|
|
349
|
-
...this.preferences.default,
|
|
350
|
-
};
|
|
351
|
-
} else {
|
|
352
|
-
return this.preferences.languageSpecific[language] || {};
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
getLanguagePreferences(resourceUri?: string) {
|
|
357
|
-
return this.preferences.languageSpecific;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
public async doSetPreference(key: string, value: any, resourceUri?: string, language?: string) {
|
|
361
|
-
if (!language) {
|
|
362
|
-
const oldValue = this.preferences.default[key];
|
|
363
|
-
this.preferences.default[key] = value;
|
|
364
|
-
this.handlePreferenceChanges(key, value, oldValue);
|
|
365
|
-
} else {
|
|
366
|
-
if (!this.preferences.languageSpecific[language]) {
|
|
367
|
-
this.preferences.languageSpecific[language] = {};
|
|
368
|
-
}
|
|
369
|
-
const oldValue = this.preferences.languageSpecific[language][key];
|
|
370
|
-
this.preferences.languageSpecific[language][key] = value;
|
|
371
|
-
this.handlePreferenceChanges(key, value, oldValue, language);
|
|
372
|
-
}
|
|
373
|
-
return true;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
public handlePreferenceChanges(preferenceName: string, newValue: any, oldValue: any, language?: string) {
|
|
377
|
-
const prefChange: PreferenceProviderDataChange = {
|
|
378
|
-
preferenceName,
|
|
379
|
-
newValue,
|
|
380
|
-
oldValue,
|
|
381
|
-
scope: PreferenceScope.Default,
|
|
382
|
-
domain: undefined,
|
|
383
|
-
};
|
|
384
|
-
if (language) {
|
|
385
|
-
this.emitPreferencesChangedEvent({
|
|
386
|
-
default: {},
|
|
387
|
-
languageSpecific: {
|
|
388
|
-
[language]: {
|
|
389
|
-
[preferenceName]: prefChange,
|
|
390
|
-
},
|
|
391
|
-
},
|
|
392
|
-
});
|
|
393
|
-
} else {
|
|
394
|
-
this.emitPreferencesChangedEvent([prefChange]);
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
function normalizeAjvValidationError(error: Ajv.ErrorObject) {
|
|
400
|
-
return error.message;
|
|
401
|
-
}
|