Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
"vscode": "^1.1.25"
},
"dependencies": {
"debounce": "^1.2.0",
"recursive-readdir": "2.2.2"
"debounce": "^1.2.0"
},
"activationEvents": [
"onView:tagTreeView"
Expand Down Expand Up @@ -94,14 +93,20 @@
},
"release": {
"plugins": [
["semantic-release-vsce", {
[
"semantic-release-vsce",
{
"path": "@semantic-release/github",
"assets": "vscode-nested-tags.vsix"
}],
["@semantic-release/changelog", {
"changelogFile": "./CHANGELOG.md"
}],
"@semantic-release/github"
}
],
"@semantic-release/github",
[
"@semantic-release/changelog",
{
"changelogFile": "./CHANGELOG.md"
}
]
]
}
}
50 changes: 27 additions & 23 deletions src/tag-tree-data-provider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { debounce } from "debounce";
import * as fs from "fs";
import * as recursiveReadDir from "recursive-readdir";
import * as vscode from "vscode";
import { setsAreEqual } from "./sets";
import { FileNode, fileNodeSort } from "./tag-tree/file-node";
Expand Down Expand Up @@ -35,24 +34,20 @@ class TagTreeDataProvider

this.tagTree = new TagTree();

/* Add all files in the current workspace folder to the tag tree
* @ts-ignore
/**
* Add all files in the current workspace folder to the tag tree
*/
if (vscode.workspace.workspaceFolders!.length > 0) {
vscode.workspace.workspaceFolders!.forEach(workspaceFolder => {
const { fsPath } = workspaceFolder.uri;
recursiveReadDir(fsPath, ["!*.md"], (error: any, files: any) => {
for (const filePath of files) {
const fileInfo = this.getTagsFromFileOnFileSystem(filePath);
if (fileInfo.tags.size > 0) {
this.tagTree.addFile(fileInfo.filePath, [...fileInfo.tags], fileInfo.filePath);
}
}

this._onDidChangeTreeData.fire();
});
});
}
(async () => {
const uris = await vscode.workspace.findFiles("**/*.md");
const infos = await Promise.all(
uris.map(uri => this.getTagsFromFileOnFileSystem(uri.fsPath))
);
infos
.filter(info => info.tags.size > 0)
.forEach(info => this.tagTree.addFile(info.filePath, [...info.tags], info.filePath));

this._onDidChangeTreeData.fire();
})();
}

/**
Expand Down Expand Up @@ -102,7 +97,15 @@ class TagTreeDataProvider
? vscode.TreeItemCollapsibleState.None
: vscode.TreeItemCollapsibleState.Collapsed;

return new vscode.TreeItem(displayName, collapsibleState);
const result = new vscode.TreeItem(displayName, collapsibleState);
if (isFile) {
result.command = {
arguments: [ vscode.Uri.file(tagTreeNode.filePath) ],
command: "vscode.open",
title: "Jump to tag reference"
};
}
return result;
}

/**
Expand All @@ -111,10 +114,10 @@ class TagTreeDataProvider
* any changes to tags for a document before saving.
* @param changeEvent
*/
private onWillSaveTextDocument(changeEvent: vscode.TextDocumentWillSaveEvent) {
private async onWillSaveTextDocument(changeEvent: vscode.TextDocumentWillSaveEvent): Promise<void> {
if (changeEvent.document.isDirty && changeEvent.document.languageId === "markdown") {
const filePath = changeEvent.document.fileName;
const fileInfo = this.getTagsFromFileOnFileSystem(filePath);
const fileInfo = await this.getTagsFromFileOnFileSystem(filePath);
const tagsInTreeForFile = this.tagTree.getTagsForFile(filePath);
this.updateTreeForFile(filePath, tagsInTreeForFile, fileInfo.tags);
}
Expand Down Expand Up @@ -202,8 +205,9 @@ class TagTreeDataProvider
*
* @param filePath The local filesystem path
*/
private getTagsFromFileOnFileSystem(filePath: string): IFileInfo {
return this.getTagsFromFileText(fs.readFileSync(filePath).toString(), filePath);
private async getTagsFromFileOnFileSystem(filePath: string): Promise<IFileInfo> {
const buffer = await fs.promises.readFile(filePath);
return this.getTagsFromFileText(buffer.toString(), filePath);
}
}

Expand Down