Skip to content

Commit

Permalink
fix: adjust the timing of loading language extensions and improve bui…
Browse files Browse the repository at this point in the history
…lt-in modules (#478)

* fix: adjust the timing of loading language extensions and improve built-in modules

* test: update the built-in modules in tests
  • Loading branch information
mortalYoung authored Oct 22, 2021
1 parent addaf23 commit f0bfabb
Show file tree
Hide file tree
Showing 15 changed files with 754 additions and 632 deletions.
2 changes: 1 addition & 1 deletion src/controller/__tests__/editorTree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('The editor tree controller', () => {
const {
groupToolbar,
...restEditor
} = modules.builtInExplorerEditorPanel;
} = modules.builtInExplorerEditorPanel();
expect(data[0]).toEqual(expect.objectContaining(restEditor));

explorerService.reset();
Expand Down
17 changes: 8 additions & 9 deletions src/controller/__tests__/explorer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@ describe('The explorer controller', () => {
explorerController.initView();

const { headerToolBar, data } = explorerService.getState();
expect(headerToolBar.id).toBe(modules.builtInExplorerHeaderToolbar.id);
expect(headerToolBar.icon).toBe(
modules.builtInExplorerHeaderToolbar.icon
);
expect(headerToolBar.title).toBe(
modules.builtInExplorerHeaderToolbar.title
);
const { id, icon, title } = modules.builtInExplorerHeaderToolbar();
expect(headerToolBar.id).toBe(id);
expect(headerToolBar.icon).toBe(icon);
expect(headerToolBar.title).toBe(title);
expect(headerToolBar.contextMenu).toHaveLength(1);

expect(data).toHaveLength(1);
Expand All @@ -41,11 +38,13 @@ describe('The explorer controller', () => {
data: activityBarData,
selected,
} = activityBarService.getState();
const builtInExplorerActivityItem = modules.builtInExplorerActivityItem();

expect(activityBarData).toHaveLength(1);
expect(activityBarData![0]).toEqual(
expect.objectContaining(modules.builtInExplorerActivityItem)
expect.objectContaining(builtInExplorerActivityItem)
);
expect(selected).toBe(modules.builtInExplorerActivityItem.id);
expect(selected).toBe(builtInExplorerActivityItem.id);

const { current, panes } = sidebarService.getState();
expect(panes).toHaveLength(1);
Expand Down
12 changes: 6 additions & 6 deletions src/controller/__tests__/folderTree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,24 @@ describe('The folder tree controller', () => {
let menus = folderTreeController.onRightClick(mockTreeNode);

expect(menus).toEqual([
...modules.FILE_CONTEXT_MENU,
...modules.COMMON_CONTEXT_MENU,
...modules.FILE_CONTEXT_MENU(),
...modules.COMMON_CONTEXT_MENU(),
]);

// get the folder contextMenus
mockTreeNode.fileType = FileTypes.Folder;
menus = folderTreeController.onRightClick(mockTreeNode);
expect(menus).toEqual([
...modules.BASE_CONTEXT_MENU,
...modules.COMMON_CONTEXT_MENU,
...modules.BASE_CONTEXT_MENU(),
...modules.COMMON_CONTEXT_MENU(),
]);

// get the root folder contextMenus
mockTreeNode.fileType = FileTypes.RootFolder;
menus = folderTreeController.onRightClick(mockTreeNode);
expect(menus).toEqual([
...modules.BASE_CONTEXT_MENU,
...modules.ROOT_FOLDER_CONTEXT_MENU,
...modules.BASE_CONTEXT_MENU(),
...modules.ROOT_FOLDER_CONTEXT_MENU(),
]);

// error fileTypes
Expand Down
8 changes: 4 additions & 4 deletions src/controller/__tests__/panel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,23 @@ describe('The panel controller', () => {
const mockFn = jest.fn();
panelService.onTabChange(mockFn);

panelController.onTabChange(modules.builtInOutputPanel.id);
panelController.onTabChange(modules.builtInOutputPanel().id);

expect(panelService.getState().current).toEqual(
expect.objectContaining(modules.builtInOutputPanel)
);
expect(mockFn).toBeCalled();
expect(mockFn.mock.calls[0][0]).toBe(modules.builtInOutputPanel.id);
expect(mockFn.mock.calls[0][0]).toBe(modules.builtInOutputPanel().id);
});

test('Should support to subscribe onClose', () => {
const mockFn = jest.fn();
panelService.onTabClose(mockFn);

panelController.onClose(modules.builtInOutputPanel.id);
panelController.onClose(modules.builtInOutputPanel().id);

expect(mockFn).toBeCalled();
expect(mockFn.mock.calls[0][0]).toBe(modules.builtInOutputPanel.id);
expect(mockFn.mock.calls[0][0]).toBe(modules.builtInOutputPanel().id);
});

test('Should support to execute onToolbarClick', () => {
Expand Down
8 changes: 4 additions & 4 deletions src/controller/__tests__/problems.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('The problems controller', () => {
expect(name).toBe(constants.PROBLEM_MODEL_NAME);

const defaultStatus = statusBarService.getStatusBarItem(
modules.builtInStatusProblems.id,
modules.builtInStatusProblems().id,
Float.left
);
expect(defaultStatus).not.toBeNull();
Expand All @@ -41,7 +41,7 @@ describe('The problems controller', () => {
);

const defaultPanel = panelService.getPanel(
modules.builtInPanelProblems.id
modules.builtInPanelProblems().id
);
const { current } = panelService.getState();
expect(defaultPanel).not.toBeNull();
Expand All @@ -56,13 +56,13 @@ describe('The problems controller', () => {

problemsController.initView();
const defaultStatus = statusBarService.getStatusBarItem(
modules.builtInStatusProblems.id,
modules.builtInStatusProblems().id,
Float.left
);
expect(defaultStatus).toBeNull();

const defaultPanel = panelService.getPanel(
modules.builtInPanelProblems.id
modules.builtInPanelProblems().id
);
const { current } = panelService.getState();
expect(defaultPanel).toBeUndefined();
Expand Down
2 changes: 1 addition & 1 deletion src/controller/__tests__/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('The search controller', () => {
expect(sidebarService.getState().panes).toHaveLength(1);
expect(sidebarService.getState().panes[0]).toEqual(
expect.objectContaining({
id: modules.builtInSearchActivityItem.id,
id: modules.builtInSearchActivityItem().id,
title: 'SEARCH',
})
);
Expand Down
33 changes: 31 additions & 2 deletions src/provider/molecule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,46 @@ export class MoleculeProvider extends Component<IMoleculeProps> {
return this.layoutService.container;
}

/**
* Distinguish the language extensions from extensions
* @param extensions
* @returns
*/
private splitLanguagesExts(extensions: IExtension[]) {
const languagesExts: IExtension[] = [];
const others: IExtension[] = [];
extensions.forEach((ext) => {
if (ext.contributes?.languages) {
languagesExts.push(ext);
} else {
others.push(ext);
}
});

return [languagesExts, others];
}

initialize() {
const { extensions = [], defaultLocale = BuiltInDefault } = this.props;

const currentLocale = localStorage.getItem(STORE_KEY) || defaultLocale;
const [languages, others] = this.splitLanguagesExts(extensions);

/**
* TODO: 添加针对主题的默认值
*/
this.monacoService.initWorkspace(this.container!);
this.extensionService.load(defaultExtensions);
this.extensionService.load(extensions);

// Molecule should load the language extensions first to
// ensure that the custom language extensions is registered in localeService
this.extensionService.load(languages);

// And Molecule should set the correct locale before loading normal extensions in case of
// the localize method returns incorrect international text caused by incorrect current locale in the normal extensions
const currentLocale = localStorage.getItem(STORE_KEY) || defaultLocale;
this.localeService.setCurrentLocale(currentLocale);

this.extensionService.load(others);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/services/__tests__/panelService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { PanelEvent } from 'mo/model/workbench/panel';
import { expectLoggerErrorToBeCalled } from '@test/utils';
import { modules } from '../builtinService/const';

const paneOutput = modules.builtInOutputPanel;
const panelProblems = modules.builtInPanelProblems;
const paneOutput = modules.builtInOutputPanel();
const panelProblems = modules.builtInPanelProblems();

const resize = modules.builtInPanelToolboxResize;
const restore = modules.builtInPanelToolboxReStore;
const resize = modules.builtInPanelToolboxResize();
const restore = modules.builtInPanelToolboxReStore();

const panelService = container.resolve(PanelService);

Expand Down
6 changes: 3 additions & 3 deletions src/services/__tests__/statusBarService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { expectLoggerErrorToBeCalled } from '@test/utils';
import { modules } from '../builtinService/const';

const mockStatusData = {
...modules.STATUS_EDITOR_INFO,
...modules.STATUS_EDITOR_INFO(),
};

const anotherStatusData = {
Expand Down Expand Up @@ -96,12 +96,12 @@ describe('Test StatusBarService', () => {
expect(expected).toEqual({ ...anotherStatusData, sortIndex: 1 });

statusBarService.update({
id: modules.STATUS_EDITOR_INFO.id,
id: modules.STATUS_EDITOR_INFO().id,
sortIndex: 0,
});

expect(
statusBarService.getStatusBarItem(modules.STATUS_EDITOR_INFO.id)
statusBarService.getStatusBarItem(modules.STATUS_EDITOR_INFO().id)
?.sortIndex
).toBe(0);
});
Expand Down
Loading

0 comments on commit f0bfabb

Please sign in to comment.