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

bugfix: handle generator types in JB #3788

Merged
merged 1 commit into from
Jan 20, 2025
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
42 changes: 38 additions & 4 deletions binary/src/IpcMessenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,46 @@ class IPCMessengerBase<
response &&
typeof response[Symbol.asyncIterator] === "function"
) {
for await (const update of response) {
this.send(msg.messageType, update, msg.messageId);
let next = await response.next();
while (!next.done) {
this.send(
msg.messageType,
{
done: false,
content: next.value,
status: "success",
},
msg.messageId,
);
next = await response.next();
}
this.send(msg.messageType, { done: true }, msg.messageId);
this.send(
msg.messageType,
{
done: true,
content: next.value,
status: "success",
},
msg.messageId,
);
} else {
this.send(msg.messageType, response, msg.messageId);
this.send(
msg.messageType,
{
done: true,
content: response,
status: "success",
},
msg.messageId,
);
}
} catch (e: any) {
this.send(
msg.messageType,
{ done: true, error: e.message, status: "error" },
msg.messageId,
);

console.warn(`Error running handler for "${msg.messageType}": `, e);
this._onErrorHandlers.forEach((handler) => {
handler(e);
Expand All @@ -62,6 +94,7 @@ class IPCMessengerBase<
}

private _unfinishedLine: string | undefined = undefined;

protected _handleData(data: Buffer) {
const d = data.toString();
const lines = d.split(/\r\n/).filter((line) => line.trim() !== "");
Expand Down Expand Up @@ -169,6 +202,7 @@ export class IpcMessenger<
process.exit(1);
});
}

_sendMsg(msg: Message) {
const d = JSON.stringify(msg);
// console.log("[info] Sending message: ", d);
Expand Down
42 changes: 38 additions & 4 deletions binary/src/TcpMessenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,46 @@ export class TcpMessenger<
response &&
typeof response[Symbol.asyncIterator] === "function"
) {
for await (const update of response) {
this.send(msg.messageType, update, msg.messageId);
let next = await response.next();
while (!next.done) {
this.send(
msg.messageType,
{
done: false,
content: next.value,
status: "success",
},
msg.messageId,
);
next = await response.next();
}
this.send(msg.messageType, { done: true }, msg.messageId);
this.send(
msg.messageType,
{
done: true,
content: next.value,
status: "success",
},
msg.messageId,
);
} else {
this.send(msg.messageType, response || {}, msg.messageId);
this.send(
msg.messageType,
{
done: true,
content: response,
status: "success",
},
msg.messageId,
);
}
} catch (e: any) {
this.send(
msg.messageType,
{ done: true, error: e.message, status: "error" },
msg.messageId,
);

console.warn(`Error running handler for "${msg.messageType}": `, e);
this._onErrorHandlers.forEach((handler) => {
handler(e);
Expand All @@ -98,6 +130,7 @@ export class TcpMessenger<
}

private _unfinishedLine: string | undefined = undefined;

private _handleData(data: Buffer) {
const d = data.toString();
const lines = d.split(/\r\n/).filter((line) => line.trim() !== "");
Expand Down Expand Up @@ -151,6 +184,7 @@ export class TcpMessenger<
data,
});
}

request<T extends keyof FromProtocol>(
messageType: T,
data: FromProtocol[T][0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ package com.github.continuedev.continueintellijextension.constants

class MessageTypes {
companion object {
val generatorTypes = listOf(
"llm/streamComplete",
"llm/streamChat",
"command/run",
"streamDiffLines"
)

val ideMessageTypes = listOf(
"readRangeInFile",
"isTelemetryEnabled",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,9 @@ class CoreMessenger(
// Responses for messageId
responseListeners[messageId]?.let { listener ->
listener(data)
if (MessageTypes.generatorTypes.contains(messageType)) {
val done = (data as Map<String, Boolean?>)["done"]
if (done == true) {
responseListeners.remove(messageId)
} else {
}
} else {
val done = (data as Map<String, Boolean>)["done"]

if (done == true) {
responseListeners.remove(messageId)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,7 @@ class ContinueBrowser(val project: Project, url: String) {


val respond = fun(data: Any?) {
// This matches the way that we expect receive messages in IdeMessenger.ts (gui)
// and the way they are sent in VS Code (webviewProtocol.ts)
var result: Map<String, Any?>? = if (MessageTypes.generatorTypes.contains(messageType)) {
data as? Map<String, Any?>
} else {
mutableMapOf(
"status" to "success",
"done" to false,
"content" to data
)
}

sendToWebview(messageType, result, messageId ?: uuid())
sendToWebview(messageType, data, messageId ?: uuid())
}

if (PASS_THROUGH_TO_CORE.contains(messageType)) {
Expand Down
12 changes: 7 additions & 5 deletions extensions/vscode/src/webviewProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import { IMessenger } from "../../../core/protocol/messenger";
import { showFreeTrialLoginMessage } from "./util/messages";

export class VsCodeWebviewProtocol
implements IMessenger<FromWebviewProtocol, ToWebviewProtocol>
{
implements IMessenger<FromWebviewProtocol, ToWebviewProtocol> {
listeners = new Map<
keyof FromWebviewProtocol,
((message: Message) => any)[]
Expand Down Expand Up @@ -83,7 +82,7 @@ export class VsCodeWebviewProtocol
status: "success",
});
} else {
respond({ content: response, status: "success" });
respond({ done: true, content: response, status: "success" });
}
} catch (e: any) {
respond({ done: true, error: e.message, status: "error" });
Expand Down Expand Up @@ -115,7 +114,8 @@ export class VsCodeWebviewProtocol
message = message.split("\n").filter((l: string) => l !== "")[1];
try {
message = JSON.parse(message).message;
} catch {}
} catch {
}
if (message.includes("exceeded")) {
message +=
" To keep using Continue, you can set up a local model or use your own API key.";
Expand Down Expand Up @@ -152,7 +152,9 @@ export class VsCodeWebviewProtocol
this._webviewListener = this._webview.onDidReceiveMessage(handleMessage);
}

constructor(private readonly reloadConfig: () => void) {}
constructor(private readonly reloadConfig: () => void) {
}

invoke<T extends keyof FromWebviewProtocol>(
messageType: T,
data: FromWebviewProtocol[T][0],
Expand Down
Loading