Support IDE service calling
This commit is contained in:
parent
69efdb7017
commit
204fcbbe07
37
src/util/IDEServiceUtil.ts
Normal file
37
src/util/IDEServiceUtil.ts
Normal 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();
|
@ -291,6 +291,17 @@ const JStoIdea = {
|
|||||||
|
|
||||||
window.JSJavaBridge.callJava(JSON.stringify(params));
|
window.JSJavaBridge.callJava(JSON.stringify(params));
|
||||||
},
|
},
|
||||||
|
getIDEServicePort: () => {
|
||||||
|
// 获取完整的用户设置
|
||||||
|
const params = {
|
||||||
|
action: "getIDEServicePort/request",
|
||||||
|
metadata: {
|
||||||
|
callback: "IdeaToJSMessage",
|
||||||
|
},
|
||||||
|
payload: {},
|
||||||
|
};
|
||||||
|
window.JSJavaBridge.callJava(JSON.stringify(params));
|
||||||
|
},
|
||||||
readConfig: () => {
|
readConfig: () => {
|
||||||
// 获取完整的用户设置
|
// 获取完整的用户设置
|
||||||
const params = {
|
const params = {
|
||||||
@ -390,6 +401,9 @@ class IdeaBridge {
|
|||||||
case "loadConversations/response":
|
case "loadConversations/response":
|
||||||
this.resviceTopicDetail(res);
|
this.resviceTopicDetail(res);
|
||||||
break;
|
break;
|
||||||
|
case "getIDEServicePort/response":
|
||||||
|
this.resviceIDEServicePort(res);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -409,6 +423,10 @@ class IdeaBridge {
|
|||||||
this.executeHandlers("codeDiffApply", res.payload);
|
this.executeHandlers("codeDiffApply", res.payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resviceIDEServicePort(res) {
|
||||||
|
this.executeHandlers("getIDEServicePort", res.payload?.port);
|
||||||
|
}
|
||||||
|
|
||||||
resviceSendUserMessage(res) {
|
resviceSendUserMessage(res) {
|
||||||
this.executeHandlers("chatWithDevChat", {
|
this.executeHandlers("chatWithDevChat", {
|
||||||
command: "chatWithDevChat",
|
command: "chatWithDevChat",
|
||||||
@ -659,6 +677,10 @@ class IdeaBridge {
|
|||||||
// 保存用户设置
|
// 保存用户设置
|
||||||
JStoIdea.writeServerConfigBase(message.value);
|
JStoIdea.writeServerConfigBase(message.value);
|
||||||
break;
|
break;
|
||||||
|
case "getIDEServicePort":
|
||||||
|
// 保存用户设置
|
||||||
|
JStoIdea.getIDEServicePort();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import {
|
|||||||
IconExternalLink,
|
IconExternalLink,
|
||||||
} from "@tabler/icons-react";
|
} from "@tabler/icons-react";
|
||||||
import { useRouter } from "../router";
|
import { useRouter } from "../router";
|
||||||
|
import IDEServiceUtil from "@/util/IDEServiceUtil";
|
||||||
|
|
||||||
interface WorkflowConf {
|
interface WorkflowConf {
|
||||||
description: string;
|
description: string;
|
||||||
@ -160,6 +161,11 @@ const chatPanel = observer(() => {
|
|||||||
APIUtil.createEvent({name: e, value: e})
|
APIUtil.createEvent({name: e, value: e})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
messageUtil.registerHandler("getIDEServicePort", (port: number) => {
|
||||||
|
IDEServiceUtil.config(port)
|
||||||
|
})
|
||||||
|
|
||||||
|
messageUtil.sendMessage({ command: "getIDEServicePort" });
|
||||||
messageUtil.sendMessage({ command: "regCommandList" });
|
messageUtil.sendMessage({ command: "regCommandList" });
|
||||||
|
|
||||||
timer.start();
|
timer.start();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user