From 51f647c11085a5df72204b66cabab51471216647 Mon Sep 17 00:00:00 2001 From: lilith-avatar-yenyuan <64084912+lilith-avatar-yenyuan@users.noreply.github.com> Date: Mon, 21 Jun 2021 11:52:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=B8=A4=E4=B8=AA=E5=9B=BE?= =?UTF-8?q?=E6=A0=87=EF=BC=8C=E7=8E=B0=E5=9C=A8=E8=AF=BB=E5=8F=96=E6=89=80?= =?UTF-8?q?=E6=9C=89=E6=96=87=E4=BB=B6=E5=A4=B9=E4=B8=8B=E7=9A=84=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B9=8B=E5=90=8E=E6=89=8D=E7=94=9F=E6=88=90=E6=A0=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/CustomEvent.svg | 1 + resources/Table.svg | 1 + src/fileExplorer.ts | 51 ++++++++++++++++++--------------------- 3 files changed, 26 insertions(+), 27 deletions(-) create mode 100644 resources/CustomEvent.svg create mode 100644 resources/Table.svg diff --git a/resources/CustomEvent.svg b/resources/CustomEvent.svg new file mode 100644 index 0000000..eda0b15 --- /dev/null +++ b/resources/CustomEvent.svg @@ -0,0 +1 @@ +custom-event \ No newline at end of file diff --git a/resources/Table.svg b/resources/Table.svg new file mode 100644 index 0000000..03b4efb --- /dev/null +++ b/resources/Table.svg @@ -0,0 +1 @@ +table \ No newline at end of file diff --git a/src/fileExplorer.ts b/src/fileExplorer.ts index f23a048..c9132e2 100644 --- a/src/fileExplorer.ts +++ b/src/fileExplorer.ts @@ -12,11 +12,6 @@ import * as rimraf from 'rimraf'; import { workspace } from 'vscode'; import EventEmitter = require('events'); -enum NodeType { - ModuleScript = 'modulescript', - Script = 'script' -} - //#region Utilities namespace _ { @@ -161,7 +156,6 @@ interface Entry { label: string, uri: vscode.Uri | undefined; type: vscode.FileType; - nodeType: NodeType | undefined; subEntry: Entry[]; } @@ -170,6 +164,7 @@ interface Entry { export class BoomTreeDataProvider implements vscode.TreeDataProvider, vscode.FileSystemProvider { private _onDidChangeFile: vscode.EventEmitter; + private luaFiles: any[] = []; private _onDidChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); readonly onDidChangeTreeData: vscode.Event = this._onDidChangeTreeData.event; private fsWathcer:vscode.FileSystemWatcher = vscode.workspace.createFileSystemWatcher("**/*.lua",false,false,false); @@ -182,16 +177,16 @@ export class BoomTreeDataProvider implements vscode.TreeDataProvider, vsc //Todo 这个也需要优化一下 bindWorkspaceEvent() { vscode.workspace.onDidChangeWorkspaceFolders(() => { - this.refresh() + this.refresh(); }); this.fsWathcer.onDidChange(()=>{ - this.refresh() + this.refresh(); }); this.fsWathcer.onDidCreate(()=>{ - this.refresh() + this.refresh(); }); this.fsWathcer.onDidDelete(()=>{ - this.refresh() + this.refresh(); }); } @@ -232,14 +227,21 @@ export class BoomTreeDataProvider implements vscode.TreeDataProvider, vsc async _readDirectory(uri: vscode.Uri): Promise<[string, vscode.FileType][]> { const children = await _.readdir(uri.fsPath); - - const result: [string, vscode.FileType][] = []; + console.log(uri); + + 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)); - result.push([child, stat.type]); + if (stat.type === vscode.FileType.File){ + result.push([child, stat.type]); + }else{ + const dirUri = vscode.Uri.file(path.join(uri.fsPath, child)); + const fileInFolder = await this.readDirectory(dirUri); + console.log(fileInFolder); + result = result.concat(fileInFolder); + } } - return Promise.resolve(result); } @@ -335,13 +337,13 @@ 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)); newEntry = { label: filename, uri: uri, type: vscode.FileType.File, - nodeType: this.getNodeType(filename), subEntry: [] } } else { @@ -349,7 +351,6 @@ export class BoomTreeDataProvider implements vscode.TreeDataProvider, vsc label: link, uri: undefined, type: vscode.FileType.SymbolicLink, - nodeType: undefined, subEntry: [] } } @@ -401,8 +402,8 @@ export class BoomTreeDataProvider implements vscode.TreeDataProvider, vsc ); treeItem.label = this.getNodePath(element.label)[this.getNodePath(element.label).length - 1] treeItem.iconPath = { - light: path.join(__filename, '..', '..', 'resources', element.nodeType + '.svg'), - dark: path.join(__filename, '..', '..', 'resources', element.nodeType + '.svg') + light: path.join(__filename, '..', '..', 'resources', this.getNodeType(element.label) + '.svg'), + dark: path.join(__filename, '..', '..', 'resources', this.getNodeType(element.label) + '.svg') } } else { treeItem = new vscode.TreeItem( @@ -433,16 +434,12 @@ export class BoomTreeDataProvider implements vscode.TreeDataProvider, vsc } } - getNodeType(fileName: string): NodeType | undefined { - const result = fileName.match(/(?<=\.)\w+(?=\.)/g) + getNodeType(fileName: string): string | undefined { + const result = fileName.match(/(?<=\.)\w+(?=\.)/g); if (result) { - if (result[0] === 'ModuleScript') { - return NodeType.ModuleScript - } else { - return NodeType.Script - } - + return result[0]; } + return; }