Skip to content

Commit

Permalink
feat(Sorting): Sort the tag tree by tag and file (#22)
Browse files Browse the repository at this point in the history
* docs(vscode-logo): Adds logo for extension (#20)

* docs(logo): Add logo

* build(config.yml): Add release branch

* feat(Sorting): Sort the tag tree by tag and file (#21)

Sort the tag tree alphbetically first by tags, then by file.

Resolves #11

* style(tag-tree-data-provider.ts): Add some space in the import statement

* ci(config.yml): Add develop branch to trigger ci
  • Loading branch information
blakedietz authored Feb 9, 2019
1 parent fed680f commit 70eb1ec
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 15 deletions.
17 changes: 12 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details

version: 2
jobs:
build-deploy-release-branches:
Expand Down Expand Up @@ -36,7 +32,7 @@ jobs:
- restore_cache:
key: project-name-{{ .Branch }}-{{ checksum "package.json" }}
- run:
name: Install node.js Dependencies with yarn
name: Install node.js Dependencies with npm
command: npm i
- save_cache:
key: project-name-{{ .Branch }}-{{ checksum "package.json" }}
Expand Down Expand Up @@ -69,6 +65,17 @@ workflows:
filters:
branches:
only:
- /build.*/
- /chore.*/
- /ci.*/
- /develop.*/
- /docs.*/
- /experiment.*/
- /feature.*/
- /fix.*/
- /perf.*/
- /test.*/
- /style.*/
- /refactor.*/
- /release.*/
- /revert.*/
3 changes: 2 additions & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ vsc-extension-quickstart.md
**/tsconfig.json
**/tslint.json
**/*.map
**/*.ts
**/*.ts
**/*.psd
Binary file added images/nested-tags-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/nested-tags-logo.psd
Binary file not shown.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
]
}
},
"icon": "images/icon.png",
"galleryBanner": {
"color": "#073642",
"theme": "dark"
},
"publisher": "vscode-nested-tags",
"config": {
"loglevel": "verbose",
Expand Down
26 changes: 19 additions & 7 deletions src/tag-tree-data-provider.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {debounce} from "debounce";
import { debounce } from "debounce";
import * as fs from "fs";
import * as path from "path";
import * as vscode from "vscode";
import { setsAreEqual } from "./sets";
import { FileNode } from "./tag-tree/file-node";
import { TagNode } from "./tag-tree/tag-node";
import { FileNode, fileNodeSort } from "./tag-tree/file-node";
import { TagNode, tagNodeSort } from "./tag-tree/tag-node";
import { TagTree } from "./tag-tree/tag-tree";

interface IFileInfo {
Expand All @@ -31,6 +31,7 @@ class TagTreeDataProvider
// });

// Register the extension to events of interest
// Debounce to improve performance. Otherwise a file read would occur during each of the user's change to the document.
vscode.workspace.onDidChangeTextDocument(debounce((e: vscode.TextDocumentChangeEvent) => this.onDocumentChanged(e), 500));
vscode.workspace.onWillSaveTextDocument((e) => {
this.onWillSaveTextDocument(e);
Expand Down Expand Up @@ -67,12 +68,23 @@ class TagTreeDataProvider
if (element instanceof FileNode) {
return [];
} else if (element === undefined) {
return [
...this.tagTree.root.tags.values(),
...this.tagTree.root.files.values()
// Convert the tags and files sets to arrays, then sort the arrays add tags first, then files
const children = [
...[...this.tagTree.root.tags.values()]
.sort(tagNodeSort),
...[...this.tagTree.root.files.values()]
.sort(fileNodeSort)
];

return children;
} else {
return [...element.tags.values(), ...element.files.values()];
// Convert the tags and files sets to arrays, then sort the arrays add tags first, then files
const children = [
...[...element.tags.values()].sort(tagNodeSort),
...[...element.files.values()].sort(fileNodeSort)
];

return children;
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/tag-tree/file-node.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { fileNodeSort, FileNode } from "./file-node";

describe(fileNodeSort.name, () => {
test("Sorts in ascending order", () => {
const fileNodeA = new FileNode("a", "a", "a", [], "a");
const fileNodeB = new FileNode("b", "b", "b", [], "b");

expect(fileNodeSort(fileNodeA, fileNodeB)).toEqual(-1);
expect(fileNodeSort(fileNodeB, fileNodeA)).toEqual(1);
expect(fileNodeSort(fileNodeA, fileNodeA)).toEqual(0);
});
});
16 changes: 15 additions & 1 deletion src/tag-tree/file-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,18 @@ class FileNode {
}
}

export { FileNode };
interface IFileNodeSort {
(fileA: FileNode, fileB: FileNode): number;
}

const fileNodeSort: IFileNodeSort = (fileA: FileNode, fileB: FileNode) => {
if (fileA.filePath < fileB.filePath) {
return -1;
} else if (fileA.filePath > fileB.filePath) {
return 1;
} else {
return 0;
}
};

export { FileNode, fileNodeSort };
12 changes: 12 additions & 0 deletions src/tag-tree/tag-node.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { tagNodeSort, TagNode } from "./tag-node";

describe(tagNodeSort.name, () => {
test("Sorts in ascending order", () => {
const tagNodeA = new TagNode(null, "a", "");
const tagNodeB = new TagNode(null, "b", "");

expect(tagNodeSort(tagNodeA, tagNodeB)).toEqual(-1);
expect(tagNodeSort(tagNodeB, tagNodeA)).toEqual(1);
expect(tagNodeSort(tagNodeA, tagNodeA)).toEqual(0);
});
});
15 changes: 14 additions & 1 deletion src/tag-tree/tag-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,17 @@ class TagNode {
}
}

export { TagNode };
interface ITagNodeSort {
(tagA: TagNode, tagB: TagNode): number;
}
const tagNodeSort: ITagNodeSort = (tagA: TagNode, tagB: TagNode) => {
if (tagA.tag < tagB.tag) {
return -1;
} else if (tagA.tag > tagB.tag) {
return 1;
} else {
return 0;
}
};

export { TagNode, tagNodeSort };

0 comments on commit 70eb1ec

Please sign in to comment.