Support IDE service calling

This commit is contained in:
Luo Tim 2024-06-16 23:18:33 +08:00
parent 69efdb7017
commit 204fcbbe07
3 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,37 @@
import axios from "axios";
class IDEServiceUtil {
private static instance: IDEServiceUtil;
private host = "http://localhost";
private port: number | undefined;
constructor() {
console.log("IDEServiceUtil ready");
}
public static getInstance(): IDEServiceUtil {
if (!IDEServiceUtil.instance) {
IDEServiceUtil.instance = new IDEServiceUtil();
}
return IDEServiceUtil.instance;
}
config(port: number) {
console.log("Recieved IDEService port: ", port);
this.port = port;
}
async getCurrentFileInfo() {
try {
if (!this.port) return undefined;
const res = await axios.post(`${this.host}:${this.port}/getCurrentFileInfo`)
console.log("currentFileInfo: ", res?.data);
} catch(err) {
console.error(err);
}
}
}
export default IDEServiceUtil.getInstance();

View File

@ -291,6 +291,17 @@ const JStoIdea = {
window.JSJavaBridge.callJava(JSON.stringify(params));
},
getIDEServicePort: () => {
// 获取完整的用户设置
const params = {
action: "getIDEServicePort/request",
metadata: {
callback: "IdeaToJSMessage",
},
payload: {},
};
window.JSJavaBridge.callJava(JSON.stringify(params));
},
readConfig: () => {
// 获取完整的用户设置
const params = {
@ -390,6 +401,9 @@ class IdeaBridge {
case "loadConversations/response":
this.resviceTopicDetail(res);
break;
case "getIDEServicePort/response":
this.resviceIDEServicePort(res);
break;
default:
break;
}
@ -409,6 +423,10 @@ class IdeaBridge {
this.executeHandlers("codeDiffApply", res.payload);
}
resviceIDEServicePort(res) {
this.executeHandlers("getIDEServicePort", res.payload?.port);
}
resviceSendUserMessage(res) {
this.executeHandlers("chatWithDevChat", {
command: "chatWithDevChat",
@ -659,6 +677,10 @@ class IdeaBridge {
// 保存用户设置
JStoIdea.writeServerConfigBase(message.value);
break;
case "getIDEServicePort":
// 保存用户设置
JStoIdea.getIDEServicePort();
break;
default:
break;
}

View File

@ -23,6 +23,7 @@ import {
IconExternalLink,
} from "@tabler/icons-react";
import { useRouter } from "../router";
import IDEServiceUtil from "@/util/IDEServiceUtil";
interface WorkflowConf {
description: string;
@ -160,6 +161,11 @@ const chatPanel = observer(() => {
APIUtil.createEvent({name: e, value: e})
})
messageUtil.registerHandler("getIDEServicePort", (port: number) => {
IDEServiceUtil.config(port)
})
messageUtil.sendMessage({ command: "getIDEServicePort" });
messageUtil.sendMessage({ command: "regCommandList" });
timer.start();