Skip to content

Commit 1db117d

Browse files
committed
(WIP) Adds new view ids
1 parent 097c74f commit 1db117d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+108
-158
lines changed

src/views/launchpadView.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ export class LaunchpadItemNode extends CacheableChildrenViewNode<'launchpad-item
4646
this.repoPath = repoPath;
4747
}
4848

49-
override get id(): string {
50-
return this._uniqueId;
51-
}
52-
5349
override toClipboard(type?: ClipboardType): string {
5450
const url = this.getUrl();
5551
switch (type) {

src/views/nodes/UncommittedFilesNode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ export class UncommittedFilesNode extends ViewNode<'uncommitted-files', ViewsWit
3131
this._uniqueId = getViewNodeId(this.type, this.context);
3232
}
3333

34-
override get id(): string {
35-
return this._uniqueId;
36-
}
37-
3834
get repoPath(): string {
3935
return this.status.repoPath;
4036
}

src/views/nodes/abstract/repositoryFolderNode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ export abstract class RepositoryFolderNode<
4949
this.child = undefined;
5050
}
5151

52-
override get id(): string {
53-
return this._uniqueId;
54-
}
55-
5652
override toClipboard(): string {
5753
return this.repo.path;
5854
}

src/views/nodes/abstract/viewNode.ts

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

src/views/nodes/autolinkedItemNode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ export class AutolinkedItemNode extends ViewNode<'autolink', ViewsWithCommits> {
2222
this._uniqueId = getViewNodeId(`${this.type}+${item.id}`, this.context);
2323
}
2424

25-
override get id(): string {
26-
return this._uniqueId;
27-
}
28-
2925
override async toClipboard(type?: ClipboardType): Promise<string> {
3026
const enriched = await this.maybeEnriched;
3127
switch (type) {

src/views/nodes/autolinkedItemsNode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ export class AutolinkedItemsNode extends CacheableChildrenViewNode<'autolinks',
3030
this._uniqueId = getViewNodeId(this.type, this.context);
3131
}
3232

33-
override get id(): string {
34-
return this._uniqueId;
35-
}
36-
3733
async getChildren(): Promise<ViewNode[]> {
3834
if (this.children == null) {
3935
const commits = [...this.log.commits.values()];

src/views/nodes/branchNode.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ export class BranchNode
8383
super('branch', uri, view, parent, root);
8484

8585
this.updateContext({ repository: repo, branch: branch, root: root });
86-
this._uniqueId = getViewNodeId(this.type, this.context);
86+
// this._uniqueId = getViewNodeId(this.type, this.context);
87+
this._uniqueId = `${this.type}(${this.branch.id})`;
88+
8789
this.limit = this.view.getNodeLastKnownLimit(this);
8890

8991
this.options = {
@@ -106,10 +108,6 @@ export class BranchNode
106108
this.children = undefined;
107109
}
108110

109-
override get id(): string {
110-
return this._uniqueId;
111-
}
112-
113111
override toClipboard(): string {
114112
return this.branch.name;
115113
}

src/views/nodes/branchOrTagFolderNode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ export class BranchOrTagFolderNode extends ViewNode<'branch-tag-folder'> {
2222
this._uniqueId = getViewNodeId(`${this.type}+${folderType}+${relativePath ?? folderName}`, this.context);
2323
}
2424

25-
override get id(): string {
26-
return this._uniqueId;
27-
}
28-
2925
override toClipboard(): string {
3026
return this.folderName;
3127
}

src/views/nodes/branchTrackingStatusNode.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,10 @@ export class BranchTrackingStatusNode
5656
branchStatusUpstreamType: upstreamType,
5757
root: root,
5858
});
59-
this._uniqueId = getViewNodeId(this.type, this.context);
59+
// this._uniqueId = getViewNodeId(this.type, this.context);
6060
this.limit = this.view.getNodeLastKnownLimit(this);
6161
}
6262

63-
override get id(): string {
64-
return this._uniqueId;
65-
}
66-
6763
get repoPath(): string {
6864
return this.uri.repoPath!;
6965
}

src/views/nodes/branchesNode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ export class BranchesNode extends CacheableChildrenViewNode<'branches', ViewsWit
2525
this._uniqueId = getViewNodeId(this.type, this.context);
2626
}
2727

28-
override get id(): string {
29-
return this._uniqueId;
30-
}
31-
3228
get repoPath(): string {
3329
return this.repo.path;
3430
}

src/views/nodes/codeSuggestionsNode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ export class CodeSuggestionsNode extends CacheableChildrenViewNode<'drafts-code-
2020
this._uniqueId = getViewNodeId(this.type, this.context);
2121
}
2222

23-
override get id(): string {
24-
return this._uniqueId;
25-
}
26-
2723
async getChildren(): Promise<ViewNode[]> {
2824
if (this.children == null) {
2925
const drafts = await this.getSuggestedChanges();

src/views/nodes/commitFileNode.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,9 @@ export abstract class CommitFileNodeBase<
3939
super(type, GitUri.fromFile(file, commit.repoPath, commit.sha), view, parent, file);
4040

4141
this.updateContext({ commit: commit, file: file });
42-
this._uniqueId = getViewNodeId(type, this.context);
43-
}
42+
this._uniqueId = `${this.type}(${this.commit.repoPath}|${this.commit.sha}:${this.file.path}+${this.file.status})`;
4443

45-
override get id(): string {
46-
return this._uniqueId;
44+
// this._uniqueId = getViewNodeId(type, this.context);
4745
}
4846

4947
override toClipboard(): string {

src/views/nodes/commitNode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ export class CommitNode extends ViewRefNode<'commit', ViewsWithCommits | FileHis
5454
this.children = undefined;
5555
}
5656

57-
override get id(): string {
58-
return this._uniqueId;
59-
}
60-
6157
override toClipboard(): string {
6258
return `${this.commit.shortSha}: ${this.commit.summary}`;
6359
}

src/views/nodes/compareResultsNode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ export class CompareResultsNode extends SubscribeableViewNode<
5858
}
5959
}
6060

