|
|
|
@ -1,5 +1,10 @@
|
|
|
|
let selectedCodeForContext = '';
|
|
|
|
let selectedCodeForContext = '';
|
|
|
|
let contextFilePath = ''; // 存储当前上下文文件路径
|
|
|
|
let contextFilePath = ''; // 存储当前上下文文件路径
|
|
|
|
|
|
|
|
let streamingMessageElement = null; // 用于存储当前流式消息的DOM元素
|
|
|
|
|
|
|
|
let streamingMessageContent = ''; // 用于存储当前流式消息的内容
|
|
|
|
|
|
|
|
let currentReader = null; // 用于存储当前流的reader,以便可以取消
|
|
|
|
|
|
|
|
let isRequestInProgress = false; // 标记是否有请求正在进行
|
|
|
|
|
|
|
|
let currentSessionHistory = []; // 存储当前会话历史
|
|
|
|
const vscode = acquireVsCodeApi();
|
|
|
|
const vscode = acquireVsCodeApi();
|
|
|
|
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
@ -7,18 +12,36 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
const userInput = document.getElementById('user-input');
|
|
|
|
const userInput = document.getElementById('user-input');
|
|
|
|
const chatBox = document.getElementById('chat-box');
|
|
|
|
const chatBox = document.getElementById('chat-box');
|
|
|
|
const loading = document.getElementById('loading');
|
|
|
|
const loading = document.getElementById('loading');
|
|
|
|
|
|
|
|
const sendBtn = document.getElementById('send-btn');
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化隐藏工作区
|
|
|
|
// 初始化显示工作区容器
|
|
|
|
const workspaceContainer = document.querySelector('.workspace-container');
|
|
|
|
const workspaceContainer = document.querySelector('.workspace-container');
|
|
|
|
if (workspaceContainer) {
|
|
|
|
if (workspaceContainer) {
|
|
|
|
workspaceContainer.style.display = 'none';
|
|
|
|
workspaceContainer.style.display = 'none';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
chatForm.addEventListener('submit', (e) => {
|
|
|
|
chatForm.addEventListener('submit', async (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.preventDefault();
|
|
|
|
const text = userInput.value.trim();
|
|
|
|
const text = userInput.value.trim();
|
|
|
|
if (!text) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果输入为空,不执行任何操作
|
|
|
|
|
|
|
|
if (!text && !isRequestInProgress) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果有请求正在进行,点击按钮将中断请求
|
|
|
|
|
|
|
|
if (isRequestInProgress) {
|
|
|
|
|
|
|
|
logToExtension("取消请求");
|
|
|
|
|
|
|
|
// 发送取消请求的消息到扩展
|
|
|
|
|
|
|
|
vscode.postMessage({
|
|
|
|
|
|
|
|
command: 'cancelRequest'
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 重置按钮状态
|
|
|
|
|
|
|
|
resetSendButton();
|
|
|
|
|
|
|
|
hideLoading();
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 发送消息
|
|
|
|
vscode.postMessage({
|
|
|
|
vscode.postMessage({
|
|
|
|
command: 'ask',
|
|
|
|
command: 'ask',
|
|
|
|
text,
|
|
|
|
text,
|
|
|
|
@ -26,11 +49,37 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
fileContentPath: contextFilePath // 添加文件路径
|
|
|
|
fileContentPath: contextFilePath // 添加文件路径
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// addMessage('user', text);
|
|
|
|
// 切换按钮为停止按钮
|
|
|
|
|
|
|
|
isRequestInProgress = true;
|
|
|
|
|
|
|
|
if (sendBtn) {
|
|
|
|
|
|
|
|
sendBtn.textContent = '停止';
|
|
|
|
|
|
|
|
sendBtn.classList.add('stop-button');
|
|
|
|
|
|
|
|
}
|
|
|
|
showLoading();
|
|
|
|
showLoading();
|
|
|
|
userInput.value = '';
|
|
|
|
userInput.value = '';
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 重置发送按钮为初始状态
|
|
|
|
|
|
|
|
function resetSendButton() {
|
|
|
|
|
|
|
|
isRequestInProgress = false;
|
|
|
|
|
|
|
|
const sendBtn = document.getElementById('send-btn');
|
|
|
|
|
|
|
|
if (sendBtn) {
|
|
|
|
|
|
|
|
sendBtn.textContent = '发送';
|
|
|
|
|
|
|
|
sendBtn.classList.remove('stop-button');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 显示加载状态
|
|
|
|
|
|
|
|
function showLoading() {
|
|
|
|
|
|
|
|
loading.classList.remove('hidden');
|
|
|
|
|
|
|
|
chatBox.scrollTop = chatBox.scrollHeight;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 隐藏加载状态
|
|
|
|
|
|
|
|
function hideLoading() {
|
|
|
|
|
|
|
|
loading.classList.add('hidden');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 判断内容是否为 Markdown(简单判断)
|
|
|
|
// 判断内容是否为 Markdown(简单判断)
|
|
|
|
function isMarkdown(content) {
|
|
|
|
function isMarkdown(content) {
|
|
|
|
if (!content || content.trim() === '') return false;
|
|
|
|
if (!content || content.trim() === '') return false;
|
|
|
|
@ -49,39 +98,45 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 处理添加消息
|
|
|
|
// 处理添加消息
|
|
|
|
function addMessage(role, content, codeDiff) {
|
|
|
|
function addMessage(role, content, codeDiffs) {
|
|
|
|
const msgDiv = document.createElement('div');
|
|
|
|
const msgDiv = document.createElement('div');
|
|
|
|
msgDiv.className = `message ${role}`;
|
|
|
|
msgDiv.className = `message ${role}`;
|
|
|
|
|
|
|
|
|
|
|
|
// 渲染内容
|
|
|
|
// 渲染内容
|
|
|
|
if (isMarkdown(content)) {
|
|
|
|
if (isMarkdown(content)) {
|
|
|
|
console.log("content:", content);
|
|
|
|
|
|
|
|
msgDiv.innerHTML = marked.parse(content);
|
|
|
|
msgDiv.innerHTML = marked.parse(content);
|
|
|
|
console.log("msgDiv.innerHTML:", msgDiv.innerHTML);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
const div = document.createElement('div');
|
|
|
|
const div = document.createElement('div');
|
|
|
|
div.textContent = content;
|
|
|
|
div.textContent = content;
|
|
|
|
msgDiv.appendChild(div);
|
|
|
|
msgDiv.appendChild(div);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 如果有代码差异,添加查看差异按钮
|
|
|
|
// 如果是AI消息且包含代码块,为每个代码块添加按钮
|
|
|
|
if (codeDiff) {
|
|
|
|
|
|
|
|
const diffButton = document.createElement('button');
|
|
|
|
|
|
|
|
diffButton.className = 'diff-button';
|
|
|
|
|
|
|
|
diffButton.textContent = '查看代码差异';
|
|
|
|
|
|
|
|
diffButton.onclick = () => showCodeDiff(codeDiff);
|
|
|
|
|
|
|
|
msgDiv.appendChild(diffButton);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果是AI消息且包含代码块,添加"创建文件"按钮
|
|
|
|
|
|
|
|
if (role === 'ai') {
|
|
|
|
if (role === 'ai') {
|
|
|
|
const codeBlocks = msgDiv.querySelectorAll('pre code');
|
|
|
|
const codeBlocks = msgDiv.querySelectorAll('pre code');
|
|
|
|
|
|
|
|
// 确保 codeDiffs 是数组
|
|
|
|
|
|
|
|
const diffs = Array.isArray(codeDiffs) ? codeDiffs : [];
|
|
|
|
|
|
|
|
|
|
|
|
codeBlocks.forEach((block, index) => {
|
|
|
|
codeBlocks.forEach((block, index) => {
|
|
|
|
|
|
|
|
// 为每个代码块添加"创建文件"按钮
|
|
|
|
const createFileButton = document.createElement('button');
|
|
|
|
const createFileButton = document.createElement('button');
|
|
|
|
createFileButton.className = 'create-file-button';
|
|
|
|
createFileButton.className = 'create-file-button';
|
|
|
|
createFileButton.textContent = `生成代码文件`;
|
|
|
|
createFileButton.textContent = `生成代码文件`;
|
|
|
|
createFileButton.onclick = () => createNewFileFromCode(block.textContent, index);
|
|
|
|
createFileButton.onclick = () => createNewFileFromCode(block.textContent, index);
|
|
|
|
msgDiv.appendChild(createFileButton);
|
|
|
|
|
|
|
|
|
|
|
|
// 将按钮插入到代码块后面
|
|
|
|
|
|
|
|
block.parentNode.after(createFileButton);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果有代码差异,也为每个代码块添加查看差异按钮
|
|
|
|
|
|
|
|
if (diffs[index]) {
|
|
|
|
|
|
|
|
const diffButton = document.createElement('button');
|
|
|
|
|
|
|
|
diffButton.className = 'diff-button';
|
|
|
|
|
|
|
|
diffButton.textContent = `查看代码差异`;
|
|
|
|
|
|
|
|
diffButton.onclick = () => showCodeDiff(diffs[index]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 将差异按钮插入到创建文件按钮后面
|
|
|
|
|
|
|
|
createFileButton.after(diffButton);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -97,6 +152,150 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
|
|
|
|
|
|
|
|
// 滚动到底部
|
|
|
|
// 滚动到底部
|
|
|
|
chatBox.scrollTop = chatBox.scrollHeight;
|
|
|
|
chatBox.scrollTop = chatBox.scrollHeight;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return msgDiv; // 返回创建的消息元素
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 开始流式传输
|
|
|
|
|
|
|
|
function startStreaming() {
|
|
|
|
|
|
|
|
// 创建一个新的AI消息元素
|
|
|
|
|
|
|
|
streamingMessageElement = document.createElement('div');
|
|
|
|
|
|
|
|
streamingMessageElement.className = 'message ai streaming';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 添加流式消息内容容器
|
|
|
|
|
|
|
|
const contentDiv = document.createElement('div');
|
|
|
|
|
|
|
|
contentDiv.className = 'streaming-content';
|
|
|
|
|
|
|
|
streamingMessageElement.appendChild(contentDiv);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 添加光标元素
|
|
|
|
|
|
|
|
const cursor = document.createElement('span');
|
|
|
|
|
|
|
|
cursor.className = 'streaming-cursor';
|
|
|
|
|
|
|
|
cursor.textContent = '▋';
|
|
|
|
|
|
|
|
streamingMessageElement.appendChild(cursor);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chatBox.appendChild(streamingMessageElement);
|
|
|
|
|
|
|
|
streamingMessageContent = '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 滚动到底部
|
|
|
|
|
|
|
|
chatBox.scrollTop = chatBox.scrollHeight;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 处理流式数据
|
|
|
|
|
|
|
|
function handleStreamData(data) {
|
|
|
|
|
|
|
|
if (!streamingMessageElement) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let processedData = data;
|
|
|
|
|
|
|
|
if (data.startsWith('data:')) {
|
|
|
|
|
|
|
|
// 移除data:前缀
|
|
|
|
|
|
|
|
processedData = data.replace(/^data:/, '');
|
|
|
|
|
|
|
|
// 逐个匹配换行符,当出现两个或更多连续换行符时删除多余的
|
|
|
|
|
|
|
|
processedData = processedData.replace(/^(\n{2,})/, (match) => {
|
|
|
|
|
|
|
|
// 删除所有连续的换行符
|
|
|
|
|
|
|
|
return '';
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 更新内容
|
|
|
|
|
|
|
|
streamingMessageContent += processedData;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 更新显示
|
|
|
|
|
|
|
|
const contentDiv = streamingMessageElement.querySelector('.streaming-content');
|
|
|
|
|
|
|
|
if (contentDiv) {
|
|
|
|
|
|
|
|
// 如果是Markdown内容,我们需要特殊处理
|
|
|
|
|
|
|
|
if (isMarkdown(streamingMessageContent)) {
|
|
|
|
|
|
|
|
contentDiv.innerHTML = marked.parse(streamingMessageContent);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
contentDiv.textContent = streamingMessageContent;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 高亮代码块
|
|
|
|
|
|
|
|
const codeBlocks = contentDiv.querySelectorAll('pre code');
|
|
|
|
|
|
|
|
codeBlocks.forEach(block => {
|
|
|
|
|
|
|
|
if (hljs && !block.dataset.highlighted) {
|
|
|
|
|
|
|
|
hljs.highlightElement(block);
|
|
|
|
|
|
|
|
block.dataset.highlighted = 'true';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 滚动到底部
|
|
|
|
|
|
|
|
chatBox.scrollTop = chatBox.scrollHeight;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 结束流式传输
|
|
|
|
|
|
|
|
function endStreaming(content, codeDiffs = null) {
|
|
|
|
|
|
|
|
if (streamingMessageElement) {
|
|
|
|
|
|
|
|
// 移除流式传输类和光标
|
|
|
|
|
|
|
|
streamingMessageElement.classList.remove('streaming');
|
|
|
|
|
|
|
|
const cursor = streamingMessageElement.querySelector('.streaming-cursor');
|
|
|
|
|
|
|
|
if (cursor) {
|
|
|
|
|
|
|
|
cursor.remove();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果是AI消息且包含代码块,为每个代码块添加按钮
|
|
|
|
|
|
|
|
if (streamingMessageElement.classList.contains('ai')) {
|
|
|
|
|
|
|
|
const codeBlocks = streamingMessageElement.querySelectorAll('pre code');
|
|
|
|
|
|
|
|
codeBlocks.forEach((block, index) => {
|
|
|
|
|
|
|
|
// 为每个代码块添加"创建文件"按钮
|
|
|
|
|
|
|
|
const createFileButton = document.createElement('button');
|
|
|
|
|
|
|
|
createFileButton.className = 'create-file-button';
|
|
|
|
|
|
|
|
createFileButton.textContent = `生成代码文件`;
|
|
|
|
|
|
|
|
createFileButton.onclick = () => createNewFileFromCode(block.textContent, index);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 将按钮插入到代码块后面
|
|
|
|
|
|
|
|
block.parentNode.after(createFileButton);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果有代码差异,也为每个代码块添加查看差异按钮
|
|
|
|
|
|
|
|
// codeDiffs是一个数组,每个元素对应一个代码块的差异信息
|
|
|
|
|
|
|
|
if (codeDiffs && codeDiffs[index]) {
|
|
|
|
|
|
|
|
const diffButton = document.createElement('button');
|
|
|
|
|
|
|
|
diffButton.className = 'diff-button';
|
|
|
|
|
|
|
|
diffButton.textContent = `查看代码差异`;
|
|
|
|
|
|
|
|
diffButton.onclick = () => showCodeDiff(codeDiffs[index]);
|
|
|
|
|
|
|
|
// 将差异按钮插入到创建文件按钮后面
|
|
|
|
|
|
|
|
createFileButton.after(diffButton);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 高亮代码块
|
|
|
|
|
|
|
|
const codeBlocks = streamingMessageElement.querySelectorAll('pre code');
|
|
|
|
|
|
|
|
codeBlocks.forEach(block => {
|
|
|
|
|
|
|
|
if (hljs) {
|
|
|
|
|
|
|
|
hljs.highlightElement(block);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
streamingMessageElement = null;
|
|
|
|
|
|
|
|
streamingMessageContent = '';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 重置发送按钮状态
|
|
|
|
|
|
|
|
resetSendButton();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 保存消息到历史记录
|
|
|
|
|
|
|
|
currentSessionHistory.push({role: 'assistant', content: content});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hideLoading();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 处理请求取消
|
|
|
|
|
|
|
|
function handleRequestCancelled() {
|
|
|
|
|
|
|
|
// 重置发送按钮
|
|
|
|
|
|
|
|
resetSendButton();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果有正在流式传输的消息,结束它
|
|
|
|
|
|
|
|
if (streamingMessageElement) {
|
|
|
|
|
|
|
|
streamingMessageElement.classList.remove('streaming');
|
|
|
|
|
|
|
|
const cursor = streamingMessageElement.querySelector('.streaming-cursor');
|
|
|
|
|
|
|
|
if (cursor) {
|
|
|
|
|
|
|
|
cursor.remove();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
streamingMessageElement = null;
|
|
|
|
|
|
|
|
streamingMessageContent = '';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hideLoading();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 显示代码差异
|
|
|
|
// 显示代码差异
|
|
|
|
@ -184,14 +383,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function showLoading() {
|
|
|
|
|
|
|
|
loading.classList.remove('hidden');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function hideLoading() {
|
|
|
|
|
|
|
|
loading.classList.add('hidden');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 更新工作区文件列表
|
|
|
|
// 更新工作区文件列表
|
|
|
|
function updateWorkspaceFiles(files) {
|
|
|
|
function updateWorkspaceFiles(files) {
|
|
|
|
const workspaceContainer = document.querySelector('.workspace-container');
|
|
|
|
const workspaceContainer = document.querySelector('.workspace-container');
|
|
|
|
@ -253,9 +444,20 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener('message', (event) => {
|
|
|
|
window.addEventListener('message', (event) => {
|
|
|
|
const message = event.data;
|
|
|
|
const message = event.data;
|
|
|
|
console.log(message)
|
|
|
|
|
|
|
|
if (message.command === 'addMessage') {
|
|
|
|
if (message.command === 'addMessage') {
|
|
|
|
addMessage(message.role, message.content, message.codeDiff);
|
|
|
|
addMessage(message.role, message.content, message.codeDiff);
|
|
|
|
|
|
|
|
} else if (message.command === 'startStream') {
|
|
|
|
|
|
|
|
// 开始流式传输
|
|
|
|
|
|
|
|
startStreaming();
|
|
|
|
|
|
|
|
} else if (message.command === 'streamData') {
|
|
|
|
|
|
|
|
// 处理流式数据
|
|
|
|
|
|
|
|
handleStreamData(message.data);
|
|
|
|
|
|
|
|
} else if (message.command === 'endStream') {
|
|
|
|
|
|
|
|
// 结束流式传输
|
|
|
|
|
|
|
|
endStreaming(message.content, message.codeDiffs);
|
|
|
|
|
|
|
|
} else if (message.command === 'requestCancelled') {
|
|
|
|
|
|
|
|
// 请求被取消
|
|
|
|
|
|
|
|
handleRequestCancelled();
|
|
|
|
} else if (message.command === 'hideLoading') {
|
|
|
|
} else if (message.command === 'hideLoading') {
|
|
|
|
hideLoading();
|
|
|
|
hideLoading();
|
|
|
|
} else if (message.command === 'addToInput') {
|
|
|
|
} else if (message.command === 'addToInput') {
|
|
|
|
@ -339,15 +541,21 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 打开文件浏览器
|
|
|
|
// 打开文件浏览器
|
|
|
|
document.getElementById('select-context-btn').addEventListener('click', () => {
|
|
|
|
const selectContextBtn = document.getElementById('select-context-btn');
|
|
|
|
|
|
|
|
if (selectContextBtn) {
|
|
|
|
|
|
|
|
selectContextBtn.addEventListener('click', () => {
|
|
|
|
// 显示模态框
|
|
|
|
// 显示模态框
|
|
|
|
document.getElementById('file-browser-modal').classList.remove('hidden');
|
|
|
|
const fileBrowserModal = document.getElementById('file-browser-modal');
|
|
|
|
|
|
|
|
if (fileBrowserModal) {
|
|
|
|
|
|
|
|
fileBrowserModal.classList.remove('hidden');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 请求文件列表
|
|
|
|
// 请求文件列表
|
|
|
|
vscode.postMessage({
|
|
|
|
vscode.postMessage({
|
|
|
|
command: 'getFileList'
|
|
|
|
command: 'getFileList'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
// 关闭模态框
|
|
|
|
// 关闭模态框
|
|
|
|
document.getElementById('close-modal').addEventListener('click', () => {
|
|
|
|
document.getElementById('close-modal').addEventListener('click', () => {
|
|
|
|
document.getElementById('file-browser-modal').classList.add('hidden');
|
|
|
|
document.getElementById('file-browser-modal').classList.add('hidden');
|
|
|
|
@ -392,6 +600,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
document.getElementById('diff-modal').classList.add('hidden');
|
|
|
|
document.getElementById('diff-modal').classList.add('hidden');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 从代码创建新文件
|
|
|
|
// 从代码创建新文件
|
|
|
|
function createNewFileFromCode(codeContent, index) {
|
|
|
|
function createNewFileFromCode(codeContent, index) {
|
|
|
|
// 简单的语言检测
|
|
|
|
// 简单的语言检测
|
|
|
|
@ -407,6 +616,14 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
language: language
|
|
|
|
language: language
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function logToExtension(...args) {
|
|
|
|
|
|
|
|
vscode.postMessage({
|
|
|
|
|
|
|
|
command: 'log',
|
|
|
|
|
|
|
|
data: args
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 简单的语言检测
|
|
|
|
// 简单的语言检测
|
|
|
|
function detectLanguage(code) {
|
|
|
|
function detectLanguage(code) {
|
|
|
|
|