feat: update bridge
This commit is contained in:
parent
857f0a9b01
commit
5b69359a4b
@ -4,11 +4,15 @@ class MessageUtil {
|
|||||||
private static instance: MessageUtil;
|
private static instance: MessageUtil;
|
||||||
|
|
||||||
handlers: { [x: string]: any };
|
handlers: { [x: string]: any };
|
||||||
|
vscodeApi: any;
|
||||||
messageListener: any;
|
messageListener: any;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.handlers = {};
|
this.handlers = {};
|
||||||
this.messageListener = null;
|
this.messageListener = null;
|
||||||
|
if (process.env.platform === "vscode") {
|
||||||
|
this.vscodeApi = window.acquireVsCodeApi();
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.messageListener) {
|
if (!this.messageListener) {
|
||||||
this.messageListener = (event: { data: any }) => {
|
this.messageListener = (event: { data: any }) => {
|
||||||
@ -64,7 +68,7 @@ class MessageUtil {
|
|||||||
if (process.env.platform === "idea") {
|
if (process.env.platform === "idea") {
|
||||||
IdeaBridge.sendMessage(message);
|
IdeaBridge.sendMessage(message);
|
||||||
} else {
|
} else {
|
||||||
window.acquireVsCodeApi().postMessage(message);
|
this.vscodeApi.postMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,4 +40,4 @@
|
|||||||
- regModelList // 与 regModelList
|
- regModelList // 与 regModelList
|
||||||
- receiveMessagePartial // 部分对话
|
- receiveMessagePartial // 部分对话
|
||||||
- receiveMessage // 对话
|
- receiveMessage // 对话
|
||||||
- systemMessage ??
|
- systemMessage // 没用了
|
||||||
|
@ -80,7 +80,7 @@ const JStoIdea = {
|
|||||||
content: code,
|
content: code,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
console.log("request viewDiff: ", params);
|
||||||
window.JSJavaBridge.callJava(JSON.stringify(params));
|
window.JSJavaBridge.callJava(JSON.stringify(params));
|
||||||
},
|
},
|
||||||
getUserAccessKey: () => {
|
getUserAccessKey: () => {
|
||||||
@ -112,6 +112,33 @@ const JStoIdea = {
|
|||||||
break;
|
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 {
|
class IdeaBridge {
|
||||||
@ -122,6 +149,7 @@ class IdeaBridge {
|
|||||||
this.handle = {};
|
this.handle = {};
|
||||||
// 注册全局的回调函数,用于接收来自IDEA的消息
|
// 注册全局的回调函数,用于接收来自IDEA的消息
|
||||||
window.IdeaToJSMessage = (res: any) => {
|
window.IdeaToJSMessage = (res: any) => {
|
||||||
|
console.log("IdeaToJSMessage res: ", res);
|
||||||
switch (res.action) {
|
switch (res.action) {
|
||||||
case "sendMessage/response":
|
case "sendMessage/response":
|
||||||
this.resviceMessage(res);
|
this.resviceMessage(res);
|
||||||
@ -135,8 +163,16 @@ class IdeaBridge {
|
|||||||
case "listCommands/response":
|
case "listCommands/response":
|
||||||
this.resviceCommandList(res);
|
this.resviceCommandList(res);
|
||||||
break;
|
break;
|
||||||
case "getKey/response":
|
// 这里暂时不用,因为获取到的只有 key,信息不全
|
||||||
this.resviceAccessKey(res.payload.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;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
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 = "") {
|
resviceAccessKey(res: string = "") {
|
||||||
const params = {
|
const params = {
|
||||||
endPoint: "",
|
endPoint: "",
|
||||||
@ -241,10 +306,18 @@ class IdeaBridge {
|
|||||||
case "getUserAccessKey":
|
case "getUserAccessKey":
|
||||||
JStoIdea.getUserAccessKey();
|
JStoIdea.getUserAccessKey();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "doCommand":
|
case "doCommand":
|
||||||
JStoIdea.etcCommand(message);
|
JStoIdea.etcCommand(message);
|
||||||
break;
|
break;
|
||||||
|
case "show_diff":
|
||||||
|
JStoIdea.viewDiff(message.content);
|
||||||
|
break;
|
||||||
|
case "updateSetting":
|
||||||
|
JStoIdea.updateSetting(message.value);
|
||||||
|
break;
|
||||||
|
case "doCommit":
|
||||||
|
JStoIdea.commit(message.content);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -165,6 +165,9 @@ const webviewConfig = {
|
|||||||
filename: "welcome.html",
|
filename: "welcome.html",
|
||||||
chunks: ["welcome"],
|
chunks: ["welcome"],
|
||||||
}),
|
}),
|
||||||
|
new DefinePlugin({
|
||||||
|
"process.env.platform": JSON.stringify("vscode"),
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user