🧑💻 set up debugging for binary with TcpMessenger
This commit is contained in:
parent
782e550622
commit
f39388aceb
13 changed files with 449 additions and 104 deletions
6
.vscode/launch.json
vendored
6
.vscode/launch.json
vendored
|
|
@ -15,7 +15,11 @@
|
|||
"outFiles": ["${workspaceFolder}/binary/out/**/*.js"],
|
||||
"sourceMaps": true,
|
||||
"smartStep": true,
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
"internalConsoleOptions": "openOnSessionStart",
|
||||
"cwd": "${workspaceFolder}/binary",
|
||||
"env": {
|
||||
"CONTINUE_DEVELOPMENT": "true"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
|
|
|
|||
111
binary/package-lock.json
generated
111
binary/package-lock.json
generated
|
|
@ -14,6 +14,7 @@
|
|||
"core": "file:../core",
|
||||
"follow-redirects": "^1.15.5",
|
||||
"ncp": "^2.0.0",
|
||||
"node-fetch": "^3.3.2",
|
||||
"posthog-node": "^3.6.3",
|
||||
"uuid": "^9.0.1",
|
||||
"vectordb": "^0.4.10"
|
||||
|
|
@ -1373,6 +1374,14 @@
|
|||
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/data-uri-to-buffer": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz",
|
||||
"integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==",
|
||||
"engines": {
|
||||
"node": ">= 12"
|
||||
}
|
||||
},
|
||||
"node_modules/debug": {
|
||||
"version": "4.3.4",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||
|
|
@ -1544,6 +1553,28 @@
|
|||
"reusify": "^1.0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/fetch-blob": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz",
|
||||
"integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/jimmywarting"
|
||||
},
|
||||
{
|
||||
"type": "paypal",
|
||||
"url": "https://paypal.me/jimmywarting"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"node-domexception": "^1.0.0",
|
||||
"web-streams-polyfill": "^3.0.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.20 || >= 14.13"
|
||||
}
|
||||
},
|
||||
"node_modules/fill-range": {
|
||||
"version": "7.0.1",
|
||||
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
|
||||
|
|
@ -1606,6 +1637,17 @@
|
|||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/formdata-polyfill": {
|
||||
"version": "4.0.10",
|
||||
"resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz",
|
||||
"integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==",
|
||||
"dependencies": {
|
||||
"fetch-blob": "^3.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.20.0"
|
||||
}
|
||||
},
|
||||
"node_modules/from2": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/from2/-/from2-2.3.0.tgz",
|
||||
|
|
@ -2050,24 +2092,39 @@
|
|||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/node-domexception": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz",
|
||||
"integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/jimmywarting"
|
||||
},
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://paypal.me/jimmywarting"
|
||||
}
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=10.5.0"
|
||||
}
|
||||
},
|
||||
"node_modules/node-fetch": {
|
||||
"version": "2.7.0",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz",
|
||||
"integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==",
|
||||
"dev": true,
|
||||
"version": "3.3.2",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz",
|
||||
"integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==",
|
||||
"dependencies": {
|
||||
"whatwg-url": "^5.0.0"
|
||||
"data-uri-to-buffer": "^4.0.0",
|
||||
"fetch-blob": "^3.1.4",
|
||||
"formdata-polyfill": "^4.0.10"
|
||||
},
|
||||
"engines": {
|
||||
"node": "4.x || >=6.0.0"
|
||||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"encoding": "^0.1.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"encoding": {
|
||||
"optional": true
|
||||
}
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/node-fetch"
|
||||
}
|
||||
},
|
||||
"node_modules/once": {
|
||||
|
|
@ -2178,6 +2235,26 @@
|
|||
"pkg-fetch": "lib-es5/bin.js"
|
||||
}
|
||||
},
|
||||
"node_modules/pkg-fetch/node_modules/node-fetch": {
|
||||
"version": "2.7.0",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz",
|
||||
"integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"whatwg-url": "^5.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "4.x || >=6.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"encoding": "^0.1.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"encoding": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/posthog-node": {
|
||||
"version": "3.6.3",
|
||||
"resolved": "https://registry.npmjs.org/posthog-node/-/posthog-node-3.6.3.tgz",
|
||||
|
|
@ -2750,6 +2827,14 @@
|
|||
"apache-arrow": "^14.0.2"
|
||||
}
|
||||
},
|
||||
"node_modules/web-streams-polyfill": {
|
||||
"version": "3.3.3",
|
||||
"resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz",
|
||||
"integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==",
|
||||
"engines": {
|
||||
"node": ">= 8"
|
||||
}
|
||||
},
|
||||
"node_modules/webidl-conversions": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@
|
|||
"core": "file:../core",
|
||||
"follow-redirects": "^1.15.5",
|
||||
"ncp": "^2.0.0",
|
||||
"node-fetch": "^3.3.2",
|
||||
"posthog-node": "^3.6.3",
|
||||
"uuid": "^9.0.1",
|
||||
"vectordb": "^0.4.10"
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
import { TODO } from "core/util";
|
||||
import { MessageIde } from "core/util/messageIde";
|
||||
import { IpcMessenger } from "./messenger";
|
||||
|
||||
export class IpcIde extends MessageIde {
|
||||
constructor(messenger: IpcMessenger<TODO, TODO>) {
|
||||
constructor(messenger: TODO) {
|
||||
super(messenger.request.bind(messenger));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { IProtocol } from "core/protocol";
|
||||
import { IMessenger, type Message } from "core/util/messenger";
|
||||
import { getCoreLogsPath } from "core/util/paths";
|
||||
import * as fs from "node:fs";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { IMessenger, type Message } from "../../core/util/messenger";
|
||||
|
||||
export class IpcMessenger<
|
||||
ToProtocol extends IProtocol,
|
||||
167
binary/src/TcpMessenger.ts
Normal file
167
binary/src/TcpMessenger.ts
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
import { IProtocol } from "core/protocol";
|
||||
import { IMessenger, Message } from "core/util/messenger";
|
||||
import net from "net";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
export class TcpMessenger<
|
||||
ToProtocol extends IProtocol,
|
||||
FromProtocol extends IProtocol,
|
||||
> implements IMessenger<ToProtocol, FromProtocol>
|
||||
{
|
||||
private port: number = 3000;
|
||||
private socket: net.Socket | null = null;
|
||||
|
||||
typeListeners = new Map<keyof ToProtocol, ((message: Message) => any)[]>();
|
||||
idListeners = new Map<string, (message: Message) => any>();
|
||||
|
||||
constructor() {
|
||||
const server = net.createServer((socket) => {
|
||||
this.socket = socket;
|
||||
socket.on("data", (data: Buffer) => {
|
||||
console.log("Received from server:", data.toString());
|
||||
this._handleData(data);
|
||||
});
|
||||
|
||||
socket.on("end", () => {
|
||||
console.log("Disconnected from server");
|
||||
});
|
||||
|
||||
socket.on("error", (err: any) => {
|
||||
console.error("Client error:", err);
|
||||
});
|
||||
});
|
||||
|
||||
server.listen(this.port, () => {
|
||||
console.log(`Server listening on port ${this.port}`);
|
||||
});
|
||||
}
|
||||
|
||||
private _onErrorHandlers: ((error: Error) => void)[] = [];
|
||||
|
||||
onError(handler: (error: Error) => void) {
|
||||
this._onErrorHandlers.push(handler);
|
||||
}
|
||||
|
||||
public async awaitConnection() {
|
||||
while (!this.socket) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
}
|
||||
}
|
||||
|
||||
private _handleLine(line: string) {
|
||||
try {
|
||||
const msg: Message = JSON.parse(line);
|
||||
if (msg.messageType === undefined || msg.messageId === undefined) {
|
||||
throw new Error("Invalid message sent: " + JSON.stringify(msg));
|
||||
}
|
||||
|
||||
// Call handler and respond with return value
|
||||
const listeners = this.typeListeners.get(msg.messageType as any);
|
||||
listeners?.forEach(async (handler) => {
|
||||
try {
|
||||
const response = await handler(msg);
|
||||
console.log(
|
||||
`Response from ${msg.messageType} handler: `,
|
||||
JSON.stringify(response),
|
||||
);
|
||||
if (
|
||||
response &&
|
||||
typeof response[Symbol.asyncIterator] === "function"
|
||||
) {
|
||||
for await (const update of response) {
|
||||
this.send(msg.messageType, update, msg.messageId);
|
||||
}
|
||||
this.send(msg.messageType, { done: true }, msg.messageId);
|
||||
} else {
|
||||
this.send(msg.messageType, response || {}, msg.messageId);
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.warn(`Error running handler for "${msg.messageType}": `, e);
|
||||
this._onErrorHandlers.forEach((handler) => {
|
||||
handler(e);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Call handler which is waiting for the response, nothing to return
|
||||
this.idListeners.get(msg.messageId)?.(msg);
|
||||
} catch (e) {
|
||||
let truncatedLine = line;
|
||||
if (line.length > 200) {
|
||||
truncatedLine =
|
||||
line.substring(0, 100) + "..." + line.substring(line.length - 100);
|
||||
}
|
||||
console.error("Error parsing line: ", truncatedLine, e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private _unfinishedLine: string | undefined = undefined;
|
||||
private _handleData(data: Buffer) {
|
||||
const d = data.toString();
|
||||
const lines = d.split(/\r\n/).filter((line) => line.trim() !== "");
|
||||
if (lines.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._unfinishedLine) {
|
||||
lines[0] = this._unfinishedLine + lines[0];
|
||||
this._unfinishedLine = undefined;
|
||||
}
|
||||
if (!d.endsWith("\r\n")) {
|
||||
this._unfinishedLine = lines.pop();
|
||||
}
|
||||
lines.forEach((line) => this._handleLine(line));
|
||||
}
|
||||
|
||||
send<T extends keyof FromProtocol>(
|
||||
messageType: T,
|
||||
data: FromProtocol[T][0],
|
||||
messageId?: string,
|
||||
): string {
|
||||
messageId = messageId ?? uuidv4();
|
||||
const msg: Message = {
|
||||
messageType: messageType as string,
|
||||
data,
|
||||
messageId,
|
||||
};
|
||||
|
||||
this.socket?.write(JSON.stringify(msg) + "\r\n");
|
||||
return messageId;
|
||||
}
|
||||
|
||||
on<T extends keyof ToProtocol>(
|
||||
messageType: T,
|
||||
handler: (message: Message<ToProtocol[T][0]>) => ToProtocol[T][1],
|
||||
): void {
|
||||
if (!this.typeListeners.has(messageType)) {
|
||||
this.typeListeners.set(messageType, []);
|
||||
}
|
||||
this.typeListeners.get(messageType)?.push(handler);
|
||||
}
|
||||
|
||||
invoke<T extends keyof ToProtocol>(
|
||||
messageType: T,
|
||||
data: ToProtocol[T][0],
|
||||
): ToProtocol[T][1] {
|
||||
return this.typeListeners.get(messageType)?.[0]?.({
|
||||
messageId: uuidv4(),
|
||||
messageType: messageType as string,
|
||||
data,
|
||||
});
|
||||
}
|
||||
request<T extends keyof FromProtocol>(
|
||||
messageType: T,
|
||||
data: FromProtocol[T][0],
|
||||
): Promise<FromProtocol[T][1]> {
|
||||
const messageId = uuidv4();
|
||||
return new Promise((resolve) => {
|
||||
const handler = (msg: Message) => {
|
||||
resolve(msg.data);
|
||||
this.idListeners.delete(messageId);
|
||||
};
|
||||
this.idListeners.set(messageId, handler);
|
||||
this.send(messageType, data, messageId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -2,21 +2,32 @@ process.env.IS_BINARY = "true";
|
|||
import { Command } from "commander";
|
||||
import { Core } from "core/core";
|
||||
import { FromCoreProtocol, ToCoreProtocol } from "core/protocol";
|
||||
import { IMessenger } from "core/util/messenger";
|
||||
import { getCoreLogsPath } from "core/util/paths";
|
||||
import fs from "node:fs";
|
||||
import { IpcIde } from "./IpcIde";
|
||||
import { IpcMessenger } from "./messenger";
|
||||
import { IpcMessenger } from "./IpcMessenger";
|
||||
import { TcpMessenger } from "./TcpMessenger";
|
||||
|
||||
const logFilePath = getCoreLogsPath();
|
||||
fs.appendFileSync(logFilePath, "[info] Starting Continue core...\n");
|
||||
|
||||
const program = new Command();
|
||||
|
||||
program.action(() => {
|
||||
program.action(async () => {
|
||||
try {
|
||||
const messenger = new IpcMessenger<ToCoreProtocol, FromCoreProtocol>();
|
||||
let messenger: IMessenger<ToCoreProtocol, FromCoreProtocol>;
|
||||
if (process.env.CONTINUE_DEVELOPMENT === "true") {
|
||||
messenger = new TcpMessenger<ToCoreProtocol, FromCoreProtocol>();
|
||||
console.log("Waiting for connection");
|
||||
await (
|
||||
messenger as TcpMessenger<ToCoreProtocol, FromCoreProtocol>
|
||||
).awaitConnection();
|
||||
console.log("Connected");
|
||||
} else {
|
||||
messenger = new IpcMessenger<ToCoreProtocol, FromCoreProtocol>();
|
||||
}
|
||||
const ide = new IpcIde(messenger);
|
||||
// const ide = new FileSystemIde(); // for testing
|
||||
const core = new Core(messenger, ide);
|
||||
} catch (e) {
|
||||
fs.writeFileSync("./error.log", `${new Date().toISOString()} ${e}\n`);
|
||||
|
|
|
|||
14
core/core.ts
14
core/core.ts
|
|
@ -66,12 +66,14 @@ export class Core {
|
|||
);
|
||||
this.codebaseIndexerPromise = new Promise(async (resolve) => {
|
||||
const ideSettings = await ideSettingsPromise;
|
||||
new CodebaseIndexer(
|
||||
this.configHandler,
|
||||
this.ide,
|
||||
new PauseToken(false),
|
||||
ideSettings.remoteConfigServerUrl,
|
||||
ideSettings.userToken,
|
||||
resolve(
|
||||
new CodebaseIndexer(
|
||||
this.configHandler,
|
||||
this.ide,
|
||||
new PauseToken(false),
|
||||
ideSettings.remoteConfigServerUrl,
|
||||
ideSettings.userToken,
|
||||
),
|
||||
);
|
||||
this.ide
|
||||
.getWorkspaceDirs()
|
||||
|
|
|
|||
|
|
@ -76,5 +76,6 @@ export const DEFAULT_IGNORE_DIRS = [
|
|||
".continue",
|
||||
"__pycache__",
|
||||
"site-packages",
|
||||
".gradle",
|
||||
];
|
||||
export const defaultIgnoreDir = ignore().add(DEFAULT_IGNORE_DIRS);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
package com.github.continuedev.continueintellijextension.`continue`
|
||||
import com.github.continuedev.continueintellijextension.services.ContinueExtensionSettings
|
||||
import com.github.continuedev.continueintellijextension.services.ContinuePluginService
|
||||
import java.io.BufferedReader
|
||||
import java.io.InputStreamReader
|
||||
|
|
@ -10,28 +11,30 @@ import com.google.gson.Gson
|
|||
import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.project.Project
|
||||
import java.net.Socket
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
import java.nio.file.attribute.PosixFilePermission
|
||||
|
||||
class CoreMessenger(private val project: Project, esbuildPath: String, continueCorePath: String, ideProtocolClient: IdeProtocolClient) {
|
||||
private val writer: OutputStreamWriter
|
||||
private val reader: BufferedReader
|
||||
private val process: Process
|
||||
private var writer: Writer? = null
|
||||
private var reader: BufferedReader? = null
|
||||
private var process: Process? = null
|
||||
private val gson = Gson()
|
||||
private val responseListeners = mutableMapOf<String, (String) -> Unit>()
|
||||
private val ideProtocolClient = ideProtocolClient
|
||||
private val useTcp: Boolean = true
|
||||
|
||||
private fun write(message: String) {
|
||||
writer.write(message + "\r\n")
|
||||
writer.flush()
|
||||
writer?.write(message + "\r\n")
|
||||
writer?.flush()
|
||||
}
|
||||
|
||||
private fun close() {
|
||||
writer.close()
|
||||
reader.close()
|
||||
val exitCode = process.waitFor()
|
||||
writer?.close()
|
||||
reader?.close()
|
||||
val exitCode = process?.waitFor()
|
||||
println("Subprocess exited with code: $exitCode")
|
||||
}
|
||||
|
||||
|
|
@ -66,8 +69,20 @@ class CoreMessenger(private val project: Project, esbuildPath: String, continueC
|
|||
|
||||
// Forward to webview
|
||||
if (forwardToWebview.contains(messageType)) {
|
||||
// TODO: Currently we aren't set up to receive a response back from the webview
|
||||
// Can circumvent for getDefaultsModelTitle here for now
|
||||
if (messageType == "getDefaultModelTitle") {
|
||||
val continueSettingsService = service<ContinueExtensionSettings>()
|
||||
val defaultModelTitle = continueSettingsService.continueState.lastSelectedInlineEditModel;
|
||||
val message = gson.toJson(mapOf(
|
||||
"messageId" to messageId,
|
||||
"messageType" to messageType,
|
||||
"data" to defaultModelTitle
|
||||
))
|
||||
write(message)
|
||||
}
|
||||
val continuePluginService = project.service<ContinuePluginService>()
|
||||
continuePluginService.sendToWebview(messageType, data, messageType)
|
||||
continuePluginService.sendToWebview(messageType, responseMap["data"], messageType)
|
||||
}
|
||||
|
||||
// Responses for messageId
|
||||
|
|
@ -120,11 +135,18 @@ class CoreMessenger(private val project: Project, esbuildPath: String, continueC
|
|||
"getBranch",
|
||||
"getIdeInfo",
|
||||
"getIdeSettings",
|
||||
"errorPopup"
|
||||
"errorPopup",
|
||||
"getRepoName",
|
||||
"listDir",
|
||||
"getGitRootPath",
|
||||
"getLastModified"
|
||||
)
|
||||
|
||||
private val forwardToWebview = listOf<String>(
|
||||
"configUpdate"
|
||||
"configUpdate",
|
||||
"getDefaultModelTitle",
|
||||
"indexProgress",
|
||||
"refreshSubmenuItems"
|
||||
)
|
||||
|
||||
private fun setPermissions(destination: String) {
|
||||
|
|
@ -151,55 +173,94 @@ class CoreMessenger(private val project: Project, esbuildPath: String, continueC
|
|||
}
|
||||
|
||||
init {
|
||||
// Set proper permissions
|
||||
setPermissions(continueCorePath)
|
||||
setPermissions(esbuildPath)
|
||||
|
||||
// Start the subprocess
|
||||
val processBuilder = ProcessBuilder(continueCorePath)
|
||||
.directory(File(continueCorePath).parentFile)
|
||||
process = processBuilder.start()
|
||||
|
||||
val outputStream = process.outputStream
|
||||
val inputStream = process.inputStream
|
||||
|
||||
writer = OutputStreamWriter(outputStream, StandardCharsets.UTF_8)
|
||||
reader = BufferedReader(InputStreamReader(inputStream, StandardCharsets.UTF_8))
|
||||
|
||||
process.onExit().thenRun {
|
||||
val err = process.errorStream.bufferedReader().readText().trim()
|
||||
println("Core process exited with output: $err")
|
||||
ideProtocolClient.showMessage("Core process exited with output: $err")
|
||||
}
|
||||
|
||||
Thread {
|
||||
if (useTcp) {
|
||||
try {
|
||||
while (true) {
|
||||
val line = reader.readLine()
|
||||
if (line != null && line.isNotEmpty()) {
|
||||
try {
|
||||
handleMessage(line)
|
||||
} catch (e: Exception) {
|
||||
println("Error handling message: $line")
|
||||
println(e)
|
||||
val socket = Socket("localhost", 3000)
|
||||
val writer = PrintWriter(socket.getOutputStream(), true)
|
||||
this.writer = writer
|
||||
val reader = BufferedReader(InputStreamReader(socket.getInputStream()))
|
||||
this.reader = reader
|
||||
|
||||
Thread {
|
||||
try {
|
||||
while (true) {
|
||||
val line = reader.readLine()
|
||||
if (line != null && line.isNotEmpty()) {
|
||||
try {
|
||||
handleMessage(line)
|
||||
} catch (e: Exception) {
|
||||
println("Error handling message: $line")
|
||||
println(e)
|
||||
}
|
||||
} else {
|
||||
Thread.sleep(100)
|
||||
}
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
try {
|
||||
reader.close()
|
||||
writer.close()
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
} else {
|
||||
Thread.sleep(100)
|
||||
}
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
}.start()
|
||||
} catch (e: Exception) {
|
||||
println("An error occurred: ${e.message}")
|
||||
}
|
||||
} else {
|
||||
// Set proper permissions
|
||||
setPermissions(continueCorePath)
|
||||
setPermissions(esbuildPath)
|
||||
|
||||
// Start the subprocess
|
||||
val processBuilder = ProcessBuilder(continueCorePath)
|
||||
.directory(File(continueCorePath).parentFile)
|
||||
process = processBuilder.start()
|
||||
|
||||
val outputStream = process!!.outputStream
|
||||
val inputStream = process!!.inputStream
|
||||
|
||||
writer = OutputStreamWriter(outputStream, StandardCharsets.UTF_8)
|
||||
reader = BufferedReader(InputStreamReader(inputStream, StandardCharsets.UTF_8))
|
||||
|
||||
process!!.onExit().thenRun {
|
||||
val err = process?.errorStream?.bufferedReader()?.readText()?.trim()
|
||||
println("Core process exited with output: $err")
|
||||
ideProtocolClient.showMessage("Core process exited with output: $err")
|
||||
}
|
||||
|
||||
Thread {
|
||||
try {
|
||||
reader.close()
|
||||
writer.close()
|
||||
outputStream.close()
|
||||
inputStream.close()
|
||||
process.destroy()
|
||||
while (true) {
|
||||
val line = reader?.readLine()
|
||||
if (line != null && line.isNotEmpty()) {
|
||||
try {
|
||||
handleMessage(line)
|
||||
} catch (e: Exception) {
|
||||
println("Error handling message: $line")
|
||||
println(e)
|
||||
}
|
||||
} else {
|
||||
Thread.sleep(100)
|
||||
}
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
try {
|
||||
reader?.close()
|
||||
writer?.close()
|
||||
outputStream.close()
|
||||
inputStream.close()
|
||||
process?.destroy()
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ class IdeProtocolClient (
|
|||
)
|
||||
val messageType = parsedMessage["messageType"] as? String
|
||||
if (messageType == null) {
|
||||
println("Recieved message without type: $text")
|
||||
println("Received message without type: $text")
|
||||
return@launch
|
||||
}
|
||||
val data = parsedMessage["data"]
|
||||
|
|
@ -360,7 +360,7 @@ class IdeProtocolClient (
|
|||
val output = reader.readLine()
|
||||
process.waitFor()
|
||||
|
||||
respond(output)
|
||||
respond(output ?: "NONE")
|
||||
}
|
||||
"getRepoName" -> {
|
||||
// Get the current repository name
|
||||
|
|
@ -372,7 +372,7 @@ class IdeProtocolClient (
|
|||
val output = reader.readLine()
|
||||
process.waitFor()
|
||||
|
||||
respond(output)
|
||||
respond(output ?: "NONE")
|
||||
}
|
||||
|
||||
// NEW //
|
||||
|
|
@ -717,7 +717,9 @@ class IdeProtocolClient (
|
|||
".pytest_cache",
|
||||
".vscode-test",
|
||||
".continue",
|
||||
"__pycache__"
|
||||
"__pycache__",
|
||||
"site-packages",
|
||||
".gradle",
|
||||
)
|
||||
private fun shouldIgnoreDirectory(name: String): Boolean {
|
||||
val components = File(name).path.split(File.separator)
|
||||
|
|
|
|||
|
|
@ -25,24 +25,36 @@ class ContinueBrowser(val project: Project, url: String, useOsr: Boolean = false
|
|||
}
|
||||
|
||||
private val PASS_THROUGH_TO_CORE = listOf(
|
||||
"abort",
|
||||
"getContinueDir",
|
||||
"history/list",
|
||||
"history/save",
|
||||
"history/delete",
|
||||
"history/load",
|
||||
"devdata/log",
|
||||
"config/addModel",
|
||||
"config/deleteModel",
|
||||
"config/addOpenAIKey",
|
||||
"llm/streamComplete",
|
||||
"llm/streamChat",
|
||||
"llm/complete",
|
||||
"command/run",
|
||||
"context/loadSubmenuItems",
|
||||
"context/getContextItems",
|
||||
"context/addDocs",
|
||||
"config/getBrowserSerialized",
|
||||
"update/modelChange",
|
||||
"ping",
|
||||
"abort",
|
||||
"history/list",
|
||||
"history/delete",
|
||||
"history/load",
|
||||
"history/save",
|
||||
"devdata/log",
|
||||
"config/addOpenAiKey",
|
||||
"config/addModel",
|
||||
"config/ideSettingsUpdate",
|
||||
"config/getBrowserSerialized",
|
||||
"config/deleteModel",
|
||||
"config/reload",
|
||||
"context/getContextItems",
|
||||
"context/loadSubmenuItems",
|
||||
"context/addDocs",
|
||||
"autocomplete/complete",
|
||||
"autocomplete/cancel",
|
||||
"autocomplete/accept",
|
||||
"command/run",
|
||||
"llm/complete",
|
||||
"llm/streamComplete",
|
||||
"llm/streamChat",
|
||||
"streamDiffLines",
|
||||
"stats/getTokensPerDay",
|
||||
"stats/getTokensPerModel",
|
||||
"index/setPaused",
|
||||
"index/forceReIndex",
|
||||
"completeOnboarding"
|
||||
)
|
||||
|
||||
private fun registerAppSchemeHandler() {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
<div id="root"></div>
|
||||
|
||||
<script>
|
||||
localStorage.setItem("ide", "jetbrains");
|
||||
localStorage.setItem("ide", '"jetbrains"');
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue