Skip to content

Commit 252c096

Browse files
author
彦熹
committed
PullRequest: 36 feat: 增加 plugin 模块
1 parent b6df6db commit 252c096

32 files changed

Lines changed: 627 additions & 19 deletions

packages/alex/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"@alipay/alex-code-service": "0.13.0",
7272
"@alipay/alex-i18n": "0.13.0",
7373
"@alipay/alex-lsif-service": "0.13.0",
74+
"@alipay/alex-plugin": "0.13.0",
7475
"antd": "^3.20.3",
7576
"@ant-design/icons": "~2.1.1"
7677
},

packages/alex/src/api/createEditor.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ import { IEditorDocumentModelService } from '@ali/ide-editor/lib/browser';
2222
import { EditorDocumentModelServiceImpl } from '@ali/ide-editor/lib/browser/doc-model/editor-document-model-service';
2323
import { EditorDocumentModel } from '@ali/ide-editor/lib/browser/doc-model/editor-document-model';
2424
import * as os from 'os';
25+
import { IPluginConfig } from '@alipay/alex-plugin';
2526

26-
import { modules } from '../core/editor/modules';
27+
import { getModules } from '../core/editor/modules';
2728
import { mergeConfig, themeStorage } from '../core/utils';
2829
import { EditorLayoutComponent, getEditorLayoutConfig } from '../core/layout';
2930
import { IConfig, IAppInstance } from './types';
@@ -32,9 +33,11 @@ import { logPv } from '../core/tracert';
3233
export { SlotLocation, SlotRenderer, BoxPanel, SplitPanel };
3334

