Skip to content

Commit

Permalink
feat(File node): Add support for opening file from file node (#36)
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

* fix(icon.png): Renames nested-tags-logo.png to icon.png

* perf(tag-tree-data-provider.ts): Scan files asynchronously (#24)

* Scan files asynchronously
* Only include markdown files

* docs(CHANGELOG.md): Automatically publish changes to CHANGELOG.md (#25)

Automatically publish changes to CHANGELOG.md

* feat(go to file): add file-open command to file nodes (#34)

- make treeDataProvider use vscode the findFiles function for searching
    - read files and scan for tags asynchronously

* build(recursive-readdir): Remove recursive-readdir as a dependency

* ci(package.json): Change run order of the plugins for semantic release
  • Loading branch information
blakedietz authored Mar 5, 2019
1 parent f14df26 commit f4eb2d6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 31 deletions.
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

0 comments on commit f4eb2d6

Please sign in to comment.