[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 优化部分启动逻辑 #1772

Merged
merged 15 commits into from
Oct 27, 2022
2 changes: 1 addition & 1 deletion packages/connection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@opensumi/ide-core-common": "2.20.9",
"@opensumi/vscode-jsonrpc": "^8.0.0-next.2",
"path-match": "^1.2.4",
"ws": "^7.2.0"
"ws": "^8.9.0"
},
"devDependencies": {
"@opensumi/ide-components": "2.20.9",
Expand Down
6 changes: 5 additions & 1 deletion packages/connection/src/node/common-channel-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ export class CommonChannelHandler extends WebSocketHandler {

private initWSServer() {
this.logger.log('init Common Channel Handler');
this.wsServer = new ws.Server({ noServer: true, ...this.options.wsServerOptions });
this.wsServer = new ws.Server({
noServer: true,
...this.options.wsServerOptions,
});
this.wsServer.on('connection', (connection: ws) => {
let connectionId;
connection.on('message', (msg: string) => {
Expand Down Expand Up @@ -194,6 +197,7 @@ export class CommonChannelHandler extends WebSocketHandler {
});
});
}

private channelConnectionSend = (connection: ws) => (content: string) => {
if (connection.readyState === connection.OPEN) {
connection.send(content, (err: any) => {
Expand Down
19 changes: 17 additions & 2 deletions packages/core-browser/src/bootstrap/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { electronEnv } from '../utils';
import { renderClientApp, IAppRenderer } from './app.view';
import { createClientConnection2, bindConnectionService } from './connection';
import { injectInnerProviders } from './inner-providers';
import { AppLifeCycleService, AppLifeCycleServiceToken, LifeCyclePhase } from './lifecycle.service';

export type ModuleConstructor = ConstructorOf<BrowserModule>;
export type ContributionConstructor = ConstructorOf<ClientAppContribution>;
Expand Down Expand Up @@ -240,6 +241,17 @@ export class ClientApp implements IClientApp, IDisposable {
}
}

get lifeCycleService(): AppLifeCycleService {
return this.injector.get(AppLifeCycleServiceToken);
}

/**
* LifeCycle
* 1. Prepare
* 2. Initialize
* 3. Starting
* 4. Ready
*/
public async start(
container: HTMLElement | IAppRenderer,
type?: 'electron' | 'web',
Expand All @@ -248,6 +260,8 @@ export class ClientApp implements IClientApp, IDisposable {
const reporterService: IReporterService = this.injector.get(IReporterService);
const measureReporter = reporterService.time(REPORT_NAME.MEASURE);

this.lifeCycleService.phase = LifeCyclePhase.Prepare;

if (connection) {
await bindConnectionService(this.injector, this.modules, connection);
} else {
Expand Down Expand Up @@ -283,6 +297,7 @@ export class ClientApp implements IClientApp, IDisposable {
this.stateService.state = 'started_contributions';
this.stateService.state = 'ready';

this.lifeCycleService.phase = LifeCyclePhase.Ready;
measureReporter.timeEnd('Framework.ready');
}

Expand Down Expand Up @@ -370,6 +385,7 @@ export class ClientApp implements IClientApp, IDisposable {
// 先渲染 layout,模块视图的时序由layout控制
await this.measure('RenderApp.render', () => this.renderApp(container));

this.lifeCycleService.phase = LifeCyclePhase.Initialize;
await this.measure('Contributions.initialize', () => this.initializeContributions());

// 初始化命令、快捷键与菜单
Expand All @@ -378,6 +394,7 @@ export class ClientApp implements IClientApp, IDisposable {
// 核心模块初始化完毕
this.stateService.state = 'core_module_initialized';

this.lifeCycleService.phase = LifeCyclePhase.Starting;
await this.measure('Contributions.onStart', () => this.onStartContributions());

await this.runContributionsPhase(this.contributions, 'onDidStart');
Expand All @@ -396,8 +413,6 @@ export class ClientApp implements IClientApp, IDisposable {
* run contribution#initialize
*/
private async initializeContributions() {
this.logger.verbose('startContributions clientAppContributions', this.contributions);

await this.runContributionsPhase(this.contributions, 'initialize');
this.appInitialized.resolve();

Expand Down
10 changes: 8 additions & 2 deletions packages/core-browser/src/bootstrap/inner-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { ClientAppStateService } from '../application/application-state-service'
import { ApplicationService } from '../application/application.service';
import { AuthenticationService } from '../authentication/authentication.service';
import { ClientAppContribution } from '../common';
import { ExtensionsPointServiceImpl, IExtensionsPointService } from '../extensions';
import { ExtensionsPointServiceImpl, IExtensionsSchemaService } from '../extensions';
import { FsProviderContribution } from '../fs';
import { KeybindingContribution, KeybindingService, KeybindingRegistryImpl, KeybindingRegistry } from '../keybinding';
import { BrowserKeyboardLayoutImpl, KeyValidator } from '../keyboard';
Expand Down Expand Up @@ -88,6 +88,8 @@ import { VariableRegistry, VariableRegistryImpl, VariableContribution } from '..
import { IWindowService } from '../window';
import { WindowService } from '../window/window.service';

import { AppLifeCycleService, AppLifeCycleServiceToken } from './lifecycle.service';

export function injectInnerProviders(injector: Injector) {
// 生成 ContributionProvider
createContributionProvider(injector, ClientAppContribution);
Expand Down Expand Up @@ -250,9 +252,13 @@ export function injectInnerProviders(injector: Injector) {
useClass: HashCalculateServiceImpl,
},
{
token: IExtensionsPointService,
token: IExtensionsSchemaService,
useClass: ExtensionsPointServiceImpl,
},
{
token: AppLifeCycleServiceToken,
Aaaaash marked this conversation as resolved.
Show resolved Hide resolved
useClass: AppLifeCycleService,
},
];
injector.addProviders(...providers);

Expand Down
28 changes: 28 additions & 0 deletions packages/core-browser/src/bootstrap/lifecycle.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Injectable } from '@opensumi/di';
import { Emitter } from '@opensumi/ide-core-common';

export const AppLifeCycleServiceToken = Symbol('AppLifeCycleService');

export const enum LifeCyclePhase {
Prepare = 1,
Initialize = 2,
Starting = 3,
Ready = 4,
}

@Injectable()
export class AppLifeCycleService {
private onDidChangeLifecyclePhaseEmitter: Emitter<LifeCyclePhase> = new Emitter();
public >

private lifeCyclePhase: LifeCyclePhase;

set phase(value: LifeCyclePhase) {
this.lifeCyclePhase = value;
this.onDidChangeLifecyclePhaseEmitter.fire(this.lifeCyclePhase);
}

get phase() {
return this.lifeCyclePhase;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ export interface IExtensionPointDescriptor {
frameworkKind?: FrameworkKind[];
}

export const IExtensionsPointService = Symbol('IExtensionsPointService');
export const IExtensionsSchemaService = Symbol('IExtensionsSchemaService');

export interface IExtensionsPointService {
export interface IExtensionsSchemaService {
registerExtensionPoint(desc: IExtensionPointDescriptor): void;
appendExtensionPoint(points: string[], desc: IExtensionPointDescriptor): void;
}

@Injectable()
export class ExtensionsPointServiceImpl implements IExtensionsPointService {
export class ExtensionsPointServiceImpl implements IExtensionsSchemaService {
@Autowired(IJSONSchemaRegistry)
private schemaRegistry: IJSONSchemaRegistry;

Expand Down
17 changes: 8 additions & 9 deletions packages/core-browser/src/monaco/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ export interface MonacoContribution {
contribCtor: new (editor: ICodeEditor, ...services: Services) => IEditorContribution,
) => void,
): void;

/**
* [{ id: association.id, mime: mimetype, filepattern: association.filePattern }]
* @param register
*/
registerPlatformLanguageAssociations?(register: (mime: MimeAssociation[]) => void): void;
}

export const Extensions = {
Expand Down Expand Up @@ -111,15 +117,8 @@ export const ISchemaStore = Symbol('ISchemaStore');

export interface MimeAssociation {
readonly id: string;
readonly filePattern: string;
}

export const IMimeService = Symbol('IMimeService');
export interface IMimeService {
/**
* 更新 mime
*/
updateMime(): void;
readonly filepattern: string;
readonly mime: string;
}

export interface SuggestEventPayload {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class PreferenceSchemaProvider extends PreferenceProvider {
const overridable = schema.overridable || false;
for (const preferenceName of Object.keys(schema.properties)) {
if (this.combinedSchema.properties[preferenceName] && !override) {
this.logger.error('Preference name collision detected in the schema for property: ' + preferenceName);
this.logger.warn('Preference name collision detected in the schema for property: ' + preferenceName);
continue;
} else {
const schemaProps = PreferenceDataProperty.fromPreferenceSchemaProperty(
Expand Down
17 changes: 9 additions & 8 deletions packages/core-common/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,15 @@ export class DefaultStorageProvider {
return this.storageCacheMap.get(storageId.toString());
}
const resolvers = this.resolversProvider.getContributions();
for (const resolver of resolvers) {
const storageResolver = await resolver.resolve(storageId);
if (storageResolver) {
this.storageCacheMap.set(storageId.toString(), storageResolver);
return storageResolver;
}
}
return;
return Promise.race(
resolvers.map(async (resolver) => {
const storageResolver = await resolver.resolve(storageId);
if (storageResolver) {
this.storageCacheMap.set(storageId.toString(), storageResolver);
return storageResolver;
}
}),
);
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/debug/src/browser/debug-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
PreferenceService,
IPreferenceSettingsService,
COMMON_COMMANDS,
IExtensionsPointService,
IExtensionsSchemaService,
} from '@opensumi/ide-core-browser';
import { browserViews } from '@opensumi/ide-core-browser/lib/extensions/schema/browserViews';
import { ToolbarRegistry, TabBarToolbarContribution } from '@opensumi/ide-core-browser/lib/layout';
Expand Down Expand Up @@ -334,8 +334,8 @@ export class DebugContribution
@Autowired(DebugContextKey)
protected readonly debugContextKey: DebugContextKey;

@Autowired(IExtensionsPointService)
protected readonly extensionsPointService: IExtensionsPointService;
@Autowired(IExtensionsSchemaService)
protected readonly extensionsPointService: IExtensionsSchemaService;

private firstSessionStart = true;

Expand Down
11 changes: 11 additions & 0 deletions packages/editor/src/browser/doc-model/editor-document-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ export class EditorDocumentModel extends Disposable implements IEditorDocumentMo
this.readCacheToApply();

this.addDispose(this._onDidChangeEncoding);

this.addDispose(
this.monacoModel.onDidChangeLanguage((e) => {
this.eventBus.fire(
new EditorDocumentModelOptionChangedEvent({
uri: this.uri,
languageId: e.newLanguage,
}),
);
}),
);
}

updateOptions(options) {
Expand Down
34 changes: 32 additions & 2 deletions packages/editor/src/browser/editor.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ import {
SUPPORTED_ENCODINGS,
FILE_COMMANDS,
electronEnv,
CorePreferences,
} from '@opensumi/ide-core-browser';
import { ComponentContribution, ComponentRegistry } from '@opensumi/ide-core-browser/lib/layout';
import { MenuContribution, IMenuRegistry, MenuId } from '@opensumi/ide-core-browser/lib/menu/next';
import { AbstractContextMenuService } from '@opensumi/ide-core-browser/lib/menu/next/menu.interface';
import { ICtxMenuRenderer } from '@opensumi/ide-core-browser/lib/menu/next/renderer/ctxmenu/base';
import { isWindows, isOSX, PreferenceScope, ILogger, OnEvent, WithEventBus } from '@opensumi/ide-core-common';
import { IElectronMainUIService } from '@opensumi/ide-core-common/lib/electron';
import { ITextmateTokenizer, ITextmateTokenizerService } from '@opensumi/ide-monaco/lib/browser/contrib/tokenizer';
import { EOL } from '@opensumi/ide-monaco/lib/browser/monaco-api/types';
import { EditorContextKeys } from '@opensumi/monaco-editor-core/esm/vs/editor/common/editorContextKeys';
import * as monaco from '@opensumi/monaco-editor-core/esm/vs/editor/editor.api';
Expand All @@ -53,7 +55,6 @@ import {
EditorGroupSplitAction,
ILanguageService,
Direction,
ResourceDecorationChangeEvent,
IDocPersistentCacheProvider,
IEditor,
SaveReason,
Expand All @@ -74,7 +75,7 @@ import { EditorContextMenuController } from './menu/editor.context';
import { NavigationMenuContainer } from './navigation.view';
import { GoToLineQuickOpenHandler } from './quick-open/go-to-line';
import { WorkspaceSymbolQuickOpenHandler } from './quick-open/workspace-symbol-quickopen';
import { EditorGroupsResetSizeEvent, BrowserEditorContribution, IEditorFeatureRegistry } from './types';
import { EditorGroupsResetSizeEvent, BrowserEditorContribution, IEditorFeatureRegistry, ResourceDecorationChangeEvent } from './types';
import { EditorSuggestWidgetContribution } from './view/suggest-widget';
import { EditorTopPaddingContribution } from './view/topPadding';
import { WorkbenchEditorServiceImpl, EditorGroup } from './workbench-editor.service';
Expand Down Expand Up @@ -160,6 +161,12 @@ export class EditorContribution
@Autowired(PreferenceService)
private readonly preferenceService: PreferenceService;

@Autowired(ITextmateTokenizer)
private readonly textmateService: ITextmateTokenizerService;

@Autowired(CorePreferences)
private readonly corePreferences: CorePreferences;

@Autowired(IEditorDocumentModelContentRegistry)
contentRegistry: IEditorDocumentModelContentRegistry;

Expand Down Expand Up @@ -235,6 +242,29 @@ export class EditorContribution
);
}

protected getMimeForMode(langId: string): string | undefined {
for (const language of this.textmateService.getLanguages()) {
if (language.id === langId && language.mimetypes) {
return language.mimetypes[0];
}
}
return undefined;
}

registerPlatformLanguageAssociations(register) {
const association = this.corePreferences['files.associations'];
if (!association) {
return;
}

const mimeAssociation = Object.keys(association).map((filepattern) => ({
id: association[filepattern],
filepattern,
mime: this.getMimeForMode(association[filepattern]) || `text/x-${association.id}`,
}));
register(mimeAssociation);
}

protected async interceptOpen(uri: URI) {
try {
await this.openerService.open(uri);
Expand Down
12 changes: 8 additions & 4 deletions packages/editor/src/browser/language/language.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
IRelatedInformation,
MarkerSeverity,
} from '@opensumi/ide-core-common';
import { ITextmateTokenizer, ITextmateTokenizerService } from '@opensumi/ide-monaco/lib/browser/contrib/tokenizer';
import * as monaco from '@opensumi/monaco-editor-core/esm/vs/editor/editor.api';

import {
Expand Down Expand Up @@ -83,6 +84,9 @@ export class LanguageService implements ILanguageService {
@Autowired()
private markerManager: MarkerManager;

@Autowired(ITextmateTokenizer)
private textmateService: ITextmateTokenizerService;

protected readonly markers = new Map<string, MonacoDiagnosticCollection>();

readonly workspaceSymbolProviders: WorkspaceSymbolProvider[] = [];
Expand All @@ -99,13 +103,13 @@ export class LanguageService implements ILanguageService {
}

get languages(): Language[] {
return [...this.mergeLanguages(monaco.languages.getLanguages()).values()];
return [...this.mergeLanguages(this.textmateService.getLanguages()).values()];
}

getLanguage(languageId: string): Language | undefined {
return this.mergeLanguages(monaco.languages.getLanguages().filter((language) => language.id === languageId)).get(
languageId,
);
return this.mergeLanguages(
this.textmateService.getLanguages().filter((language) => language.id === languageId),
).get(languageId);
}

protected mergeLanguages(registered: monaco.languages.ILanguageExtensionPoint[]): Map<string, Mutable<Language>> {
Expand Down
Loading