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

fix: create new channel when needed #106

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/core/src/api/renderDiffViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ import { BoxPanel, SplitPanel } from '../editor';
import { Injector } from '../modules/opensumi__common-di';
import { AppRenderer, IAppRendererProps } from './renderApp';

export {
IDiffViewerHandle,
IDiffViewerProps,
IDiffViewerTab,
IExtendPartialEditEvent,
} from '../core/diff-viewer/common';

export const defaultLayoutConfig = {
[SlotLocation.action]: {
modules: [''],
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export * from './api/createApp';
export * from './api/exports';
export * from './api/register';
export * from './api/renderApp';
export * from './api/renderDiffViewer';
export * from './api/require';
export * from './api/types';
6 changes: 6 additions & 0 deletions packages/sumi-core/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { SearchContribution } from './search/index.contribution';
import { WebConnectionHelper } from '@opensumi/ide-core-browser/lib/application/runtime';
import { IExtensionStorageService } from '@opensumi/ide-extension-storage';
import { getThemeTypeByPreferenceThemeId } from '../common/theme';
import { createChannel, InMemoryMessageChannel } from '../connection';
import { CodeBlitzAINativeContribution } from './ai-native';
import { injectAINativePreferences } from './ai-native/preferences';
import { ExtensionStorageServiceOverride } from './override/extensionStorageService';
Expand Down Expand Up @@ -135,6 +136,11 @@ export class ClientApp extends BasicClientApp {
constructor(opts: IAppOpts) {
super(opts);
this.modules = opts.modules;

this.injector.addProviders({
token: InMemoryMessageChannel,
useValue: createChannel(),
});
this.initServer(opts);
this.initMonacoProxy();
}
Expand Down
10 changes: 7 additions & 3 deletions packages/sumi-core/src/client/override/webConnectionHelper.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { Injectable } from '@opensumi/di';
import { Autowired, Injectable } from '@opensumi/di';
import { IRuntimeSocketConnection, WSChannel } from '@opensumi/ide-connection';
import { WSChannelHandler } from '@opensumi/ide-connection/lib/browser/ws-channel-handler';
import { RawMessageIO } from '@opensumi/ide-connection/lib/common/rpc/message-io';
import { rawSerializer } from '@opensumi/ide-connection/lib/common/serializer/raw';
import { createConnectionService, getDebugLogger, ModuleConstructor } from '@opensumi/ide-core-browser';
import { BaseConnectionHelper } from '@opensumi/ide-core-browser/lib/application/runtime/base-socket';
import { ClientPort, CodeBlitzConnection } from '../../connection';
import { CodeBlitzConnection, InMemoryMessageChannel } from '../../connection';

@Injectable({ multiple: true })
export class CodeBlitzConnectionHelper extends BaseConnectionHelper {
@Autowired(InMemoryMessageChannel)
private channel: InMemoryMessageChannel;

getDefaultClientId() {
return 'codeblitz';
}

createConnection(): IRuntimeSocketConnection {
return new CodeBlitzConnection(ClientPort);
return new CodeBlitzConnection(this.channel.port1);
}

createRPCServiceChannel(modules: ModuleConstructor[]): Promise<WSChannel> {
Expand Down
12 changes: 7 additions & 5 deletions packages/sumi-core/src/connection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ export interface Port {
call(...args: any): any;
}

const createChannel: () => { port1: Port; port2: Port } = () => {
export const InMemoryMessageChannel = Symbol('InMemoryMessageChannel');
export interface InMemoryMessageChannel {
port1: Port;
port2: Port;
}

export const createChannel: () => InMemoryMessageChannel = () => {
type InnerPort = {
callback(...args: any[]): any;
listen(cb: (...args: any[]) => any): void;
Expand Down Expand Up @@ -40,10 +46,6 @@ const createChannel: () => { port1: Port; port2: Port } = () => {
return { port1, port2 };
};

const { port1, port2 } = createChannel();

export { port1 as ClientPort, port2 as ServerPort };

export abstract class RPCService {
client?: any;
}
Expand Down
6 changes: 4 additions & 2 deletions packages/sumi-core/src/server/core/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
SupportLogNamespace,
} from '@opensumi/ide-core-common';
import * as path from 'path';
import { CodeBlitzConnection, ServerPort } from '../../connection';
import { CodeBlitzConnection, InMemoryMessageChannel, Port } from '../../connection';
import { ILogServiceManager } from './base';
import { INodeLogger, NodeLogger } from './node-logger';

Expand Down Expand Up @@ -220,7 +220,9 @@ export class ServerApp implements IServerApp {
await this.launch();
await this.initializeContribution();
const handler = new CodeblitzCommonChannelHandler('codeblitz-server');
handler.receiveConnection(new CodeBlitzConnection(ServerPort));

const channel = this.injector.get(InMemoryMessageChannel) as InMemoryMessageChannel;
handler.receiveConnection(new CodeBlitzConnection(channel.port2));

commonChannelPathHandler.register(RPCServiceChannelPath, {
handler: (channel: WSChannel, clientId: string) => {
Expand Down
Loading