feat: update bridge
This commit is contained in:
parent
857f0a9b01
commit
5b69359a4b
@ -4,11 +4,15 @@ class MessageUtil {
|
||||
private static instance: MessageUtil;
|
||||
|
||||
handlers: { [x: string]: any };
|
||||
vscodeApi: any;
|
||||
messageListener: any;
|
||||
|
||||
constructor() {
|
||||
this.handlers = {};
|
||||
this.messageListener = null;
|
||||
if (process.env.platform === "vscode") {
|
||||
this.vscodeApi = window.acquireVsCodeApi();
|
||||
}
|
||||
|
||||
if (!this.messageListener) {
|
||||
this.messageListener = (event: { data: any }) => {
|
||||
@ -64,7 +68,7 @@ class MessageUtil {
|
||||
if (process.env.platform === "idea") {
|
||||
IdeaBridge.sendMessage(message);
|
||||
} else {
|
||||
window.acquireVsCodeApi().postMessage(message);
|
||||
this.vscodeApi.postMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,4 +40,4 @@
|
||||
- regModelList // 与 regModelList
|
||||
- receiveMessagePartial // 部分对话
|
||||
- receiveMessage // 对话
|
||||
- systemMessage ??
|
||||
- systemMessage // 没用了
|
||||
|
@ -80,7 +80,7 @@ const JStoIdea = {
|
||||
content: code,
|
||||
},
|
||||
};
|
||||
|
||||
console.log("request viewDiff: ", params);
|
||||
window.JSJavaBridge.callJava(JSON.stringify(params));
|
||||
},
|
||||
getUserAccessKey: () => {
|
||||
@ -112,6 +112,33 @@ const JStoIdea = {
|
||||
break;
|
||||
}
|
||||
},
|
||||
updateSetting: (value: string) => {
|
||||
// 因为现在只有更换模型,所以直接取 value
|
||||
const params = {
|
||||
action: "updateSetting/request",
|
||||
metadata: {
|
||||
callback: "IdeaToJSMessage",
|
||||
},
|
||||
payload: {
|
||||
setting: {
|
||||
currentModel: value,
|
||||
},
|
||||
},
|
||||
};
|
||||
window.JSJavaBridge.callJava(JSON.stringify(params));
|
||||
},
|
||||
commit: (code: string) => {
|
||||
const params = {
|
||||
action: "commitCode/request",
|
||||
metadata: {
|
||||
callback: "IdeaToJSMessage",
|
||||
},
|
||||
payload: {
|
||||
message: code,
|
||||
},
|
||||
};
|
||||
window.JSJavaBridge.callJava(JSON.stringify(params));
|
||||
},
|
||||
};
|
||||
|
||||
class IdeaBridge {
|
||||
@ -122,6 +149,7 @@ class IdeaBridge {
|
||||
this.handle = {};
|
||||
// 注册全局的回调函数,用于接收来自IDEA的消息
|
||||
window.IdeaToJSMessage = (res: any) => {
|
||||
console.log("IdeaToJSMessage res: ", res);
|
||||
switch (res.action) {
|
||||
case "sendMessage/response":
|
||||
this.resviceMessage(res);
|
||||
@ -135,8 +163,16 @@ class IdeaBridge {
|
||||
case "listCommands/response":
|
||||
this.resviceCommandList(res);
|
||||
break;
|
||||
case "getKey/response":
|
||||
this.resviceAccessKey(res.payload.key);
|
||||
// 这里暂时不用,因为获取到的只有 key,信息不全
|
||||
// 所以用 resviceSettings 来获取
|
||||
// case "getKey/response":
|
||||
// this.resviceAccessKey(res.payload.key);
|
||||
// break;
|
||||
case "addContext/notify":
|
||||
this.resviesContext(res);
|
||||
break;
|
||||
case "getSetting/response":
|
||||
this.resviceSettings(res);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -144,6 +180,35 @@ class IdeaBridge {
|
||||
};
|
||||
}
|
||||
|
||||
resviesContext(res) {
|
||||
console.log("resviesContextres: ", res);
|
||||
const params = {
|
||||
file: res.payload.path,
|
||||
result: "",
|
||||
};
|
||||
const contextObj = {
|
||||
path: res.payload.path,
|
||||
content: res.payload.content,
|
||||
command: "",
|
||||
};
|
||||
params.result = JSON.stringify(contextObj);
|
||||
this.handle.contextDetailResponse(params);
|
||||
}
|
||||
|
||||
resviceSettings(res) {
|
||||
// 用户设置的回调
|
||||
const setting = res.payload.setting;
|
||||
// 当前的默认模型
|
||||
this.handle.getSetting({
|
||||
value: setting.currentModel,
|
||||
});
|
||||
this.handle.getUserAccessKey({
|
||||
endPoint: setting.apiBase,
|
||||
accessKey: setting.apiKey,
|
||||
keyType: setting.apiKey.startsWith("DC") ? "DevChat" : "OpenAi",
|
||||
});
|
||||
}
|
||||
|
||||
resviceAccessKey(res: string = "") {
|
||||
const params = {
|
||||
endPoint: "",
|
||||
@ -241,10 +306,18 @@ class IdeaBridge {
|
||||
case "getUserAccessKey":
|
||||
JStoIdea.getUserAccessKey();
|
||||
break;
|
||||
|
||||
case "doCommand":
|
||||
JStoIdea.etcCommand(message);
|
||||
break;
|
||||
case "show_diff":
|
||||
JStoIdea.viewDiff(message.content);
|
||||
break;
|
||||
case "updateSetting":
|
||||
JStoIdea.updateSetting(message.value);
|
||||
break;
|
||||
case "doCommit":
|
||||
JStoIdea.commit(message.content);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -165,6 +165,9 @@ const webviewConfig = {
|
||||
filename: "welcome.html",
|
||||
chunks: ["welcome"],
|
||||
}),
|
||||
new DefinePlugin({
|
||||
"process.env.platform": JSON.stringify("vscode"),
|
||||
}),
|
||||
],
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user