feat:实现读取本地文件的功能

This commit is contained in:
Roe-xin
2025-12-11 14:29:56 +08:00
parent 565f4afe46
commit 49b3e34101
5 changed files with 315 additions and 7 deletions

View File

@ -1,4 +1,5 @@
import * as vscode from "vscode";
import { readFileContent } from "./readFiles";
/**
* 处理用户消息
@ -16,6 +17,28 @@ export function handleUserMessage(panel: vscode.WebviewPanel, text: string) {
}, 500);
}
/**
* 处理文件读取请求
*/
export async function handleReadFile(
panel: vscode.WebviewPanel,
filePath: string
) {
try {
const content = await readFileContent(filePath);
panel.webview.postMessage({
command: "fileContent",
content: content,
filePath: filePath,
});
} catch (error) {
panel.webview.postMessage({
command: "fileError",
error: error instanceof Error ? error.message : "读取文件失败",
});
}
}
/**
* 获取模拟回复
*/