fix: file_list 工具现在同时返回文件和目录

This commit is contained in:
XiaoFeng
2025-12-26 15:40:40 +08:00
parent 9bfa774336
commit 5cb68652f9

View File

@ -94,6 +94,13 @@ export async function readDirectory(
const results = []; const results = [];
for (const [fileName, fileType] of entries) { for (const [fileName, fileType] of entries) {
// 处理目录
if (fileType === vscode.FileType.Directory) {
results.push({ path: fileName + '/', content: '[目录]', isDirectory: true });
continue;
}
// 处理文件
if (fileType === vscode.FileType.File) { if (fileType === vscode.FileType.File) {
// 如果指定了扩展名过滤 // 如果指定了扩展名过滤
if (extensions && extensions.length > 0) { if (extensions && extensions.length > 0) {
@ -108,7 +115,7 @@ export async function readDirectory(
const fileUri = vscode.Uri.file(filePath); const fileUri = vscode.Uri.file(filePath);
const contentBytes = await vscode.workspace.fs.readFile(fileUri); const contentBytes = await vscode.workspace.fs.readFile(fileUri);
const content = Buffer.from(contentBytes).toString("utf-8"); const content = Buffer.from(contentBytes).toString("utf-8");
results.push({ path: fileName, content }); results.push({ path: fileName, content, isDirectory: false });
} catch (error) { } catch (error) {
// 跳过无法读取的文件 // 跳过无法读取的文件
continue; continue;