61-
override get id(): string {
62-
return this._uniqueId;
63-
}
64-
6561
protected override etag(): number {
6662
return this._storedAt;
6763
}

src/views/nodes/contributorNode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ export class ContributorNode extends ViewNode<'contributor', ViewsWithContributo
3939
this.limit = this.view.getNodeLastKnownLimit(this);
4040
}
4141

42-
override get id(): string {
43-
return this._uniqueId;
44-
}
45-
4642
override toClipboard(type?: ClipboardType): string {
4743
const text = `${this.contributor.name}${this.contributor.email ? ` <${this.contributor.email}>` : ''}`;
4844
switch (type) {

src/views/nodes/contributorsNode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ export class ContributorsNode extends CacheableChildrenViewNode<
3030
this._uniqueId = getViewNodeId(this.type, this.context);
3131
}
3232

33-
override get id(): string {
34-
return this._uniqueId;
35-
}
36-
3733
get repoPath(): string {
3834
return this.repo.path;
3935
}

src/views/nodes/draftNode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ export class DraftNode extends ViewNode<'draft', ViewsWithCommits | DraftsView>
2222
this._uniqueId = getViewNodeId(this.type, this.context);
2323
}
2424

25-
override get id(): string {
26-
return this._uniqueId;
27-
}
28-
2925
override toClipboard(): string {
3026
return this.getUrl();
3127
}

src/views/nodes/fileHistoryNode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ export class FileHistoryNode
4545
this.limit = this.view.getNodeLastKnownLimit(this);
4646
}
4747

48-
override get id(): string {
49-
return this._uniqueId;
50-
}
51-
5248
override toClipboard(): string {
5349
return this.uri.fileName;
5450
}

src/views/nodes/fileRevisionAsCommitNode.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export class FileRevisionAsCommitNode extends ViewRefFileNode<
4242
} = {},
4343
) {
4444
super('file-commit', GitUri.fromFile(file, commit.repoPath, commit.sha), view, parent, file);
45+
46+
this._uniqueId = `${this.type}(${this.commit.repoPath}|${this.commit.sha}:${this.file.path}+${this.file.status})`;
4547
}
4648

4749
override toClipboard(): string {

src/views/nodes/folderNode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ export class FolderNode extends ViewNode<'folder', ViewsWithCommits | StashesVie
3535
this._uniqueId = getViewNodeId(`${this.type}+${relativePath ?? folderName}`, this.context);
3636
}
3737

38-
override get id(): string {
39-
return this._uniqueId;
40-
}
41-
4238
override toClipboard(): string {
4339
return this.folderName;
4440
}

src/views/nodes/lineHistoryNode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ export class LineHistoryNode
5252
this.limit = this.view.getNodeLastKnownLimit(this);
5353
}
5454

55-
override get id(): string {
56-
return this._uniqueId;
57-
}
58-
5955
override toClipboard(): string {
6056
return this.uri.fileName;
6157
}

src/views/nodes/pullRequestNode.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,10 @@ export class PullRequestNode extends CacheableChildrenViewNode<'pullrequest', Vi
5353
}
5454

5555
this.updateContext({ pullRequest: pullRequest });
56-
this._uniqueId = getViewNodeId(this.type, this.context);
57-
this.repoPath = repoPath;
58-
}
56+
// this._uniqueId = getViewNodeId(this.type, this.context);
57+
this._uniqueId = `${this.type}(${this.pullRequest.url})`;
5958

60-
override get id(): string {
61-
return this._uniqueId;
59+
this.repoPath = repoPath;
6260
}
6361

6462
override toClipboard(type?: ClipboardType): string {

src/views/nodes/reflogNode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ export class ReflogNode
3030
this.limit = this.view.getNodeLastKnownLimit(this);
3131
}
3232

33-
override get id(): string {
34-
return this._uniqueId;
35-
}
36-
3733
async getChildren(): Promise<ViewNode[]> {
3834
if (this.children === undefined) {
3935
const children = [];

src/views/nodes/reflogRecordNode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ export class ReflogRecordNode extends ViewNode<'reflog-record', ViewsWithCommits
2727
this.limit = this.view.getNodeLastKnownLimit(this);
2828
}
2929

30-
override get id(): string {
31-
return this._uniqueId;
32-
}
33-
3430
async getChildren(): Promise<ViewNode[]> {
3531
const log = await this.getLog();
3632
if (log === undefined) return [new MessageNode(this.view, this, 'No commits could be found.')];

src/views/nodes/remoteNode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ export class RemoteNode extends ViewNode<'remote', ViewsWithRemotes> {
2727
this._uniqueId = getViewNodeId(this.type, this.context);
2828
}
2929

30-
override get id(): string {
31-
return this._uniqueId;
32-
}
33-
3430
override toClipboard(): string {
3531
return this.remote.name;
3632
}

0 commit comments

Comments
 (0)