@@ -154,7 +154,29 @@ export interface AmbientContext {
154
154
readonly worktreesByBranch ?: Map < string , GitWorktree > ;
155
155
}
156
156
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
+
158
180
let uniqueness = '' ;
159
181
if ( context . root ) {
160
182
uniqueness += '/root' ;
@@ -252,8 +274,22 @@ export abstract class ViewNode<
252
274
return types . includes ( this . type as unknown as T [ number ] ) ;
253
275
}
254
276
277
+ public childrenIds = new Set < string > ( ) ;
278
+ public childrenCount = 0 ;
255
279
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
+
257
293
// NOTE: @eamodio uncomment to track node leaks
258
294
// readonly uuid = uuid();
259
295
@@ -266,7 +302,10 @@ export abstract class ViewNode<
266
302
//** Indicates if this node is only shown as its children, not itself */
267
303
splatted ?: boolean ,
268
304
) {
269
- this . splatted = splatted ?? false ;
305
+ this . _splatted = splatted ?? false ;
306
+ ( parent ?? this ) . childrenCount ++ ;
307
+
308
+ // this.setId();
270
309
271
310
// NOTE: @eamodio uncomment to track node leaks
272
311
// queueMicrotask(() => this.view.registerNode(this));
@@ -281,9 +320,38 @@ export abstract class ViewNode<
281
320
// NOTE: @eamodio uncomment to track node leaks
282
321
// this.view.unregisterNode(this);
283
322
}
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
+ }
284
340
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);
287
355
}
288
356
289
357
private _context : AmbientContext | undefined ;
0 commit comments