@@ -154,7 +154,29 @@ export interface AmbientContext {
154154 readonly worktreesByBranch ?: Map < string , GitWorktree > ;
155155}
156156
157- export function getViewNodeId ( type : string , context : AmbientContext ) : string {
157+ export function getViewNodeId (
158+ type : TreeViewNodeTypes | `${TreeViewNodeTypes } +${string } `,
159+ context : AmbientContext ,
160+ ) : string {
161+ switch ( type ) {
162+ case 'branch' :
163+ return `${ type } (${ context . branch ?. id } )` ;
164+
165+ case 'commit' :
166+ return `${ type } (${ context . commit ?. repoPath } |${ context . commit ?. sha } )` ;
167+
168+ case 'pullrequest' :
169+ return `${ type } (${ context . pullRequest ?. url } )` ;
170+
171+ case 'commit-file' :
172+ return `${ type } :(${
173+ context . repository ?. path ?? context . branch ?. repoPath ?? context . commit ?. repoPath
174+ } |${ context . file ?. path } +${ context . file ?. status } )`;
175+
176+ // case 'results-file':
177+ // return `${type}(${context.file?.path}+${context.file?.status})`;
178+ }
179+
158180 let uniqueness = '' ;
159181 if ( context . root ) {
160182 uniqueness += '/root' ;
@@ -252,8 +274,22 @@ export abstract class ViewNode<
252274 return types . includes ( this . type as unknown as T [ number ] ) ;
253275 }
254276
277+ public childrenIds = new Set < string > ( ) ;
278+ public childrenCount = 0 ;
255279 protected _uniqueId ! : string ;
256- splatted = false ;
280+
281+ private _splatted : boolean ;
282+ //** Indicates if this node is only shown as its children, not itself */
283+ get splatted ( ) : boolean {
284+ return this . _splatted ;
285+ }
286+ set splatted ( value : boolean ) {
287+ if ( this . _splatted === value ) return ;
288+
289+ this . _splatted = value ;
290+ // this.setId();
291+ }
292+
257293 // NOTE: @eamodio uncomment to track node leaks
258294 // readonly uuid = uuid();
259295
@@ -266,7 +302,10 @@ export abstract class ViewNode<
266302 //** Indicates if this node is only shown as its children, not itself */
267303 splatted ?: boolean ,
268304 ) {
269- this . splatted = splatted ?? false ;
305+ this . _splatted = splatted ?? false ;
306+ ( parent ?? this ) . childrenCount ++ ;
307+
308+ // this.setId();
270309
271310 // NOTE: @eamodio uncomment to track node leaks
272311 // queueMicrotask(() => this.view.registerNode(this));
@@ -281,9 +320,38 @@ export abstract class ViewNode<
281320 // NOTE: @eamodio uncomment to track node leaks
282321 // this.view.unregisterNode(this);
283322 }
323+ private _id ! : string ;
324+ get id ( ) : string {
325+ if ( this . _id == null ) {
326+ // if (!this.splatted) {
327+ this . _id = this . _uniqueId ?? `${ ( this . parent ?? this ) . childrenCount } :${ this . type } ` ;
328+ // }
329+ }
330+ return this . _id ;
331+ }
332+
333+ get parentId ( ) : string {
334+ return this . parent ?. treeId ?? '~' ;
335+ }
336+
337+ get treeId ( ) : string {
338+ return this . splatted ? this . parentId : `${ this . parentId } /${ this . id } ` ;
339+ }
284340
285- get id ( ) : string | undefined {
286- return this . _uniqueId ;
341+ private setId ( ) {
342+ // if (this.splatted) {
343+ // this._id = undefined!; //this.parent?.id ?? '~';
344+ // } else {
345+ // const { parent } = this;
346+ // const { childrenIds } = parent ?? this;
347+ // this._id = this._uniqueId ?? `${childrenIds.size ?? 0}:${this.type}`;
348+ // if (childrenIds.has(this._id)) {
349+ // debugger;
350+ // // this._id = `${this._id}-${this._uniqueCounter++}`;
351+ // }
352+ // childrenIds.add(this._id);
353+ // }
354+ // console.log('#######', this.type, this.splatted, this._id);
287355 }
288356
289357 private _context : AmbientContext | undefined ;
0 commit comments