@@ -6,6 +6,8 @@ import { FileNode, fileNodeSort } from "./tag-tree/file-node";
66import { TagNode , tagNodeSort } from "./tag-tree/tag-node" ;
77import { TagTree } from "./tag-tree/tag-tree" ;
88import * as grayMatter from "gray-matter" ;
9+ import { Uri } from "vscode" ;
10+ import * as path from "path" ;
911
1012interface IFileInfo {
1113 tags : Set < string > ;
@@ -46,7 +48,11 @@ class TagTreeDataProvider
4648 ) ;
4749 infos
4850 . filter ( info => info . tags . size > 0 )
49- . forEach ( info => this . tagTree . addFile ( info . filePath , [ ...info . tags ] , info . filePath ) ) ;
51+ . forEach ( info => {
52+ const displayName = this . getPathRelativeToWorkspaceFolder ( Uri . file ( info . filePath ) ) ;
53+
54+ this . tagTree . addFile ( info . filePath , [ ...info . tags ] , displayName ) ;
55+ } ) ;
5056
5157 this . _onDidChangeTreeData . fire ( ) ;
5258 } ) ( ) ;
@@ -147,7 +153,8 @@ class TagTreeDataProvider
147153 */
148154 if ( isUpdateNeeded ) {
149155 this . tagTree . deleteFile ( filePath ) ;
150- this . tagTree . addFile ( filePath , [ ...fileInfo . tags . values ( ) ] , filePath ) ;
156+ const displayName = this . getPathRelativeToWorkspaceFolder ( Uri . file ( filePath ) ) ;
157+ this . tagTree . addFile ( filePath , [ ...fileInfo . tags . values ( ) ] , displayName ) ;
151158 // TODO: (bdietz) - this._onDidChangeTreeData.fire(specificNode?)
152159 this . _onDidChangeTreeData . fire ( ) ;
153160 }
@@ -164,7 +171,8 @@ class TagTreeDataProvider
164171 const isUpdateNeeded = ! setsAreEqual ( tagsBefore , tagsAfter ) ;
165172 if ( isUpdateNeeded ) {
166173 this . tagTree . deleteFile ( filePath ) ;
167- this . tagTree . addFile ( filePath , [ ...tagsAfter . values ( ) ] , filePath ) ;
174+ const displayName = this . getPathRelativeToWorkspaceFolder ( Uri . file ( filePath ) ) ;
175+ this . tagTree . addFile ( filePath , [ ...tagsAfter . values ( ) ] , displayName ) ;
168176 /*
169177 * TODO (bdietz) - this._onDidChangeTreeData.fire(specificNode?)
170178 * specifying the specific node would help to improve the efficiency of the tree refresh.
@@ -219,6 +227,19 @@ class TagTreeDataProvider
219227 const buffer = await fs . promises . readFile ( filePath ) ;
220228 return this . getTagsFromFileText ( buffer . toString ( ) , filePath ) ;
221229 }
230+
231+ /**
232+ *
233+ * @param uri
234+ */
235+ private getPathRelativeToWorkspaceFolder ( uri : Uri ) : string {
236+ const currentWorkspaceFolder = vscode . workspace . getWorkspaceFolder ( uri ) ;
237+ const relativePath = typeof currentWorkspaceFolder !== "undefined"
238+ ? path . relative ( currentWorkspaceFolder . uri . path , uri . path )
239+ : uri . path ;
240+
241+ return relativePath ;
242+ }
222243}
223244
224245export { TagTreeDataProvider } ;
0 commit comments