Skip to content

Commit b5e0d2c

Browse files
author
winjo
committed
feat: 内置更改默认偏好设置的命令
1 parent 8e14730 commit b5e0d2c

4 files changed

Lines changed: 53 additions & 1 deletion

File tree

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { Injectable, Provider } from '@ali/common-di';
22
import { BrowserModule } from '@ali/ide-core-browser';
33
import { ExtensionActivateContribution } from './extension/extension.contribution';
4+
import { AlexCommandContribution } from './commands';
45

56
@Injectable()
67
export class AlexModule extends BrowserModule {
7-
providers: Provider[] = [ExtensionActivateContribution];
8+
providers: Provider[] = [ExtensionActivateContribution, AlexCommandContribution];
89
}

packages/alex/src/core/commands.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Autowired } from '@ali/common-di';
2+
import {
3+
Domain,
4+
CommandContribution,
5+
CommandRegistry,
6+
Command,
7+
PreferenceScope,
8+
PreferenceProvider,
9+
} from '@ali/ide-core-browser';
10+
11+
/**
12+
* 内置一些 commands 来调用内部的 service
13+
*/
14+
15+
namespace ALEX_COMMANDS {
16+
const CATEGORY = 'alex';
17+
18+
// 提供更改和获取默认偏好设置的能力,这个无法通过 extension 实现
19+
export const ALEX_GET_DEFAULT_PREFERENCE: Command = {
20+
id: 'alex.getDefaultPreference',
21+
category: CATEGORY,
22+
};
23+
24+
export const ALEX_SET_DEFAULT_PREFERENCE: Command = {
25+
id: 'alex.setDefaultPreference',
26+
category: CATEGORY,
27+
};
28+
}
29+
30+
@Domain(CommandContribution)
31+
export class AlexCommandContribution implements CommandContribution {
32+
@Autowired(PreferenceProvider, { tag: PreferenceScope.Default })
33+
private readonly defaultPreference: PreferenceProvider;
34+
35+
registerCommands(registry: CommandRegistry) {
36+
registry.registerCommand(ALEX_COMMANDS.ALEX_GET_DEFAULT_PREFERENCE, {
37+
execute: (preferenceName: string, resourceUri?: string, language?: string) => {
38+
return this.defaultPreference.get(preferenceName, resourceUri, language);
39+
},
40+
});
41+
42+
registry.registerCommand(ALEX_COMMANDS.ALEX_SET_DEFAULT_PREFERENCE, {
43+
execute: (preferenceName: string, value: any, resourceUri?: string, language?: string) => {
44+
return this.defaultPreference.setPreference(preferenceName, value, resourceUri, language);
45+
},
46+
});
47+
}
48+
}

packages/alex/src/core/editor/editor.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import { IDETheme, GeekTheme } from '../extension/metadata';
5252
import { isCodeDocumentModel, CodeDocumentModel, EditorProps } from './types';
5353
import styles from '../style.module.less';
5454
import { IPropsService } from '../props.service';
55+
import { AlexCommandContribution } from '../commands';
5556

5657
@Injectable()
5758
class BreadCrumbServiceImplOverride extends BreadCrumbServiceImpl {
@@ -669,5 +670,6 @@ export class EditorSpecialModule extends BrowserModule {
669670
},
670671
ThemeContribution,
671672
EditorSpecialContribution,
673+
AlexCommandContribution,
672674
];
673675
}

packages/toolkit/webpack/config.build.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ module.exports = createWebpackConfig({
5252
],
5353
optimization: {
5454
minimize: false,
55+
concatenateModules: false,
5556
},
5657
},
5758
});

0 commit comments

Comments
 (0)