|
|
|
|
@ -82,7 +82,12 @@ function openWebview(
|
|
|
|
|
vscode.Uri.file(path.join(extensionPath, 'media', 'webview', 'styles', 'atom-one-dark.css'))
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
panel.webview.html = getWebviewContent(styleUri, scriptUri,highlightScriptUri,highlightStyleUri);
|
|
|
|
|
const markedScriptUri = panel.webview.asWebviewUri(
|
|
|
|
|
vscode.Uri.file(path.join(context.extensionPath, 'media', 'webview', 'marked.min.js'))
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
panel.webview.html = getWebviewContent(styleUri, scriptUri,highlightScriptUri,highlightStyleUri,markedScriptUri);
|
|
|
|
|
|
|
|
|
|
panel.webview.onDidReceiveMessage(
|
|
|
|
|
async (message) => {
|
|
|
|
|
@ -101,7 +106,6 @@ function openWebview(
|
|
|
|
|
const response = await callQwenAPI(question, history, fileContent, context);
|
|
|
|
|
console.log("response:",response)
|
|
|
|
|
const aiMessage = response.choices[0]?.message?.content || '未获取到回复';
|
|
|
|
|
console.log("aiMessage:",aiMessage)
|
|
|
|
|
|
|
|
|
|
const updatedHistory = [...newHistory, { role: 'assistant', content: aiMessage }];
|
|
|
|
|
globalState.update('chatHistory', updatedHistory);
|
|
|
|
|
@ -132,7 +136,7 @@ async function callQwenAPI(
|
|
|
|
|
const messages = [
|
|
|
|
|
{
|
|
|
|
|
role: 'system',
|
|
|
|
|
content: `你是一个代码助手,请根据当前文件内容和历史对话回答问题。`
|
|
|
|
|
content: `你是一个代码助手,请根据当前文件内容和历史对话回答问题。请使用中文回答。`
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
role: 'user',
|
|
|
|
|
@ -170,7 +174,7 @@ async function callQwenAPI(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getWebviewContent(styleUri: vscode.Uri, scriptUri: vscode.Uri,highlightScriptUri:vscode.Uri,highlightStyleUri:vscode.Uri): string {
|
|
|
|
|
function getWebviewContent(styleUri: vscode.Uri, scriptUri: vscode.Uri,highlightScriptUri:vscode.Uri,highlightStyleUri:vscode.Uri,markedScriptUri:vscode.Uri): string {
|
|
|
|
|
return `
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html lang="en">
|
|
|
|
|
@ -194,12 +198,7 @@ function getWebviewContent(styleUri: vscode.Uri, scriptUri: vscode.Uri,highlight
|
|
|
|
|
</div>
|
|
|
|
|
<script src="${scriptUri}"></script>
|
|
|
|
|
<script src="${highlightScriptUri}"></script>
|
|
|
|
|
<!-- 启用自动高亮 -->
|
|
|
|
|
<script>
|
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
|
hljs.highlightAll(); // 自动高亮所有代码块
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
<script src="${markedScriptUri}"></script>
|
|
|
|
|
</body>
|
|
|
|
|
</html>`;
|
|
|
|
|
}
|