3435
const getDefaultAppConfig = (): IAppOpts => ({
35-
modules,
36+
modules: getModules(),
3637
useCdnIcon: true,
3738
noExtHost: true,
39+
extWorkerHost: __WORKER_HOST__,
40+
webviewEndpoint: __WEBVIEW_ENDPOINT__,
3841
defaultPreferences: {
3942
'general.theme': 'ide-light',
4043
'application.confirmExit': 'never',
@@ -141,6 +144,11 @@ export function createEditor({ appConfig, runtimeConfig }: IConfig): IAppInstanc
141144
useValue: runtimeConfig,
142145
});
143146

147+
app.injector.addProviders({
148+
token: IPluginConfig,
149+
useValue: customConfig.plugins,
150+
});
151+
144152
if (runtimeConfig.reporter) {
145153
app.injector.addProviders({
146154
token: IReporter,

packages/alex/src/api/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1+
/// <reference path="../../typings/thenable.d.ts" />
2+
13
import { IAppOpts, RuntimeConfig, ClientApp } from '@alipay/alex-core';
24
import { IAppRenderer } from '@ali/ide-core-browser';
5+
import { IPluginConfig } from '@alipay/alex-plugin';
6+
7+
export type { IPluginAPI, IPluginModule } from '@alipay/alex-plugin';
38

49
export type IAppConfig = Partial<IAppOpts> & {
510
/**
611
* 工作空间目录,最好确保不同项目名称不同,如 group/repository 的形式,工作空间目录会挂载到 /workspace 根目录下
712
*/
813
workspaceDir: string;
14+
} & {
15+
plugins?: IPluginConfig;
916
};
1017

1118
export interface IConfig {

packages/alex/src/core/Landing.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const Landing: FC<LandingProps> = ({ status, error }) => {
1919
>
2020
<path d="M988 548c-19.9 0-36-16.1-36-36 0-59.4-11.6-117-34.6-171.3a440.45 440.45 0 00-94.3-139.9 437.71 437.71 0 00-139.9-94.3C629 83.6 571.4 72 512 72c-19.9 0-36-16.1-36-36s16.1-36 36-36c69.1 0 136.2 13.5 199.3 40.3C772.3 66 827 103 874 150c47 47 83.9 101.8 109.7 162.7 26.7 63.1 40.2 130.2 40.2 199.3.1 19.9-16 36-35.9 36z"></path>
2121
</svg>
22-
正在加载工作空间...
22+
正在加载...
2323
</span>
2424
)}
2525
</div>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Autowired, Injectable, Provider } from '@ali/common-di';
2+
import { BrowserModule } from '@ali/ide-core-browser';
3+
import { ExtensionServiceImpl } from '@ali/ide-kaitian-extension/lib/browser/extension.service';
4+
import { IPluginService } from '@alipay/alex-plugin';
5+
import { ExtensionService } from '@ali/ide-kaitian-extension/lib/common';
6+
7+
@Injectable()
8+
class ExtensionServiceImplOverride extends ExtensionServiceImpl {
9+
@Autowired(IPluginService)
10+
pluginService: IPluginService;
11+
12+
activate(): Promise<void> {
13+
this.lazyActivate();
14+
return Promise.resolve();
15+
}
16+
17+
/**
18+
* 不阻塞启动
19+
* TODO: 目前使用私有属性,待升级后改造
20+
*/
21+
async lazyActivate(this: any) {
22+
await this.initBaseData();
23+
this.extensionMetaDataArr = await this.getAllExtensions();
24+
await this.initExtension();
25+
await this.enableAvailableExtensions();
26+
await this.pluginService.whenReady.promise;
27+
this.doActivate();
28+
}
29+
}
30+
31+
@Injectable()
32+
export class ExtensionActivateModule extends BrowserModule {
33+
providers: Provider[] = [
34+
{
35+
token: ExtensionService,
36+
useClass: ExtensionServiceImplOverride,
37+
override: true,
38+
},
39+
];
40+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* kaitian
3+
*/
4+
import { CommentsModule } from '@ali/ide-comments/lib/browser';
5+
import { ExtensionStorageModule } from '@ali/ide-extension-storage/lib/browser';
6+
import { KaitianExtensionModule } from '@ali/ide-kaitian-extension/lib/browser';
7+
import { StaticResourceModule } from '@ali/ide-static-resource/lib/browser';
8+
import { WebviewModule } from '@ali/ide-webview/lib/browser';
9+
10+
/**
11+
* editor special
12+
*/
13+
import { WorkerPatchModule } from '../worker/worker.module';
14+
import { ExtensionActivateModule } from './editor.extension';
15+
16+
import { setExtensionModules } from './modules';
17+
18+
setExtensionModules([
19+
StaticResourceModule,
20+
ExtensionStorageModule,
21+
WebviewModule,
22+
KaitianExtensionModule,
23+
CommentsModule,
24+
WorkerPatchModule,
25+
ExtensionActivateModule,
26+
]);

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,19 @@ import { WorkspaceModule } from '@ali/ide-workspace/lib/browser';
2525
*/
2626
import { ClientModule, ServerModuleCollection } from '@alipay/alex-core';
2727
import { LsifModule } from '@alipay/alex-lsif-service';
28+
import { PluginModule } from '@alipay/alex-plugin';
2829

2930
/**
3031
* editor special
3132
*/
3233
import { EditorSpecialModule } from './editor.module';
3334

34-
export const modules: ModuleConstructor[] = [
35+
let extensionModules: ModuleConstructor[] = [];
36+
export const setExtensionModules = (modules: ModuleConstructor[]) => {
37+
extensionModules = modules;
38+
};
39+
40+
export const getModules: () => ModuleConstructor[] = () => [
3541
MainLayoutModule,
3642
OverlayModule,
3743
LogModule,
@@ -53,9 +59,12 @@ export const modules: ModuleConstructor[] = [
5359

5460
MonacoEnhanceModule,
5561

62+
...extensionModules,
63+
5664
// Alex
5765
ClientModule,
5866
LsifModule,
67+
PluginModule,
5968
...ServerModuleCollection,
6069

6170
// Editor Special

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Thenable } from '../types';
2-
31
export interface DocumentModel {
42
/**
53
* 打开的文件路径

packages/alex/src/core/types.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,3 @@ export interface LandingProps {
1111
export interface RootProps extends LandingProps {
1212
Landing?: ComponentType<LandingProps>;
1313
}
14-
15-
export interface Thenable<T> {
16-
then<TResult>(
17-
onfulfilled?: (value: T) => TResult | Thenable<TResult>,
18-
onrejected?: (reason: any) => TResult | Thenable<TResult>
19-
): Thenable<TResult>;
20-
then<TResult>(
21-
onfulfilled?: (value: T) => TResult | Thenable<TResult>,
22-
onrejected?: (reason: any) => void
23-
): Thenable<TResult>;
24-
}

packages/alex/src/editor.all.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* 包含 extension 的 editor
3+
*/
4+
5+
import './editor.extension';
6+
7+
export * from './editor';

0 commit comments

Comments
 (0)