Skip to content

Commit

Permalink
fix(tag-tree): Fix removal of parent nodes (#39) (#40)
Browse files Browse the repository at this point in the history
* fix(tag-tree): Fix removal of parent nodes (#39)

When renaming a tag with hierarchy, if the root node was renamed, when
removing the path to the node, parents would not be properly cleaned up.

Closes #37

* build(package.json): Add semantic release and release notes generator
  • Loading branch information
blakedietz authored Mar 28, 2019
1 parent f4eb2d6 commit 7949982
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "npm: watch"
"preLaunchTask": "watch"
}
]
}
5 changes: 5 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
"kind": "build",
"isDefault": true
}
},
{
"type": "npm",
"script": "build:watch",
"problemMatcher": []
}
]
}
46 changes: 30 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 26 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"test": "jest --passWithNoTests",
"test:watch": "jest --watch --passWithNoTests",
"vscode:prepublish": "npm run build",
"watch": "tsc -watch -p ./"
"watch": "npm run build:watch"
},
"devDependencies": {
"@semantic-release/changelog": "^3.0.2",
Expand All @@ -32,6 +32,7 @@
"@semantic-release/git": "^7.0.8",
"@semantic-release/github": "^5.2.9",
"@semantic-release/npm": "^5.1.4",
"@semantic-release/release-notes-generator": "^7.1.4",
"@types/debounce": "^1.2.0",
"@types/jest": "^23.3.12",
"@types/node": "^10.12.18",
Expand Down Expand Up @@ -93,18 +94,37 @@
},
"release": {
"plugins": [
[
"@semantic-release/release-notes-generator",
{
"preset": "angular",
"parserOpts": {
"noteKeywords": [
"BREAKING CHANGE",
"BREAKING CHANGES",
"BREAKING"
]
},
"writerOpts": {
"commitsSort": [
"subject",
"scope"
]
}
}
],
[
"semantic-release-vsce",
"@semantic-release/changelog",
{
"path": "@semantic-release/github",
"assets": "vscode-nested-tags.vsix"
"changelogFile": "./CHANGELOG.md"
}
],
"@semantic-release/github",
[
"@semantic-release/changelog",
"semantic-release-vsce",
{
"changelogFile": "./CHANGELOG.md"
"path": "@semantic-release/github",
"assets": "vscode-nested-tags.vsix"
}
]
]
Expand Down
1 change: 1 addition & 0 deletions src/tag-tree-data-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface IFileInfo {

class TagTreeDataProvider
implements vscode.TreeDataProvider<TagNode | FileNode> {

private tagTree: TagTree;
// Responsible for notifying the TreeDataProvider to update for the specified element in tagTree
private _onDidChangeTreeData: vscode.EventEmitter< TagNode | FileNode | null> = new vscode.EventEmitter<TagNode | FileNode | null>();
Expand Down
20 changes: 2 additions & 18 deletions src/tag-tree/__snapshots__/tag-tree.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -395,15 +395,7 @@ exports[`TagTree deleteFile Delete file under shared tag with empty node 1`] = `
tags: [ 'hello' ] } },
pathToNode: 'hello',
tag: 'hello',
tags:
Map {
'world' => TagNode {
parent: [Circular],
displayName: 'world',
files: Map {},
pathToNode: 'hello/world',
tag: 'world',
tags: Map {} } } } } },
tags: Map {} } } },
fileIndex:
Map {
'|Users|test|bar.md' => [ TagNode {
Expand All @@ -426,15 +418,7 @@ exports[`TagTree deleteFile Delete file under shared tag with empty node 1`] = `
tags: [ 'hello' ] } },
pathToNode: 'hello',
tag: 'hello',
tags:
Map {
'world' => TagNode {
parent: [Circular],
displayName: 'world',
files: Map {},
pathToNode: 'hello/world',
tag: 'world',
tags: Map {} } } } ] } }"
tags: Map {} } ] } }"
`;

exports[`TagTree deleteFile Delete node under root 1`] = `
Expand Down
13 changes: 13 additions & 0 deletions src/tag-tree/tag-tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ describe("TagTree", () => {
tagTree.deleteFile(filePath);
expect(createDeepSnapshot(tagTree)).toMatchSnapshot();
});

test("Move tag tree from one top level node to another", () => {
const tagTree = new TagTree();
const filePath = "/Users/test/foo.md";
tagTree.addFile(filePath, ["hello/world"], "foo.md");
tagTree.deleteFile(filePath);
tagTree.addFile(filePath, ["goodbye/world"], "foo.md");
const tag = tagTree.root.getTag("hello");
const renamedTag = tagTree.root.getTag("goodbye");

expect(tag).toBeUndefined();
expect(renamedTag).toBeDefined();
});
});
describe("getTagsForFile", () => {
test("Retrieves all tags for a file", () => {
Expand Down
4 changes: 3 additions & 1 deletion src/tag-tree/tag-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ class TagTree {

while (currentNode!.files.size === 0 && currentNode!.tags.size === 0) {
const { parent } = currentNode;
// We're not at the root of the tree yet
if (parent !== null) {
parent!.deleteTag(node.tag);
parent!.deleteTag(currentNode.tag);
// @ts-ignore
currentNode = parent;
// At this point we've hit the root of the tree
} else {
break;
}
Expand Down

0 comments on commit 7949982

Please sign in to comment.