@opensumi/ide-preferences 2.21.13 → 2.22.0
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/browser/abstract-resource-preference-provider.d.ts +1 -0
- package/lib/browser/abstract-resource-preference-provider.d.ts.map +1 -1
- package/lib/browser/abstract-resource-preference-provider.js +22 -3
- package/lib/browser/abstract-resource-preference-provider.js.map +1 -1
- package/lib/browser/folder-file-preference-provider.d.ts +24 -0
- package/lib/browser/folder-file-preference-provider.d.ts.map +1 -0
- package/lib/browser/{folder-preference-provider.js → folder-file-preference-provider.js} +12 -14
- package/lib/browser/folder-file-preference-provider.js.map +1 -0
- package/lib/browser/folders-preferences-provider.d.ts +8 -8
- package/lib/browser/folders-preferences-provider.d.ts.map +1 -1
- package/lib/browser/folders-preferences-provider.js +7 -7
- package/lib/browser/folders-preferences-provider.js.map +1 -1
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +8 -8
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/preference-contribution.d.ts.map +1 -1
- package/lib/browser/preference-contribution.js +3 -3
- package/lib/browser/preference-contribution.js.map +1 -1
- package/lib/browser/preference-settings.service.d.ts +22 -10
- package/lib/browser/preference-settings.service.d.ts.map +1 -1
- package/lib/browser/preference-settings.service.js +284 -101
- package/lib/browser/preference-settings.service.js.map +1 -1
- package/lib/browser/preference-widgets.js.map +1 -1
- package/lib/browser/preferenceItem.view.d.ts +4 -3
- package/lib/browser/preferenceItem.view.d.ts.map +1 -1
- package/lib/browser/preferenceItem.view.js +125 -62
- package/lib/browser/preferenceItem.view.js.map +1 -1
- package/lib/browser/preferences.module.less +100 -60
- package/lib/browser/preferences.view.d.ts +3 -17
- package/lib/browser/preferences.view.d.ts.map +1 -1
- package/lib/browser/preferences.view.js +194 -112
- package/lib/browser/preferences.view.js.map +1 -1
- package/lib/browser/user-preference-provider.js.map +1 -1
- package/lib/browser/userstorage/user-storage.contribution.js.map +1 -1
- package/lib/browser/userstorage/user-storage.service.js +7 -7
- package/lib/browser/userstorage/user-storage.service.js.map +1 -1
- package/lib/browser/workspace-file-preference-provider.d.ts +1 -1
- package/lib/browser/workspace-file-preference-provider.d.ts.map +1 -1
- package/lib/browser/workspace-file-preference-provider.js.map +1 -1
- package/lib/browser/workspace-preference-provider.js.map +1 -1
- package/lib/common/preference-id.d.ts +3 -0
- package/lib/common/preference-id.d.ts.map +1 -1
- package/lib/common/preference-id.js +4 -1
- package/lib/common/preference-id.js.map +1 -1
- package/lib/common/preference.d.ts +1 -0
- package/lib/common/preference.d.ts.map +1 -1
- package/lib/common/preference.js +26 -4
- package/lib/common/preference.js.map +1 -1
- package/lib/common/types.d.ts +18 -3
- package/lib/common/types.d.ts.map +1 -1
- package/lib/common/user-storage.d.ts +1 -1
- package/lib/common/user-storage.d.ts.map +1 -1
- package/package.json +12 -11
- package/src/browser/abstract-resource-preference-provider.ts +357 -0
- package/src/browser/folder-file-preference-provider.ts +56 -0
- package/src/browser/folders-preferences-provider.ts +262 -0
- package/src/browser/index.ts +125 -0
- package/src/browser/preference-contribution.ts +432 -0
- package/src/browser/preference-settings.service.ts +810 -0
- package/src/browser/preference-widgets.ts +368 -0
- package/src/browser/preferenceItem.view.tsx +787 -0
- package/src/browser/preferences.module.less +345 -0
- package/src/browser/preferences.view.tsx +388 -0
- package/src/browser/user-preference-provider.ts +18 -0
- package/src/browser/userstorage/index.ts +2 -0
- package/src/browser/userstorage/user-storage.contribution.ts +19 -0
- package/src/browser/userstorage/user-storage.service.ts +192 -0
- package/src/browser/workspace-file-preference-provider.ts +50 -0
- package/src/browser/workspace-preference-provider.ts +129 -0
- package/src/common/commands.ts +5 -0
- package/src/common/index.ts +4 -0
- package/src/common/preference-id.ts +11 -0
- package/src/common/preference.ts +51 -0
- package/src/common/types.ts +63 -0
- package/src/common/user-storage.ts +6 -0
- package/src/index.ts +1 -0
- package/lib/browser/folder-preference-provider.d.ts +0 -26
- package/lib/browser/folder-preference-provider.d.ts.map +0 -1
- package/lib/browser/folder-preference-provider.js.map +0 -1
- package/lib/browser/index.less +0 -36
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { Provider, Injector, Injectable } from '@opensumi/di';
|
|
2
|
+
import { BrowserModule } from '@opensumi/ide-core-browser';
|
|
3
|
+
import {
|
|
4
|
+
PreferenceScope,
|
|
5
|
+
PreferenceConfigurations,
|
|
6
|
+
PreferenceProvider,
|
|
7
|
+
IPreferenceSettingsService,
|
|
8
|
+
} from '@opensumi/ide-core-browser/lib/preferences';
|
|
9
|
+
|
|
10
|
+
import { IUserStorageService, SettingContribution } from '../common';
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
FolderFilePreferenceProviderFactory,
|
|
14
|
+
FolderFilePreferenceProviderOptions,
|
|
15
|
+
FolderFilePreferenceProvider,
|
|
16
|
+
} from './folder-file-preference-provider';
|
|
17
|
+
import { FoldersPreferencesProvider } from './folders-preferences-provider';
|
|
18
|
+
import { PreferenceContribution } from './preference-contribution';
|
|
19
|
+
import { PreferenceSettingsService } from './preference-settings.service';
|
|
20
|
+
import { UserPreferenceProvider } from './user-preference-provider';
|
|
21
|
+
import { UserStorageContribution, UserStorageServiceImpl } from './userstorage';
|
|
22
|
+
import {
|
|
23
|
+
WorkspaceFilePreferenceProviderFactory,
|
|
24
|
+
WorkspaceFilePreferenceProviderOptions,
|
|
25
|
+
WorkspaceFilePreferenceProvider,
|
|
26
|
+
} from './workspace-file-preference-provider';
|
|
27
|
+
import { WorkspacePreferenceProvider } from './workspace-preference-provider';
|
|
28
|
+
|
|
29
|
+
@Injectable()
|
|
30
|
+
export class PreferencesModule extends BrowserModule {
|
|
31
|
+
contributionProvider = SettingContribution;
|
|
32
|
+
providers: Provider[] = [
|
|
33
|
+
...createPreferenceProviders(),
|
|
34
|
+
{
|
|
35
|
+
token: IUserStorageService,
|
|
36
|
+
useClass: UserStorageServiceImpl,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
token: IPreferenceSettingsService,
|
|
40
|
+
useClass: PreferenceSettingsService,
|
|
41
|
+
},
|
|
42
|
+
PreferenceContribution,
|
|
43
|
+
UserStorageContribution,
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
preferences = injectPreferenceProviders;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function injectFolderPreferenceProvider(inject: Injector): void {
|
|
50
|
+
inject.addProviders({
|
|
51
|
+
token: FolderFilePreferenceProviderFactory,
|
|
52
|
+
useFactory: () => (options: FolderFilePreferenceProviderOptions) => {
|
|
53
|
+
const configurations = inject.get(PreferenceConfigurations);
|
|
54
|
+
const sectionName = configurations.getName(options.configUri);
|
|
55
|
+
const child = inject.createChild(
|
|
56
|
+
[
|
|
57
|
+
{
|
|
58
|
+
token: FolderFilePreferenceProviderOptions,
|
|
59
|
+
useValue: options,
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
{
|
|
63
|
+
dropdownForTag: true,
|
|
64
|
+
tag: sectionName,
|
|
65
|
+
},
|
|
66
|
+
);
|
|
67
|
+
// 当传入为配置文件时,如settings.json, 获取Setting
|
|
68
|
+
if (configurations.isConfigUri(options.configUri)) {
|
|
69
|
+
child.addProviders({
|
|
70
|
+
token: FolderFilePreferenceProvider,
|
|
71
|
+
useClass: FolderFilePreferenceProvider,
|
|
72
|
+
});
|
|
73
|
+
return child.get(FolderFilePreferenceProvider);
|
|
74
|
+
}
|
|
75
|
+
// 当传入为其他文件时,如launch.json
|
|
76
|
+
// 需设置对应的FolderPreferenceProvider 及其对应的 FolderFilePreferenceProviderOptions 依赖
|
|
77
|
+
// 这里的FolderPreferenceProvider获取必须为多例,因为工作区模式下可能存在多个配置文件
|
|
78
|
+
return child.get(FolderFilePreferenceProvider, { tag: sectionName, multiple: true });
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function injectWorkspaceFilePreferenceProvider(inject: Injector): void {
|
|
84
|
+
inject.addProviders({
|
|
85
|
+
token: WorkspaceFilePreferenceProviderFactory,
|
|
86
|
+
useFactory: () => (options: WorkspaceFilePreferenceProviderOptions) => {
|
|
87
|
+
const child = inject.createChild([
|
|
88
|
+
{
|
|
89
|
+
token: WorkspaceFilePreferenceProviderOptions,
|
|
90
|
+
useValue: options,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
token: WorkspaceFilePreferenceProvider,
|
|
94
|
+
useClass: WorkspaceFilePreferenceProvider,
|
|
95
|
+
},
|
|
96
|
+
]);
|
|
97
|
+
return child.get(WorkspaceFilePreferenceProvider);
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function injectPreferenceProviders(inject: Injector): void {
|
|
103
|
+
injectFolderPreferenceProvider(inject);
|
|
104
|
+
injectWorkspaceFilePreferenceProvider(inject);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function createPreferenceProviders(): Provider[] {
|
|
108
|
+
return [
|
|
109
|
+
{
|
|
110
|
+
token: PreferenceProvider,
|
|
111
|
+
tag: PreferenceScope.Folder,
|
|
112
|
+
useClass: FoldersPreferencesProvider,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
token: PreferenceProvider,
|
|
116
|
+
tag: PreferenceScope.Workspace,
|
|
117
|
+
useClass: WorkspacePreferenceProvider,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
token: PreferenceProvider,
|
|
121
|
+
tag: PreferenceScope.User,
|
|
122
|
+
useClass: UserPreferenceProvider,
|
|
123
|
+
},
|
|
124
|
+
];
|
|
125
|
+
}
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
import * as jsoncParser from 'jsonc-parser';
|
|
2
|
+
|
|
3
|
+
import { Autowired, Injectable, INJECTOR_TOKEN, Injector } from '@opensumi/di';
|
|
4
|
+
import {
|
|
5
|
+
ClientAppContribution,
|
|
6
|
+
PreferenceSchemaProvider,
|
|
7
|
+
URI,
|
|
8
|
+
Domain,
|
|
9
|
+
CommandContribution,
|
|
10
|
+
CommandRegistry,
|
|
11
|
+
COMMON_COMMANDS,
|
|
12
|
+
KeybindingContribution,
|
|
13
|
+
KeybindingRegistry,
|
|
14
|
+
PreferenceScope,
|
|
15
|
+
PreferenceProvider,
|
|
16
|
+
WithEventBus,
|
|
17
|
+
MaybePromise,
|
|
18
|
+
localize,
|
|
19
|
+
CommandService,
|
|
20
|
+
EDITOR_COMMANDS,
|
|
21
|
+
JsonSchemaContribution,
|
|
22
|
+
IJSONSchemaRegistry,
|
|
23
|
+
IPreferenceSettingsService,
|
|
24
|
+
ContributionProvider,
|
|
25
|
+
ISettingGroup,
|
|
26
|
+
IDisposable,
|
|
27
|
+
arrays,
|
|
28
|
+
Command,
|
|
29
|
+
getIcon,
|
|
30
|
+
isString,
|
|
31
|
+
ISettingSection,
|
|
32
|
+
CodeSchemaId,
|
|
33
|
+
} from '@opensumi/ide-core-browser';
|
|
34
|
+
import { MenuContribution, IMenuRegistry, MenuId } from '@opensumi/ide-core-browser/lib/menu/next';
|
|
35
|
+
import { ResourceService, IResourceProvider, IResource } from '@opensumi/ide-editor';
|
|
36
|
+
import {
|
|
37
|
+
BrowserEditorContribution,
|
|
38
|
+
EditorComponentRegistry,
|
|
39
|
+
EditorOpenType,
|
|
40
|
+
IEditor,
|
|
41
|
+
IEditorFeatureRegistry,
|
|
42
|
+
IResourceOpenResult,
|
|
43
|
+
WorkbenchEditorService,
|
|
44
|
+
} from '@opensumi/ide-editor/lib/browser';
|
|
45
|
+
import { IFileServiceClient } from '@opensumi/ide-file-service/lib/common';
|
|
46
|
+
|
|
47
|
+
import { PREF_SCHEME, SettingContribution } from '../common';
|
|
48
|
+
|
|
49
|
+
import { PreferenceSettingsService, defaultSettingGroup, defaultSettingSections } from './preference-settings.service';
|
|
50
|
+
import { EditPreferenceDecorationsContribution } from './preference-widgets';
|
|
51
|
+
import { PreferenceView } from './preferences.view';
|
|
52
|
+
import { USER_PREFERENCE_URI } from './user-preference-provider';
|
|
53
|
+
import { WorkspacePreferenceProvider } from './workspace-preference-provider';
|
|
54
|
+
|
|
55
|
+
const PREF_PREVIEW_COMPONENT_ID = 'pref-preview';
|
|
56
|
+
const { addElement } = arrays;
|
|
57
|
+
|
|
58
|
+
@Injectable()
|
|
59
|
+
export class PrefResourceProvider extends WithEventBus implements IResourceProvider {
|
|
60
|
+
readonly scheme: string = PREF_SCHEME;
|
|
61
|
+
|
|
62
|
+
constructor() {
|
|
63
|
+
super();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
provideResource(uri: URI): MaybePromise<IResource<any>> {
|
|
67
|
+
// 获取文件类型 getFileType: (path: string) => string
|
|
68
|
+
return {
|
|
69
|
+
supportsRevive: true,
|
|
70
|
+
name: localize('preference.tab.name'),
|
|
71
|
+
icon: getIcon('setting'),
|
|
72
|
+
uri,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
provideResourceSubname(resource: IResource, groupResources: IResource[]): string | null {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async shouldCloseResource(resource: IResource, openedResources: IResource[][]): Promise<boolean> {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export namespace PreferenceContextMenu {
|
|
86
|
+
// 1_, 2_用于菜单排序,这样能保证分组顺序顺序
|
|
87
|
+
export const OPEN = '1_open';
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export namespace PREFERENCE_COMMANDS {
|
|
91
|
+
const CATEGORY = 'preference';
|
|
92
|
+
|
|
93
|
+
export const OPEN_USER_SETTING_FILE: Command = {
|
|
94
|
+
id: 'preference.open.user',
|
|
95
|
+
label: localize('preference.editorTitle.openUserSource'),
|
|
96
|
+
category: CATEGORY,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const OPEN_WORKSPACE_SETTING_FILE: Command = {
|
|
100
|
+
id: 'preference.open.workspace',
|
|
101
|
+
label: localize('preference.editorTitle.openWorkspaceSource'),
|
|
102
|
+
category: CATEGORY,
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const OPEN_SOURCE_FILE: Command = {
|
|
106
|
+
id: 'preference.open.source',
|
|
107
|
+
label: localize('preference.editorTitle.openSource'),
|
|
108
|
+
category: CATEGORY,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export const PREFERENCE_INPUT_FOCUS: Command = {
|
|
112
|
+
id: 'preference.input.focus',
|
|
113
|
+
category: CATEGORY,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@Domain(
|
|
118
|
+
CommandContribution,
|
|
119
|
+
KeybindingContribution,
|
|
120
|
+
ClientAppContribution,
|
|
121
|
+
BrowserEditorContribution,
|
|
122
|
+
MenuContribution,
|
|
123
|
+
JsonSchemaContribution,
|
|
124
|
+
)
|
|
125
|
+
export class PreferenceContribution
|
|
126
|
+
implements
|
|
127
|
+
CommandContribution,
|
|
128
|
+
KeybindingContribution,
|
|
129
|
+
ClientAppContribution,
|
|
130
|
+
BrowserEditorContribution,
|
|
131
|
+
MenuContribution,
|
|
132
|
+
JsonSchemaContribution
|
|
133
|
+
{
|
|
134
|
+
@Autowired(INJECTOR_TOKEN)
|
|
135
|
+
private readonly injector: Injector;
|
|
136
|
+
|
|
137
|
+
@Autowired(PreferenceSchemaProvider)
|
|
138
|
+
private readonly schemaProvider: PreferenceSchemaProvider;
|
|
139
|
+
|
|
140
|
+
@Autowired(PreferenceProvider, { tag: PreferenceScope.Workspace })
|
|
141
|
+
protected readonly workspacePreferenceProvider: WorkspacePreferenceProvider;
|
|
142
|
+
|
|
143
|
+
@Autowired(IFileServiceClient)
|
|
144
|
+
protected readonly filesystem: IFileServiceClient;
|
|
145
|
+
|
|
146
|
+
@Autowired(PrefResourceProvider)
|
|
147
|
+
private readonly prefResourceProvider: PrefResourceProvider;
|
|
148
|
+
|
|
149
|
+
@Autowired(CommandService)
|
|
150
|
+
private readonly commandService: CommandService;
|
|
151
|
+
|
|
152
|
+
@Autowired(IJSONSchemaRegistry)
|
|
153
|
+
private readonly schemaRegistry: IJSONSchemaRegistry;
|
|
154
|
+
|
|
155
|
+
@Autowired(IPreferenceSettingsService)
|
|
156
|
+
private readonly preferenceService: PreferenceSettingsService;
|
|
157
|
+
|
|
158
|
+
@Autowired(SettingContribution)
|
|
159
|
+
private readonly contributions: ContributionProvider<SettingContribution>;
|
|
160
|
+
|
|
161
|
+
@Autowired(WorkbenchEditorService)
|
|
162
|
+
private readonly workbenchEditorService: WorkbenchEditorService;
|
|
163
|
+
|
|
164
|
+
private settingGroupsWillRegister: ISettingGroup[] = defaultSettingGroup;
|
|
165
|
+
|
|
166
|
+
private settingSectionsWillRegister: {
|
|
167
|
+
[key: string]: ISettingSection[];
|
|
168
|
+
} = defaultSettingSections;
|
|
169
|
+
|
|
170
|
+
onStart() {
|
|
171
|
+
/**
|
|
172
|
+
* 处理各个模块下贡献的 PreferenceSettingSectionContribution, 组成默认的设置面板内容
|
|
173
|
+
*/
|
|
174
|
+
/**
|
|
175
|
+
* 收集 contribution 里对 settingGroupsWillRegister, settingSectionsWillRegister 增删
|
|
176
|
+
*/
|
|
177
|
+
this.saveSettings();
|
|
178
|
+
this.handleSettingGroups();
|
|
179
|
+
this.handleSettingSections();
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 将收集到的 group 和 section 真正注册到 service
|
|
183
|
+
*/
|
|
184
|
+
this.registerSettings();
|
|
185
|
+
this.registerSettingSections();
|
|
186
|
+
|
|
187
|
+
this.preferenceService.fireDidSettingsChange();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
registerCommands(commands: CommandRegistry) {
|
|
191
|
+
commands.registerCommand(COMMON_COMMANDS.OPEN_PREFERENCES, {
|
|
192
|
+
execute: async (search?: string) => {
|
|
193
|
+
await this.openPreferences(search);
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
commands.registerCommand(COMMON_COMMANDS.LOCATE_PREFERENCES, {
|
|
198
|
+
execute: async (groupId: string) => {
|
|
199
|
+
await this.openPreferences();
|
|
200
|
+
return await this.preferenceService.scrollToGroup(groupId);
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
commands.registerCommand(PREFERENCE_COMMANDS.OPEN_USER_SETTING_FILE, {
|
|
205
|
+
execute: () => {
|
|
206
|
+
this.openResource(PreferenceScope.User);
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
commands.registerCommand(PREFERENCE_COMMANDS.OPEN_WORKSPACE_SETTING_FILE, {
|
|
211
|
+
execute: () => {
|
|
212
|
+
this.openResource(PreferenceScope.Workspace);
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
commands.registerCommand(PREFERENCE_COMMANDS.OPEN_SOURCE_FILE, {
|
|
217
|
+
execute: async (scopeOrUrl?: PreferenceScope | URI, preferenceId?: string) => {
|
|
218
|
+
// 这里可能被 Editor 的 Toolbar 调用
|
|
219
|
+
// 传入 URI 及 EditorGroup
|
|
220
|
+
if (!scopeOrUrl || typeof scopeOrUrl !== 'number') {
|
|
221
|
+
this.openResource();
|
|
222
|
+
} else {
|
|
223
|
+
this.openResource(scopeOrUrl as PreferenceScope, preferenceId);
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
commands.registerCommand(PREFERENCE_COMMANDS.PREFERENCE_INPUT_FOCUS, {
|
|
229
|
+
execute: () => {
|
|
230
|
+
this.preferenceService.focusInput();
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
registerMenus(menus: IMenuRegistry) {
|
|
236
|
+
menus.registerMenuItem(MenuId.SettingsIconMenu, {
|
|
237
|
+
command: COMMON_COMMANDS.OPEN_PREFERENCES.id,
|
|
238
|
+
group: PreferenceContextMenu.OPEN,
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
menus.registerMenuItem(MenuId.EditorTitle, {
|
|
242
|
+
command: PREFERENCE_COMMANDS.OPEN_SOURCE_FILE.id,
|
|
243
|
+
iconClass: getIcon('open'),
|
|
244
|
+
group: 'navigation',
|
|
245
|
+
order: 4,
|
|
246
|
+
when: `resourceScheme == ${PREF_SCHEME}`,
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
menus.registerMenuItem(MenuId.EditorTitle, {
|
|
250
|
+
command: COMMON_COMMANDS.OPEN_PREFERENCES.id,
|
|
251
|
+
iconClass: getIcon('open'),
|
|
252
|
+
group: 'navigation',
|
|
253
|
+
order: 4,
|
|
254
|
+
when: 'resourceFilename =~ /settings.json/',
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
registerKeybindings(keybindings: KeybindingRegistry): void {
|
|
259
|
+
keybindings.registerKeybinding({
|
|
260
|
+
command: COMMON_COMMANDS.OPEN_PREFERENCES.id,
|
|
261
|
+
keybinding: 'ctrlcmd+,',
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
keybindings.registerKeybinding({
|
|
265
|
+
command: PREFERENCE_COMMANDS.PREFERENCE_INPUT_FOCUS.id,
|
|
266
|
+
keybinding: 'ctrlcmd+f',
|
|
267
|
+
when: 'resourceScheme == pref',
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
handleSettingGroups() {
|
|
272
|
+
for (const contrib of this.contributions.getContributions()) {
|
|
273
|
+
if (contrib.handleSettingGroup) {
|
|
274
|
+
this.settingGroupsWillRegister = contrib.handleSettingGroup(this.settingGroupsWillRegister);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
handleSettingSections() {
|
|
280
|
+
for (const contrib of this.contributions.getContributions()) {
|
|
281
|
+
if (contrib.handleSettingSections) {
|
|
282
|
+
this.settingSectionsWillRegister = contrib.handleSettingSections({ ...this.settingSectionsWillRegister });
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
saveSettings() {
|
|
288
|
+
for (const contrib of this.contributions.getContributions()) {
|
|
289
|
+
contrib.registerSetting &&
|
|
290
|
+
contrib.registerSetting({
|
|
291
|
+
registerSettingGroup: (settingGroup: ISettingGroup): IDisposable =>
|
|
292
|
+
addElement(this.settingGroupsWillRegister, settingGroup),
|
|
293
|
+
registerSettingSection: (key, section): IDisposable => {
|
|
294
|
+
const has = (key: string) => Object.keys(this.settingSectionsWillRegister).includes(key);
|
|
295
|
+
if (!has(key)) {
|
|
296
|
+
this.settingSectionsWillRegister[key] = [];
|
|
297
|
+
}
|
|
298
|
+
return addElement(this.settingSectionsWillRegister[key], section);
|
|
299
|
+
},
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
registerSettings() {
|
|
305
|
+
this.settingGroupsWillRegister.forEach((g) => {
|
|
306
|
+
this.preferenceService.registerSettingGroup(g);
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
registerSettingSections() {
|
|
311
|
+
Object.keys(this.settingSectionsWillRegister).forEach((key) => {
|
|
312
|
+
this.settingSectionsWillRegister[key].forEach((section) => {
|
|
313
|
+
this.preferenceService.registerSettingSection(key, section);
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
async openPreferences(search?: string, prefernceId?: string) {
|
|
319
|
+
await this.commandService.executeCommand(EDITOR_COMMANDS.OPEN_RESOURCE.id, new URI('/').withScheme(PREF_SCHEME), {
|
|
320
|
+
preview: false,
|
|
321
|
+
});
|
|
322
|
+
if (isString(search)) {
|
|
323
|
+
this.preferenceService.search(search);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
async openResource(scope?: PreferenceScope, preferenceId?: string) {
|
|
328
|
+
const url = await this.preferenceService.getCurrentPreferenceUrl(scope);
|
|
329
|
+
const openResult = await this.commandService.executeCommand<IResourceOpenResult>(
|
|
330
|
+
EDITOR_COMMANDS.OPEN_RESOURCE.id,
|
|
331
|
+
new URI(url),
|
|
332
|
+
{
|
|
333
|
+
focus: true,
|
|
334
|
+
groupIndex: this.workbenchEditorService.currentEditorGroup.index,
|
|
335
|
+
},
|
|
336
|
+
);
|
|
337
|
+
if (openResult && preferenceId) {
|
|
338
|
+
const editor = this.workbenchEditorService.editorGroups.find((g) => g.name === openResult.groupId)?.currentEditor;
|
|
339
|
+
if (editor) {
|
|
340
|
+
const { _commandService: commandService } = editor.monacoEditor as any;
|
|
341
|
+
let text = editor.monacoEditor.getValue();
|
|
342
|
+
let lines;
|
|
343
|
+
let numReturns;
|
|
344
|
+
let preferenceLine: string | undefined;
|
|
345
|
+
let preferenceLineNumber: number | undefined;
|
|
346
|
+
const { index } = text.match(new RegExp(`\\"${preferenceId}\\"`)) || {};
|
|
347
|
+
if (index && index >= 0) {
|
|
348
|
+
numReturns = text.slice(0, index).match(new RegExp('\\n', 'g'))?.length || -1 + 1;
|
|
349
|
+
if (numReturns > 0) {
|
|
350
|
+
lines = text.split('\n');
|
|
351
|
+
preferenceLine = lines[numReturns];
|
|
352
|
+
preferenceLineNumber = numReturns;
|
|
353
|
+
}
|
|
354
|
+
} else {
|
|
355
|
+
// 如果不存在配置项,追加配置项内容
|
|
356
|
+
const formattingOptions = { tabSize: 2, insertSpaces: true, eol: '' };
|
|
357
|
+
const edits = jsoncParser.modify(text, [preferenceId], '', { formattingOptions });
|
|
358
|
+
const content = jsoncParser.applyEdits(text, edits);
|
|
359
|
+
editor.monacoEditor.setValue(content);
|
|
360
|
+
text = content;
|
|
361
|
+
numReturns = text.slice(0, index).match(new RegExp('\\n', 'g'))?.length || -1;
|
|
362
|
+
if (numReturns > 1) {
|
|
363
|
+
lines = text.split('\n');
|
|
364
|
+
preferenceLine = lines[numReturns - 1];
|
|
365
|
+
preferenceLineNumber = numReturns - 1;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (!(preferenceLine && preferenceLineNumber)) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const regStr = `\\s+\\"${preferenceId}\\":\\s?["|{|t|f|[]`;
|
|
374
|
+
const match = new RegExp(regStr, 'g').exec(preferenceLine);
|
|
375
|
+
if (match) {
|
|
376
|
+
const isStringExpr = match[0].slice(-1) === '"';
|
|
377
|
+
editor.monacoEditor.setPosition({ lineNumber: preferenceLineNumber + 1, column: match[0].length + 1 });
|
|
378
|
+
setTimeout(() => {
|
|
379
|
+
editor.monacoEditor.revealPositionInCenter(
|
|
380
|
+
{ lineNumber: preferenceLineNumber! + 1, column: match[0].length + 1 },
|
|
381
|
+
1,
|
|
382
|
+
);
|
|
383
|
+
});
|
|
384
|
+
if (isStringExpr) {
|
|
385
|
+
// 只对 String 类型配置展示提示,包括不存在配置项时追加的情况
|
|
386
|
+
await commandService.executeCommand('editor.action.triggerSuggest');
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
initialize() {
|
|
394
|
+
this.schemaProvider.onDidPreferenceSchemaChanged(() => {
|
|
395
|
+
this.registerSchema(this.schemaRegistry);
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
registerSchema(registry: IJSONSchemaRegistry) {
|
|
400
|
+
registry.registerSchema(CodeSchemaId.userSettings, this.schemaProvider.getCombinedSchema(), [
|
|
401
|
+
'settings.json',
|
|
402
|
+
USER_PREFERENCE_URI.toString(),
|
|
403
|
+
]);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
registerResource(resourceService: ResourceService) {
|
|
407
|
+
resourceService.registerResourceProvider(this.prefResourceProvider);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
registerEditorComponent(editorComponentRegistry: EditorComponentRegistry) {
|
|
411
|
+
editorComponentRegistry.registerEditorComponent({
|
|
412
|
+
component: PreferenceView,
|
|
413
|
+
uid: PREF_PREVIEW_COMPONENT_ID,
|
|
414
|
+
scheme: PREF_SCHEME,
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
editorComponentRegistry.registerEditorComponentResolver(PREF_SCHEME, (_, __, resolve) => {
|
|
418
|
+
resolve([
|
|
419
|
+
{
|
|
420
|
+
type: EditorOpenType.component,
|
|
421
|
+
componentId: PREF_PREVIEW_COMPONENT_ID,
|
|
422
|
+
},
|
|
423
|
+
]);
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
registerEditorFeature(registry: IEditorFeatureRegistry) {
|
|
428
|
+
registry.registerEditorFeatureContribution({
|
|
429
|
+
contribute: (editor: IEditor) => this.injector.get(EditPreferenceDecorationsContribution, [editor]).contribute(),
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
}
|