Skip to content

Commit

Permalink
fix debug messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-marechal committed Oct 19, 2021
1 parent bfe3ce2 commit f83c04a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
10 changes: 4 additions & 6 deletions packages/core/src/common/messaging/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import { BareMessageConnection } from './bare-message-connection';
import { Disposable } from '../disposable';

/**
* A `Channel` represents a logical connection to a remote service.
* A `Channel` represents a bidirectional logical connection to a remote.
*/
export interface Channel extends Disposable {
send(content: string): void;
send(content: any): void;
onMessage(cb: (data: any) => void): void;
onError(cb: (reason: any) => void): void;
onClose(cb: (code: number, reason: string) => void): void;
Expand All @@ -39,7 +39,7 @@ export namespace Channel {
channel.onClose(() => this.fireClose());
}
listen(callback: rpc.DataCallback): rpc.Disposable {
this.channel.onMessage(data => callback(JSON.parse(data)));
this.channel.onMessage((data: string) => callback(JSON.parse(data)));
return rpc.Disposable.create(() => {
throw new Error('not supported');
});
Expand All @@ -55,9 +55,7 @@ export namespace Channel {
async write(message: rpc.Message): Promise<void> {
this.channel.send(JSON.stringify(message));
}
end(): void {
this.channel.dispose();
}
end(): void { }
}

export function createMessageConnection(channel: Channel, logger?: rpc.Logger, options?: rpc.ConnectionOptions): rpc.MessageConnection {
Expand Down
5 changes: 4 additions & 1 deletion packages/plugin-ext/src/common/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ export class PluginWebSocketChannel implements Channel {
constructor(protected readonly connection: PluginConnection) { }

send(content: string): void {
this.connection.writer.write({ jsonrpc: content });
// vscode-jsonrpc's MessageReader/Writer expect to send JSON-RPC messages.
// Use a bogus jsonrpc version and pass along the content to send.
const payload = { jsonrpc: '0.0', content };
this.connection.writer.write(payload);
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
8 changes: 4 additions & 4 deletions packages/plugin-ext/src/common/plugin-message-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,25 @@ export class PluginMessageReader extends AbstractMessageReader {

readMessage(message: string): void {
if (this.state === 'initial') {
this.events.splice(0, 0, { message });
this.events.unshift({ message });
} else if (this.state === 'listening') {
const data = JSON.parse(message);
const data = JSON.parse(message).content;
this.callback!(data);
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
fireError(error: any): void {
if (this.state === 'initial') {
this.events.splice(0, 0, { error });
this.events.unshift({ error });
} else if (this.state === 'listening') {
super.fireError(error);
}
}

fireClose(): void {
if (this.state === 'initial') {
this.events.splice(0, 0, {});
this.events.unshift({});
} else if (this.state === 'listening') {
super.fireClose();
}
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-ext/src/common/plugin-message-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export abstract class AbstractMessageWriter {
export class PluginMessageWriter extends AbstractMessageWriter implements MessageWriter {
constructor(
protected readonly id: string,
protected readonly proxy: ConnectionMain | ConnectionExt) {
protected readonly proxy: ConnectionMain | ConnectionExt
) {
super();
}

Expand Down
2 changes: 0 additions & 2 deletions packages/plugin-ext/src/hosted/node/hosted-plugin-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,10 @@ export class HostedPluginProcess implements ServerPluginRunner {

}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
public acceptMessage(pluginHostId: string, message: string): boolean {
return pluginHostId === 'main';
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
public onMessage(pluginHostId: string, jsonMessage: string): void {
if (this.childProcess) {
this.childProcess.send(jsonMessage);
Expand Down

0 comments on commit f83c04a

Please sign in to comment.