Skip to content

Commit

Permalink
上传两个图标,现在读取所有文件夹下的文件之后才生成树
Browse files Browse the repository at this point in the history
  • Loading branch information
free-yenyuan committed Jun 21, 2021
1 parent 871df82 commit 51f647c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
1 change: 1 addition & 0 deletions resources/CustomEvent.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources/Table.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 24 additions & 27 deletions src/fileExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 _ {
Expand Down Expand Up @@ -161,7 +156,6 @@ interface Entry {
label: string,
uri: vscode.Uri | undefined;
type: vscode.FileType;
nodeType: NodeType | undefined;
subEntry: Entry[];
}

Expand All @@ -170,6 +164,7 @@ interface Entry {
export class BoomTreeDataProvider implements vscode.TreeDataProvider<Entry>, vscode.FileSystemProvider {

private _onDidChangeFile: vscode.EventEmitter<vscode.FileChangeEvent[]>;
private luaFiles: any[] = [];
private _onDidChangeTreeData: vscode.EventEmitter<any> = new vscode.EventEmitter<any>();
readonly onDidChangeTreeData: vscode.Event<any> = this._onDidChangeTreeData.event;
private fsWathcer:vscode.FileSystemWatcher = vscode.workspace.createFileSystemWatcher("**/*.lua",false,false,false);
Expand All @@ -182,16 +177,16 @@ export class BoomTreeDataProvider implements vscode.TreeDataProvider<Entry>, 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();
});
}

Expand Down Expand Up @@ -232,14 +227,21 @@ export class BoomTreeDataProvider implements vscode.TreeDataProvider<Entry>, 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);
}

Expand Down Expand Up @@ -335,21 +337,20 @@ export class BoomTreeDataProvider implements vscode.TreeDataProvider<Entry>, 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 {
newEntry = {
label: link,
uri: undefined,
type: vscode.FileType.SymbolicLink,
nodeType: undefined,
subEntry: []
}
}
Expand Down Expand Up @@ -401,8 +402,8 @@ export class BoomTreeDataProvider implements vscode.TreeDataProvider<Entry>, 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(
Expand Down Expand Up @@ -433,16 +434,12 @@ export class BoomTreeDataProvider implements vscode.TreeDataProvider<Entry>, 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;
}


Expand Down

0 comments on commit 51f647c

Please sign in to comment.