Skip to content

Commit

Permalink
Directly pass the message transport
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisalmen committed Aug 17, 2023
1 parent 96375b1 commit 44062d1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 21 deletions.
12 changes: 6 additions & 6 deletions packages/client/src/monaco-language-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ export type MonacoLanguageClientOptions = {
name: string;
id?: string;
clientOptions: LanguageClientOptions;
connectionProvider: IConnectionProvider;
messageTransports: MessageTransports;
}

export class MonacoLanguageClient extends BaseLanguageClient {
protected readonly connectionProvider: IConnectionProvider;
protected readonly messageTransports: MessageTransports;

constructor({ id, name, clientOptions, connectionProvider }: MonacoLanguageClientOptions) {
constructor({ id, name, clientOptions, messageTransports }: MonacoLanguageClientOptions) {
super(id || name.toLowerCase(), name, clientOptions);
this.connectionProvider = connectionProvider;
this.messageTransports = messageTransports;
}

protected createMessageTransports(encoding: string): Promise<MessageTransports> {
return this.connectionProvider.get(encoding);
protected override createMessageTransports(_encoding: string): Promise<MessageTransports> {
return Promise.resolve(this.messageTransports);

This comment has been minimized.

Copy link
@CGNonofr

CGNonofr Aug 17, 2023

Collaborator

so it will return the same message transport each time? what if it disconnects?

This comment has been minimized.

Copy link
@kaisalmen

kaisalmen Aug 17, 2023

Author Collaborator

Then all examples here are wrong, because the message transports / sockets are not re-created. They are created once.
If the connectionProvider implementation should do something else, then we use it wrong.

This comment has been minimized.

Copy link
@CGNonofr

CGNonofr Aug 17, 2023

Collaborator

The examples are probably improvable indeed, not a big change I think though: just more the socket creation logic into the provider

This comment has been minimized.

Copy link
@kaisalmen

kaisalmen Aug 18, 2023

Author Collaborator

True, we should do this. I will open an issue for that.

This comment has been minimized.

Copy link
@kaisalmen

kaisalmen Aug 18, 2023

Author Collaborator

@CGNonofr I opened #525

}

protected override getLocale(): string {
Expand Down
6 changes: 1 addition & 5 deletions packages/examples/main/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ export const createLanguageClient = (transports: MessageTransports): MonacoLangu
}
},
// create a language client connection from the JSON RPC connection on demand
connectionProvider: {
get: () => {
return Promise.resolve(transports);
}
}
messageTransports: transports
});
};

Expand Down
6 changes: 1 addition & 5 deletions packages/examples/main/src/langium/langiumClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ const run = async () => {
}
},
// create a language client connection to the server running in the web worker
connectionProvider: {
get: () => {
return Promise.resolve(transports);
}
}
messageTransports: transports
});
}

Expand Down
6 changes: 1 addition & 5 deletions packages/examples/main/src/langium/statemachineClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ const run = async () => {
}
},
// create a language client connection to the server running in the web worker
connectionProvider: {
get: () => {
return Promise.resolve(transports);
}
}
messageTransports: transports
});
}

Expand Down

0 comments on commit 44062d1

Please sign in to comment.