From 32d084eb9e017adffc87a8e3dff7839424ce09a9 Mon Sep 17 00:00:00 2001 From: lilith-avatar-yenyuan <64084912+lilith-avatar-yenyuan@users.noreply.github.com> Date: Mon, 28 Jun 2021 14:55:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A0=E6=B3=95=E4=BB=8EBo?= =?UTF-8?q?om!Tree=E6=89=93=E5=BC=80=E6=96=87=E4=BB=B6=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/fileExplorer.ts | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/client/src/fileExplorer.ts b/client/src/fileExplorer.ts index 696d3c1..12912cc 100644 --- a/client/src/fileExplorer.ts +++ b/client/src/fileExplorer.ts @@ -231,6 +231,7 @@ export class BoomTreeDataProvider implements vscode.TreeDataProvider, vsc var result: [string, vscode.FileType][] = []; for (let i = 0; i < children.length; i++) { const child = children[i]; + const stat = await this._stat(path.join(uri.fsPath, child)); if (stat.type === vscode.FileType.File && this.isLua(child)) { result.push([child, stat.type]); @@ -243,6 +244,28 @@ export class BoomTreeDataProvider implements vscode.TreeDataProvider, vsc return Promise.resolve(result); } + readAllFiles(uri: vscode.Uri): [string, vscode.FileType, string][] | Thenable<[string, vscode.FileType, string][]> { + return this._readAllFiles(uri); + } + + async _readAllFiles(uri: vscode.Uri): Promise<[string, vscode.FileType, string][]> { + const children = await _.readdir(uri.fsPath); + var result: [string, vscode.FileType, string][] = []; + for (let i = 0; i < children.length; i++) { + const child = children[i]; + + const stat = await this._stat(path.join(uri.fsPath, child)); + if (stat.type === vscode.FileType.File && this.isLua(child)) { + result.push([child, stat.type, path.join(uri.fsPath, child)]); + } else if (stat.type === vscode.FileType.Directory) { + const dirUri = vscode.Uri.file(path.join(uri.fsPath, child)); + const fileInFolder = await this.readAllFiles(dirUri); + result = result.concat(fileInFolder); + } + } + return Promise.resolve(result); + } + createDirectory(uri: vscode.Uri): void | Thenable { return _.mkdir(uri.fsPath); } @@ -305,7 +328,7 @@ export class BoomTreeDataProvider implements vscode.TreeDataProvider, vsc ////* avatar methods ⬇️ // 解析结果,生成对应的树 - parseResult(result: [string, vscode.FileType][], folderName?: string): Entry[] { + parseResult(result: [string, vscode.FileType, string][], folderName?: string): Entry[] { let entries: Entry[] = []; entries = [{ label: folderName, uri: undefined, type: vscode.FileType.SymbolicLink, subEntry: [] }]; @@ -319,7 +342,7 @@ export class BoomTreeDataProvider implements vscode.TreeDataProvider, vsc for (let i = 0; i < paths.length; i++) { if (i === paths.length - 1) { - tempEntries = this.buildTree(tempEntries, paths[i], rs[0]); + tempEntries = this.buildTree(tempEntries, paths[i], rs[0], rs[2]); } else { tempEntries = this.buildTree(tempEntries, paths[i]); } @@ -330,7 +353,7 @@ export class BoomTreeDataProvider implements vscode.TreeDataProvider, vsc } // 生成结果树 - buildTree(entries: Entry[], link: string, filename?: string): Entry[] { + buildTree(entries: Entry[], link: string, filename?: string, fileUri?: string): Entry[] { for (let entry of entries) { if (entry.label === link) { return entry.subEntry; @@ -338,9 +361,11 @@ export class BoomTreeDataProvider implements vscode.TreeDataProvider, vsc } let newEntry: Entry; if (filename && vscode.workspace.workspaceFolders) { - // todo: 这里应该读取所有文件夹下的文件 const workspaceFolder = vscode.workspace.workspaceFolders.filter(folder => folder.uri.scheme === 'file')[0]; - const uri = vscode.Uri.file(path.join(workspaceFolder.uri.fsPath, filename)); + //const uri = vscode.Uri.file(path.join(workspaceFolder.uri.fsPath, filename)); + const uri = vscode.Uri.file(fileUri); + console.log(uri); + newEntry = { label: filename, uri: uri, @@ -382,7 +407,7 @@ export class BoomTreeDataProvider implements vscode.TreeDataProvider, vsc const workspaceFolders = vscode.workspace.workspaceFolders.filter(folder => folder.uri.scheme === 'file'); var entries = []; for (let i = 0; i < workspaceFolders.length; i++) { - const children = await this.readDirectory(workspaceFolders[i].uri); + const children = await this.readAllFiles(workspaceFolders[i].uri); children.sort((a, b) => { if (a[1] !== b[1]) { return a[0].localeCompare(b[0]);