fix: file_list 工具现在同时返回文件和目录
This commit is contained in:
@ -94,6 +94,13 @@ export async function readDirectory(
|
||||
const results = [];
|
||||
|
||||
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 (extensions && extensions.length > 0) {
|
||||
@ -108,7 +115,7 @@ export async function readDirectory(
|
||||
const fileUri = vscode.Uri.file(filePath);
|
||||
const contentBytes = await vscode.workspace.fs.readFile(fileUri);
|
||||
const content = Buffer.from(contentBytes).toString("utf-8");
|
||||
results.push({ path: fileName, content });
|
||||
results.push({ path: fileName, content, isDirectory: false });
|
||||
} catch (error) {
|
||||
// 跳过无法读取的文件
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user