@@ -42,11 +42,41 @@ export class SourcegraphTreeDataProvider implements vscode.TreeDataProvider<stri
4242 } )
4343 }
4444
45- public getParent ( uriString ?: string ) : string | undefined {
45+ public async getParent ( uriString ?: string ) : Promise < string | undefined > {
4646 if ( ! uriString ) {
4747 return undefined
4848 }
49- return SourcegraphUri . parse ( uriString ) . parentUri ( )
49+ const uri = SourcegraphUri . parse ( uriString )
50+ if ( ! uri . path ) {
51+ return undefined
52+ }
53+ let ancestor : string | undefined = uri . repositoryUri ( )
54+ let children = await this . getChildren ( ancestor )
55+ while ( ancestor ) {
56+ for ( const childName of children || [ ] ) {
57+ log . appendLine ( `child=${ childName } ` )
58+ }
59+ const isParent = children ?. includes ( uriString )
60+ if ( isParent ) {
61+ break
62+ }
63+ ancestor = children ?. find ( childUri => {
64+ const child = SourcegraphUri . parse ( childUri )
65+ return child . path && uri . path ?. startsWith ( child . path + '/' )
66+ } )
67+ if ( ! ancestor ) {
68+ log . error ( `getParent(${ uriString || 'undefined' } ) nothing startsWith` )
69+ throw new Error ( 'BOOM' )
70+ }
71+ children = await this . getChildren ( ancestor )
72+ }
73+ log . appendLine ( `getParent(${ uriString || 'undefined' } ) ancestor=${ ancestor || 'undefined' } ` )
74+ return ancestor
75+ // let parentUri = SourcegraphUri.parse(uriString).parentUri()
76+ // while (parentUri && !this.treeItemCache.has(parentUri)) {
77+ // parentUri = SourcegraphUri.parse(parentUri).parentUri()
78+ // }
79+ // return parentUri
5080 }
5181
5282 public async getChildren ( uriString ?: string ) : Promise < string [ ] | undefined > {
@@ -84,14 +114,14 @@ export class SourcegraphTreeDataProvider implements vscode.TreeDataProvider<stri
84114 }
85115 }
86116
87- public getTreeItem ( uriString : string ) : vscode . TreeItem {
117+ public async getTreeItem ( uriString : string ) : Promise < vscode . TreeItem > {
88118 try {
89119 const fromCache = this . treeItemCache . get ( uriString )
90120 if ( fromCache ) {
91121 return fromCache
92122 }
93123 const uri = SourcegraphUri . parse ( uriString )
94- const parentUri = uri . parentUri ( )
124+ const parentUri = await this . getParent ( uri . uri )
95125 return this . newTreeItem ( uri , parentUri ? SourcegraphUri . parse ( parentUri ) : undefined , 0 )
96126 } catch ( error ) {
97127 log . error ( `getTreeItem(${ uriString } )` , error )
@@ -106,7 +136,7 @@ export class SourcegraphTreeDataProvider implements vscode.TreeDataProvider<stri
106136 ) : Promise < void > {
107137 try {
108138 if ( this . treeView ) {
109- const parent = uri . parentUri ( )
139+ const parent = await this . getParent ( uri . uri )
110140 if ( parent && ! this . isExpandedNode . has ( parent ) ) {
111141 await this . didFocusString ( SourcegraphUri . parse ( parent ) , false , token )
112142 }
0 commit comments