From 828b7e26e3fb74a4f167f692804490bef7bb092e Mon Sep 17 00:00:00 2001 From: r3inbowari Date: Sat, 21 May 2022 17:47:20 +0800 Subject: [PATCH] add: sort packages --- CHANGELOG.md | 6 +++++- README.md | 2 +- package.json | 2 +- src/extension.ts | 2 +- src/mod-tree.ts | 12 ++++++++++-- src/utils.ts | 1 + 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7d3bf1..ffdda75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,5 +64,9 @@ [0.2.5] 1. add: one icon(.svg) from GoLand -2. add: classify packages for direct or indirect by icon color +2. add: classify packages for (in)direct by icon color 3. chore: fix typos + +[0.2.6] + +1. add: packages sorting diff --git a/README.md b/README.md index cc92024..d4f0c8c 100644 --- a/README.md +++ b/README.md @@ -61,5 +61,5 @@ Vscode Market: https://marketplace.visualstudio.com/items?itemName=r3inbowari.go --- -I'm appreciate if you could report an issues or pr. (๑•̀ㅂ•́)و✧ +I'm appreciate if you could report an issue or pr. (๑•̀ㅂ•́)و✧ **Enjoy!** diff --git a/package.json b/package.json index 02920de..bf4ebe8 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "Go Mod Explorer", "description": "Displays the External Library for the current go project in the Explorer.", "publisher": "r3inbowari", - "version": "0.2.5", + "version": "0.2.6", "repository": { "type": "git", "url": "https://github.com/r3inbowari/go-mod-explorer.git" diff --git a/src/extension.ts b/src/extension.ts index c1b4638..32e2fe9 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -12,7 +12,7 @@ export function activate(context: vscode.ExtensionContext) { mt.watch(); mt.update(); - // TODO: need fix: delay load after vscode-go + // TODO: need fixed: delay load after vscode-go try { execSync('go version'); } catch { diff --git a/src/mod-tree.ts b/src/mod-tree.ts index 984a7d7..a1fa32c 100644 --- a/src/mod-tree.ts +++ b/src/mod-tree.ts @@ -133,6 +133,7 @@ export class ModTree implements TreeDataProvider, TextDocumentContentPr if (this._goSDK !== undefined) { this._rootData?.push(this._goSDK); } + let packageList: ModItem[] = []; dat.forEach((res: ModObject, index: number) => { if (index !== 0 && res.Dir !== undefined) { let item = new ModItem(res, Uri.parse(res.Dir), res.Dir !== undefined); @@ -142,9 +143,16 @@ export class ModTree implements TreeDataProvider, TextDocumentContentPr res.Indirect ? 'module_indirect.svg' : 'module_direct.svg' ); item.hideHost(this._hideHost); - this._rootData?.push(item); + packageList.push(item); } }); + + this._rootData = this._rootData.concat( + packageList.sort(({ _modObject: l1 }, { _modObject: l2 }) => + l1?.Indirect === l2?.Indirect ? 0 : l1?.Indirect ? 1 : -1 + ) + ); + this.updateView(); this._loadingBar.hide(); } @@ -240,7 +248,7 @@ export class ModTree implements TreeDataProvider, TextDocumentContentPr public getChildren(element?: ModItem): ProviderResult { let ret: ModItem[] = []; if (element === undefined) { - return this._rootData.sort(({ isDirectory: s1 = false }, { isDirectory: s2 = false }) => Number(s2) - Number(s1)); + return this._rootData; } else { const result = readdirSync(resolvePath(element.resourceUri!)); result.forEach((fileName) => { diff --git a/src/utils.ts b/src/utils.ts index 0b0c0e3..73b5bba 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -88,6 +88,7 @@ export function queryGoSDK(): ModObject | null { Path: '', Version: '', SDK: true, + Indirect: false, }; }