From 097c74f3792c3d023f706e5e6f6dc8753a162cd7 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sun, 17 Nov 2024 01:14:52 -0500 Subject: [PATCH 1/2] Consolidates view node splatting --- src/views/branchesView.ts | 2 +- src/views/commitsView.ts | 2 +- src/views/contributorsView.ts | 2 +- .../abstract/repositoriesSubscribeableNode.ts | 4 +--- .../nodes/abstract/repositoryFolderNode.ts | 10 ++------ .../nodes/abstract/subscribeableViewNode.ts | 4 ++-- src/views/nodes/abstract/viewNode.ts | 24 ++++++++++++------- src/views/nodes/abstract/viewRefNode.ts | 3 ++- src/views/nodes/branchNode.ts | 5 +--- src/views/nodes/branchesNode.ts | 2 +- src/views/nodes/contributorsNode.ts | 6 +---- src/views/nodes/fileHistoryNode.ts | 6 +---- src/views/nodes/fileHistoryTrackerNode.ts | 5 +--- src/views/nodes/lineHistoryNode.ts | 6 +---- src/views/nodes/lineHistoryTrackerNode.ts | 5 +--- src/views/nodes/resultsCommitsNode.ts | 5 +--- src/views/nodes/worktreeNode.ts | 2 -- src/views/remotesView.ts | 2 +- src/views/searchAndCompareView.ts | 5 +--- src/views/stashesView.ts | 2 +- src/views/tagsView.ts | 2 +- src/views/viewBase.ts | 16 ++++++++----- src/views/worktreesView.ts | 2 +- 23 files changed, 49 insertions(+), 73 deletions(-) diff --git a/src/views/branchesView.ts b/src/views/branchesView.ts index 886601096349e..2fd70b1d6861e 100644 --- a/src/views/branchesView.ts +++ b/src/views/branchesView.ts @@ -76,7 +76,7 @@ export class BranchesViewNode extends RepositoriesSubscribeableNode new BranchesRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, splat), + r => new BranchesRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, splat, r), ); } diff --git a/src/views/commitsView.ts b/src/views/commitsView.ts index 5f09b5a026290..23563e67fdcc6 100644 --- a/src/views/commitsView.ts +++ b/src/views/commitsView.ts @@ -136,7 +136,7 @@ export class CommitsViewNode extends RepositoriesSubscribeableNode - new CommitsRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, splat, { + new CommitsRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, splat, r, { showBranchAndLastFetched: true, }), ); diff --git a/src/views/contributorsView.ts b/src/views/contributorsView.ts index 7c412aadba4eb..8efba4375d03f 100644 --- a/src/views/contributorsView.ts +++ b/src/views/contributorsView.ts @@ -76,7 +76,7 @@ export class ContributorsViewNode extends RepositoriesSubscribeableNode new ContributorsRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, splat), + r => new ContributorsRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, splat, r), ); } diff --git a/src/views/nodes/abstract/repositoriesSubscribeableNode.ts b/src/views/nodes/abstract/repositoriesSubscribeableNode.ts index eaa9164670a93..253ebf25212c2 100644 --- a/src/views/nodes/abstract/repositoriesSubscribeableNode.ts +++ b/src/views/nodes/abstract/repositoriesSubscribeableNode.ts @@ -13,10 +13,8 @@ export abstract class RepositoriesSubscribeableNode< TView extends View = View, TChild extends ViewNode = ViewNode, > extends SubscribeableViewNode<'repositories', TView, TChild> { - protected override splatted = true; - constructor(view: TView) { - super('repositories', unknownGitUri, view); + super('repositories', unknownGitUri, view, undefined, true); } override async getSplattedChild() { diff --git a/src/views/nodes/abstract/repositoryFolderNode.ts b/src/views/nodes/abstract/repositoryFolderNode.ts index c7db03d916ef2..98886fe7220b6 100644 --- a/src/views/nodes/abstract/repositoryFolderNode.ts +++ b/src/views/nodes/abstract/repositoryFolderNode.ts @@ -19,22 +19,18 @@ export abstract class RepositoryFolderNode< TView extends View = View, TChild extends ViewNode = ViewNode, > extends SubscribeableViewNode<'repo-folder', TView> { - protected override splatted = true; - constructor( uri: GitUri, view: TView, protected override readonly parent: ViewNode, - public readonly repo: Repository, splatted: boolean, + public readonly repo: Repository, private readonly options?: { showBranchAndLastFetched?: boolean }, ) { - super('repo-folder', uri, view, parent); + super('repo-folder', uri, view, parent, splatted); this.updateContext({ repository: this.repo }); this._uniqueId = getViewNodeId(this.type, this.context); - - this.splatted = splatted; } private _child: TChild | undefined; @@ -66,8 +62,6 @@ export abstract class RepositoryFolderNode< } async getTreeItem(): Promise { - this.splatted = false; - const branch = await this.repo.git.getBranch(); const ahead = (branch?.state.ahead ?? 0) > 0; const behind = (branch?.state.behind ?? 0) > 0; diff --git a/src/views/nodes/abstract/subscribeableViewNode.ts b/src/views/nodes/abstract/subscribeableViewNode.ts index 1f5d388fea58e..2088849767269 100644 --- a/src/views/nodes/abstract/subscribeableViewNode.ts +++ b/src/views/nodes/abstract/subscribeableViewNode.ts @@ -21,8 +21,8 @@ export abstract class SubscribeableViewNode< protected loaded: boolean = false; - constructor(type: Type, uri: GitUri, view: TView, parent?: ViewNode) { - super(type, uri, view, parent); + constructor(type: Type, uri: GitUri, view: TView, parent?: ViewNode, splatted?: boolean) { + super(type, uri, view, parent, splatted); const disposables = [ weakEvent(this.view.onDidChangeVisibility, this.onVisibilityChanged, this), diff --git a/src/views/nodes/abstract/viewNode.ts b/src/views/nodes/abstract/viewNode.ts index 004c17ea5e30a..cac8aa7c4df42 100644 --- a/src/views/nodes/abstract/viewNode.ts +++ b/src/views/nodes/abstract/viewNode.ts @@ -253,7 +253,7 @@ export abstract class ViewNode< } protected _uniqueId!: string; - protected splatted = false; + splatted = false; // NOTE: @eamodio uncomment to track node leaks // readonly uuid = uuid(); @@ -262,8 +262,12 @@ export abstract class ViewNode< // public readonly id: string | undefined, uri: GitUri, public readonly view: TView, - protected parent?: ViewNode, + protected parent?: ViewNode | undefined, + //** Indicates if this node is only shown as its children, not itself */ + splatted?: boolean, ) { + this.splatted = splatted ?? false; + // NOTE: @eamodio uncomment to track node leaks // queueMicrotask(() => this.view.registerNode(this)); this._uri = uri; @@ -339,20 +343,24 @@ export abstract class ViewNode< getSplattedChild?(): Promise; + protected get storedId(): string | undefined { + return this.id; + } + deleteState = StateKey>(key?: T): void { - if (this.id == null) { + if (this.storedId == null) { debugger; throw new Error('Id is required to delete state'); } - this.view.nodeState.deleteState(this.id, key as string); + this.view.nodeState.deleteState(this.storedId, key as string); } getState = StateKey>(key: T): StateValue | undefined { - if (this.id == null) { + if (this.storedId == null) { debugger; throw new Error('Id is required to get state'); } - return this.view.nodeState.getState(this.id, key as string); + return this.view.nodeState.getState(this.storedId, key as string); } storeState = StateKey>( @@ -360,11 +368,11 @@ export abstract class ViewNode< value: StateValue, sticky?: boolean, ): void { - if (this.id == null) { + if (this.storedId == null) { debugger; throw new Error('Id is required to store state'); } - this.view.nodeState.storeState(this.id, key as string, value, sticky); + this.view.nodeState.storeState(this.storedId, key as string, value, sticky); } } diff --git a/src/views/nodes/abstract/viewRefNode.ts b/src/views/nodes/abstract/viewRefNode.ts index bd2b1a6f84da2..5da77a49249a1 100644 --- a/src/views/nodes/abstract/viewRefNode.ts +++ b/src/views/nodes/abstract/viewRefNode.ts @@ -17,8 +17,9 @@ export abstract class ViewRefNode< uri: GitUri, view: TView, protected override readonly parent: ViewNode, + splatted?: boolean, ) { - super(type, uri, view, parent); + super(type, uri, view, parent, splatted); } abstract get ref(): TReference; diff --git a/src/views/nodes/branchNode.ts b/src/views/nodes/branchNode.ts index 1a37e583a8569..f387c3104c23f 100644 --- a/src/views/nodes/branchNode.ts +++ b/src/views/nodes/branchNode.ts @@ -69,7 +69,6 @@ export class BranchNode limit: number | undefined; private readonly options: Options; - protected override splatted = true; constructor( uri: GitUri, @@ -81,7 +80,7 @@ export class BranchNode public readonly root: boolean, options?: Partial, ) { - super('branch', uri, view, parent); + super('branch', uri, view, parent, root); this.updateContext({ repository: repo, branch: branch, root: root }); this._uniqueId = getViewNodeId(this.type, this.context); @@ -418,8 +417,6 @@ export class BranchNode } async getTreeItem(): Promise { - this.splatted = false; - const parts = await getBranchNodeParts(this.view.container, this.branch, this.current, { pendingPullRequest: this.getState('pendingPullRequest'), showAsCommits: this.options.showAsCommits, diff --git a/src/views/nodes/branchesNode.ts b/src/views/nodes/branchesNode.ts index 8034455e9becb..ed31b4f4e294f 100644 --- a/src/views/nodes/branchesNode.ts +++ b/src/views/nodes/branchesNode.ts @@ -19,7 +19,7 @@ export class BranchesNode extends CacheableChildrenViewNode<'branches', ViewsWit protected override readonly parent: ViewNode, public readonly repo: Repository, ) { - super('branches', uri, view, parent); + super('branches', uri, view, parent, true); this.updateContext({ repository: repo }); this._uniqueId = getViewNodeId(this.type, this.context); diff --git a/src/views/nodes/contributorsNode.ts b/src/views/nodes/contributorsNode.ts index de1b4fea7f18c..d243de51dc9df 100644 --- a/src/views/nodes/contributorsNode.ts +++ b/src/views/nodes/contributorsNode.ts @@ -17,8 +17,6 @@ export class ContributorsNode extends CacheableChildrenViewNode< ViewsWithContributorsNode, ContributorNode > { - protected override splatted = true; - constructor( uri: GitUri, view: ViewsWithContributorsNode, @@ -26,7 +24,7 @@ export class ContributorsNode extends CacheableChildrenViewNode< public readonly repo: Repository, private readonly options?: { all?: boolean; showMergeCommits?: boolean; stats?: boolean }, ) { - super('contributors', uri, view, parent); + super('contributors', uri, view, parent, true); this.updateContext({ repository: repo }); this._uniqueId = getViewNodeId(this.type, this.context); @@ -83,8 +81,6 @@ export class ContributorsNode extends CacheableChildrenViewNode< } getTreeItem(): TreeItem { - this.splatted = false; - const item = new TreeItem('Contributors', TreeItemCollapsibleState.Collapsed); item.id = this.id; item.contextValue = ContextValues.Contributors; diff --git a/src/views/nodes/fileHistoryNode.ts b/src/views/nodes/fileHistoryNode.ts index f7784dfed0569..5b235a1cc48b1 100644 --- a/src/views/nodes/fileHistoryNode.ts +++ b/src/views/nodes/fileHistoryNode.ts @@ -29,8 +29,6 @@ export class FileHistoryNode { limit: number | undefined; - protected override splatted = true; - constructor( uri: GitUri, view: FileHistoryView, @@ -38,7 +36,7 @@ export class FileHistoryNode private readonly folder: boolean, private readonly branch: GitBranch | undefined, ) { - super('file-history', uri, view, parent); + super('file-history', uri, view, parent, true); if (branch != null) { this.updateContext({ branch: branch }); @@ -148,8 +146,6 @@ export class FileHistoryNode } getTreeItem(): TreeItem { - this.splatted = false; - const label = this.label; const item = new TreeItem(label, TreeItemCollapsibleState.Expanded); item.contextValue = ContextValues.FileHistory; diff --git a/src/views/nodes/fileHistoryTrackerNode.ts b/src/views/nodes/fileHistoryTrackerNode.ts index 97dfce5af60f2..3e4532e62d5a5 100644 --- a/src/views/nodes/fileHistoryTrackerNode.ts +++ b/src/views/nodes/fileHistoryTrackerNode.ts @@ -22,10 +22,9 @@ import { FileHistoryNode } from './fileHistoryNode'; export class FileHistoryTrackerNode extends SubscribeableViewNode<'file-history-tracker', FileHistoryView> { private _base: string | undefined; - protected override splatted = true; constructor(view: FileHistoryView) { - super('file-history-tracker', unknownGitUri, view); + super('file-history-tracker', unknownGitUri, view, undefined, true); } override dispose() { @@ -85,8 +84,6 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode<'file-history- } getTreeItem(): TreeItem { - this.splatted = false; - const item = new TreeItem('File History', TreeItemCollapsibleState.Expanded); item.contextValue = ContextValues.ActiveFileHistory; diff --git a/src/views/nodes/lineHistoryNode.ts b/src/views/nodes/lineHistoryNode.ts index b4ab4806ee652..18b63afb9cc4b 100644 --- a/src/views/nodes/lineHistoryNode.ts +++ b/src/views/nodes/lineHistoryNode.ts @@ -30,8 +30,6 @@ export class LineHistoryNode { limit: number | undefined; - protected override splatted = true; - constructor( uri: GitUri, view: FileHistoryView | LineHistoryView, @@ -40,7 +38,7 @@ export class LineHistoryNode public readonly selection: Selection, private readonly editorContents: string | undefined, ) { - super('line-history', uri, view, parent); + super('line-history', uri, view, parent, true); if (branch != null) { this.updateContext({ branch: branch }); @@ -163,8 +161,6 @@ export class LineHistoryNode } getTreeItem(): TreeItem { - this.splatted = false; - const label = this.label; const item = new TreeItem(label, TreeItemCollapsibleState.Expanded); item.contextValue = ContextValues.LineHistory; diff --git a/src/views/nodes/lineHistoryTrackerNode.ts b/src/views/nodes/lineHistoryTrackerNode.ts index 43493eb9ecac8..f9877ad66c3b2 100644 --- a/src/views/nodes/lineHistoryTrackerNode.ts +++ b/src/views/nodes/lineHistoryTrackerNode.ts @@ -28,10 +28,9 @@ export class LineHistoryTrackerNode extends SubscribeableViewNode< private _base: string | undefined; private _editorContents: string | undefined; private _selection: Selection | undefined; - protected override splatted = true; constructor(view: FileHistoryView | LineHistoryView) { - super('line-history-tracker', unknownGitUri, view); + super('line-history-tracker', unknownGitUri, view, undefined, true); } override dispose() { @@ -96,8 +95,6 @@ export class LineHistoryTrackerNode extends SubscribeableViewNode< } getTreeItem(): TreeItem { - this.splatted = false; - const item = new TreeItem('Line History', TreeItemCollapsibleState.Expanded); item.contextValue = ContextValues.ActiveLineHistory; diff --git a/src/views/nodes/resultsCommitsNode.ts b/src/views/nodes/resultsCommitsNode.ts index 1b0c6917b58bd..b78f84074b796 100644 --- a/src/views/nodes/resultsCommitsNode.ts +++ b/src/views/nodes/resultsCommitsNode.ts @@ -51,7 +51,7 @@ export class ResultsCommitsNode, splatted?: boolean, ) { - super('results-commits', GitUri.fromRepoPath(repoPath), view, parent); + super('results-commits', GitUri.fromRepoPath(repoPath), view, parent, splatted); if (_results.direction != null) { this.updateContext({ branchStatusUpstreamType: _results.direction }); @@ -60,9 +60,6 @@ export class ResultsCommitsNode { - this.splatted = false; - let description = ''; let icon: IconPath | undefined; let hasChanges = false; diff --git a/src/views/remotesView.ts b/src/views/remotesView.ts index 39295a3bd51d7..163b7cae6bd7b 100644 --- a/src/views/remotesView.ts +++ b/src/views/remotesView.ts @@ -68,7 +68,7 @@ export class RemotesViewNode extends RepositoriesSubscribeableNode new RemotesRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, splat), + r => new RemotesRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, splat, r), ); } diff --git a/src/views/searchAndCompareView.ts b/src/views/searchAndCompareView.ts index 7a18afb919881..2e454a1ad85d7 100644 --- a/src/views/searchAndCompareView.ts +++ b/src/views/searchAndCompareView.ts @@ -29,11 +29,10 @@ import { disposeChildren, ViewBase } from './viewBase'; import { registerViewCommand } from './viewCommands'; export class SearchAndCompareViewNode extends ViewNode<'search-compare', SearchAndCompareView> { - protected override splatted = true; private comparePicker: ComparePickerNode | undefined; constructor(view: SearchAndCompareView) { - super('search-compare', unknownGitUri, view); + super('search-compare', unknownGitUri, view, undefined, true); } override dispose() { @@ -73,8 +72,6 @@ export class SearchAndCompareViewNode extends ViewNode<'search-compare', SearchA } getTreeItem(): TreeItem { - this.splatted = false; - const item = new TreeItem('SearchAndCompare', TreeItemCollapsibleState.Expanded); item.contextValue = ContextValues.SearchAndCompare; return item; diff --git a/src/views/stashesView.ts b/src/views/stashesView.ts index c0eaa2b44f7ad..de0132bad8a4b 100644 --- a/src/views/stashesView.ts +++ b/src/views/stashesView.ts @@ -54,7 +54,7 @@ export class StashesViewNode extends RepositoriesSubscribeableNode new StashesRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, splat), + r => new StashesRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, splat, r), ); } diff --git a/src/views/tagsView.ts b/src/views/tagsView.ts index 4e97ad42bac4d..df165b38844d4 100644 --- a/src/views/tagsView.ts +++ b/src/views/tagsView.ts @@ -55,7 +55,7 @@ export class TagsViewNode extends RepositoriesSubscribeableNode new TagsRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, splat), + r => new TagsRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, splat, r), ); } diff --git a/src/views/viewBase.ts b/src/views/viewBase.ts index 6197a658c16e6..9d2ad519dda1c 100644 --- a/src/views/viewBase.ts +++ b/src/views/viewBase.ts @@ -246,14 +246,14 @@ export abstract class ViewBase< } if (typeof item.tooltip === 'string') { - item.tooltip = `${item.tooltip}\n\n---\ncontext: ${item.contextValue}\nnode: ${node.toString()}${ - parent != null ? `\nparent: ${parent.toString()}` : '' - }`; + item.tooltip = `${item.tooltip}\n\n---\ncontext: ${ + item.contextValue + }\nnode: ${node.toString()}\nparent: ${parent?.toString()}`; } else { item.tooltip.appendMarkdown( - `\n\n---\n\ncontext: \`${item.contextValue}\`\\\nnode: \`${node.toString()}\`${ - parent != null ? `\\\nparent: \`${parent.toString()}\`` : '' - }`, + `\n\n---\n\ncontext: \`${ + item.contextValue + }\`\\\nnode: \`${node.toString()}\` \\\nparent: \`${parent?.toString()}\``, ); } } @@ -458,6 +458,10 @@ export abstract class ViewBase< } getTreeItem(node: ViewNode): TreeItem | Promise { + if (node.splatted) { + debugger; + node.splatted = false; + } return node.getTreeItem(); } diff --git a/src/views/worktreesView.ts b/src/views/worktreesView.ts index 5160d7d71c57d..ea9b9f738de88 100644 --- a/src/views/worktreesView.ts +++ b/src/views/worktreesView.ts @@ -65,7 +65,7 @@ export class WorktreesViewNode extends RepositoriesSubscribeableNode new WorktreesRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, splat), + r => new WorktreesRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, splat, r), ); } From 1db117d52447aa9cd247774c54d3889dc74d44bd Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 26 Nov 2024 14:29:14 -0500 Subject: [PATCH 2/2] (WIP) Adds new view ids --- src/views/launchpadView.ts | 4 - src/views/nodes/UncommittedFilesNode.ts | 4 - .../nodes/abstract/repositoryFolderNode.ts | 4 - src/views/nodes/abstract/viewNode.ts | 78 +++++++++++++++++-- src/views/nodes/autolinkedItemNode.ts | 4 - src/views/nodes/autolinkedItemsNode.ts | 4 - src/views/nodes/branchNode.ts | 8 +- src/views/nodes/branchOrTagFolderNode.ts | 4 - src/views/nodes/branchTrackingStatusNode.ts | 6 +- src/views/nodes/branchesNode.ts | 4 - src/views/nodes/codeSuggestionsNode.ts | 4 - src/views/nodes/commitFileNode.ts | 6 +- src/views/nodes/commitNode.ts | 4 - src/views/nodes/compareResultsNode.ts | 4 - src/views/nodes/contributorNode.ts | 4 - src/views/nodes/contributorsNode.ts | 4 - src/views/nodes/draftNode.ts | 4 - src/views/nodes/fileHistoryNode.ts | 4 - src/views/nodes/fileRevisionAsCommitNode.ts | 2 + src/views/nodes/folderNode.ts | 4 - src/views/nodes/lineHistoryNode.ts | 4 - src/views/nodes/pullRequestNode.ts | 8 +- src/views/nodes/reflogNode.ts | 4 - src/views/nodes/reflogRecordNode.ts | 4 - src/views/nodes/remoteNode.ts | 4 - src/views/nodes/remotesNode.ts | 4 - src/views/nodes/repositoryNode.ts | 4 - src/views/nodes/resultsCommitsNode.ts | 4 - src/views/nodes/resultsFilesNode.ts | 4 - src/views/nodes/searchResultsNode.ts | 4 - src/views/nodes/stashNode.ts | 4 - src/views/nodes/stashesNode.ts | 4 - src/views/nodes/statusFileNode.ts | 1 + src/views/nodes/statusFilesNode.ts | 4 - src/views/nodes/tagNode.ts | 4 - src/views/nodes/tagsNode.ts | 4 - .../nodes/workspaceMissingRepositoryNode.ts | 4 - src/views/nodes/workspaceNode.ts | 4 - src/views/nodes/worktreeNode.ts | 4 - src/views/nodes/worktreesNode.ts | 4 - src/views/viewBase.ts | 25 +++++- 41 files changed, 108 insertions(+), 158 deletions(-) diff --git a/src/views/launchpadView.ts b/src/views/launchpadView.ts index af01c967a5985..c72a36e9b0b5c 100644 --- a/src/views/launchpadView.ts +++ b/src/views/launchpadView.ts @@ -46,10 +46,6 @@ export class LaunchpadItemNode extends CacheableChildrenViewNode<'launchpad-item this.repoPath = repoPath; } - override get id(): string { - return this._uniqueId; - } - override toClipboard(type?: ClipboardType): string { const url = this.getUrl(); switch (type) { diff --git a/src/views/nodes/UncommittedFilesNode.ts b/src/views/nodes/UncommittedFilesNode.ts index b660e5a412224..19610ccb29770 100644 --- a/src/views/nodes/UncommittedFilesNode.ts +++ b/src/views/nodes/UncommittedFilesNode.ts @@ -31,10 +31,6 @@ export class UncommittedFilesNode extends ViewNode<'uncommitted-files', ViewsWit this._uniqueId = getViewNodeId(this.type, this.context); } - override get id(): string { - return this._uniqueId; - } - get repoPath(): string { return this.status.repoPath; } diff --git a/src/views/nodes/abstract/repositoryFolderNode.ts b/src/views/nodes/abstract/repositoryFolderNode.ts index 98886fe7220b6..514ee41ca0817 100644 --- a/src/views/nodes/abstract/repositoryFolderNode.ts +++ b/src/views/nodes/abstract/repositoryFolderNode.ts @@ -49,10 +49,6 @@ export abstract class RepositoryFolderNode< this.child = undefined; } - override get id(): string { - return this._uniqueId; - } - override toClipboard(): string { return this.repo.path; } diff --git a/src/views/nodes/abstract/viewNode.ts b/src/views/nodes/abstract/viewNode.ts index cac8aa7c4df42..18237eb2198ae 100644 --- a/src/views/nodes/abstract/viewNode.ts +++ b/src/views/nodes/abstract/viewNode.ts @@ -154,7 +154,29 @@ export interface AmbientContext { readonly worktreesByBranch?: Map; } -export function getViewNodeId(type: string, context: AmbientContext): string { +export function getViewNodeId( + type: TreeViewNodeTypes | `${TreeViewNodeTypes}+${string}`, + context: AmbientContext, +): string { + switch (type) { + case 'branch': + return `${type}(${context.branch?.id})`; + + case 'commit': + return `${type}(${context.commit?.repoPath}|${context.commit?.sha})`; + + case 'pullrequest': + return `${type}(${context.pullRequest?.url})`; + + case 'commit-file': + return `${type}:(${ + context.repository?.path ?? context.branch?.repoPath ?? context.commit?.repoPath + }|${context.file?.path}+${context.file?.status})`; + + // case 'results-file': + // return `${type}(${context.file?.path}+${context.file?.status})`; + } + let uniqueness = ''; if (context.root) { uniqueness += '/root'; @@ -252,8 +274,22 @@ export abstract class ViewNode< return types.includes(this.type as unknown as T[number]); } + public childrenIds = new Set(); + public childrenCount = 0; protected _uniqueId!: string; - splatted = false; + + private _splatted: boolean; + //** Indicates if this node is only shown as its children, not itself */ + get splatted(): boolean { + return this._splatted; + } + set splatted(value: boolean) { + if (this._splatted === value) return; + + this._splatted = value; + // this.setId(); + } + // NOTE: @eamodio uncomment to track node leaks // readonly uuid = uuid(); @@ -266,7 +302,10 @@ export abstract class ViewNode< //** Indicates if this node is only shown as its children, not itself */ splatted?: boolean, ) { - this.splatted = splatted ?? false; + this._splatted = splatted ?? false; + (parent ?? this).childrenCount++; + + // this.setId(); // NOTE: @eamodio uncomment to track node leaks // queueMicrotask(() => this.view.registerNode(this)); @@ -281,9 +320,38 @@ export abstract class ViewNode< // NOTE: @eamodio uncomment to track node leaks // this.view.unregisterNode(this); } + private _id!: string; + get id(): string { + if (this._id == null) { + // if (!this.splatted) { + this._id = this._uniqueId ?? `${(this.parent ?? this).childrenCount}:${this.type}`; + // } + } + return this._id; + } + + get parentId(): string { + return this.parent?.treeId ?? '~'; + } + + get treeId(): string { + return this.splatted ? this.parentId : `${this.parentId}/${this.id}`; + } - get id(): string | undefined { - return this._uniqueId; + private setId() { + // if (this.splatted) { + // this._id = undefined!; //this.parent?.id ?? '~'; + // } else { + // const { parent } = this; + // const { childrenIds } = parent ?? this; + // this._id = this._uniqueId ?? `${childrenIds.size ?? 0}:${this.type}`; + // if (childrenIds.has(this._id)) { + // debugger; + // // this._id = `${this._id}-${this._uniqueCounter++}`; + // } + // childrenIds.add(this._id); + // } + // console.log('#######', this.type, this.splatted, this._id); } private _context: AmbientContext | undefined; diff --git a/src/views/nodes/autolinkedItemNode.ts b/src/views/nodes/autolinkedItemNode.ts index 67b36e60fd024..55bdff820bfc9 100644 --- a/src/views/nodes/autolinkedItemNode.ts +++ b/src/views/nodes/autolinkedItemNode.ts @@ -22,10 +22,6 @@ export class AutolinkedItemNode extends ViewNode<'autolink', ViewsWithCommits> { this._uniqueId = getViewNodeId(`${this.type}+${item.id}`, this.context); } - override get id(): string { - return this._uniqueId; - } - override async toClipboard(type?: ClipboardType): Promise { const enriched = await this.maybeEnriched; switch (type) { diff --git a/src/views/nodes/autolinkedItemsNode.ts b/src/views/nodes/autolinkedItemsNode.ts index f44c1b162296c..8165ce8aae58d 100644 --- a/src/views/nodes/autolinkedItemsNode.ts +++ b/src/views/nodes/autolinkedItemsNode.ts @@ -30,10 +30,6 @@ export class AutolinkedItemsNode extends CacheableChildrenViewNode<'autolinks', this._uniqueId = getViewNodeId(this.type, this.context); } - override get id(): string { - return this._uniqueId; - } - async getChildren(): Promise { if (this.children == null) { const commits = [...this.log.commits.values()]; diff --git a/src/views/nodes/branchNode.ts b/src/views/nodes/branchNode.ts index f387c3104c23f..62b231ebaff1b 100644 --- a/src/views/nodes/branchNode.ts +++ b/src/views/nodes/branchNode.ts @@ -83,7 +83,9 @@ export class BranchNode super('branch', uri, view, parent, root); this.updateContext({ repository: repo, branch: branch, root: root }); - this._uniqueId = getViewNodeId(this.type, this.context); + // this._uniqueId = getViewNodeId(this.type, this.context); + this._uniqueId = `${this.type}(${this.branch.id})`; + this.limit = this.view.getNodeLastKnownLimit(this); this.options = { @@ -106,10 +108,6 @@ export class BranchNode this.children = undefined; } - override get id(): string { - return this._uniqueId; - } - override toClipboard(): string { return this.branch.name; } diff --git a/src/views/nodes/branchOrTagFolderNode.ts b/src/views/nodes/branchOrTagFolderNode.ts index 61f473419d966..3ba935fa4945a 100644 --- a/src/views/nodes/branchOrTagFolderNode.ts +++ b/src/views/nodes/branchOrTagFolderNode.ts @@ -22,10 +22,6 @@ export class BranchOrTagFolderNode extends ViewNode<'branch-tag-folder'> { this._uniqueId = getViewNodeId(`${this.type}+${folderType}+${relativePath ?? folderName}`, this.context); } - override get id(): string { - return this._uniqueId; - } - override toClipboard(): string { return this.folderName; } diff --git a/src/views/nodes/branchTrackingStatusNode.ts b/src/views/nodes/branchTrackingStatusNode.ts index 5b185c60fb770..9be7f97951bf4 100644 --- a/src/views/nodes/branchTrackingStatusNode.ts +++ b/src/views/nodes/branchTrackingStatusNode.ts @@ -56,14 +56,10 @@ export class BranchTrackingStatusNode branchStatusUpstreamType: upstreamType, root: root, }); - this._uniqueId = getViewNodeId(this.type, this.context); + // this._uniqueId = getViewNodeId(this.type, this.context); this.limit = this.view.getNodeLastKnownLimit(this); } - override get id(): string { - return this._uniqueId; - } - get repoPath(): string { return this.uri.repoPath!; } diff --git a/src/views/nodes/branchesNode.ts b/src/views/nodes/branchesNode.ts index ed31b4f4e294f..0c888c182fee7 100644 --- a/src/views/nodes/branchesNode.ts +++ b/src/views/nodes/branchesNode.ts @@ -25,10 +25,6 @@ export class BranchesNode extends CacheableChildrenViewNode<'branches', ViewsWit this._uniqueId = getViewNodeId(this.type, this.context); } - override get id(): string { - return this._uniqueId; - } - get repoPath(): string { return this.repo.path; } diff --git a/src/views/nodes/codeSuggestionsNode.ts b/src/views/nodes/codeSuggestionsNode.ts index 860dd3b232fba..be67fd6ebeea3 100644 --- a/src/views/nodes/codeSuggestionsNode.ts +++ b/src/views/nodes/codeSuggestionsNode.ts @@ -20,10 +20,6 @@ export class CodeSuggestionsNode extends CacheableChildrenViewNode<'drafts-code- this._uniqueId = getViewNodeId(this.type, this.context); } - override get id(): string { - return this._uniqueId; - } - async getChildren(): Promise { if (this.children == null) { const drafts = await this.getSuggestedChanges(); diff --git a/src/views/nodes/commitFileNode.ts b/src/views/nodes/commitFileNode.ts index 54ff6e3b4fac4..de245ab03af4f 100644 --- a/src/views/nodes/commitFileNode.ts +++ b/src/views/nodes/commitFileNode.ts @@ -39,11 +39,9 @@ export abstract class CommitFileNodeBase< super(type, GitUri.fromFile(file, commit.repoPath, commit.sha), view, parent, file); this.updateContext({ commit: commit, file: file }); - this._uniqueId = getViewNodeId(type, this.context); - } + this._uniqueId = `${this.type}(${this.commit.repoPath}|${this.commit.sha}:${this.file.path}+${this.file.status})`; - override get id(): string { - return this._uniqueId; + // this._uniqueId = getViewNodeId(type, this.context); } override toClipboard(): string { diff --git a/src/views/nodes/commitNode.ts b/src/views/nodes/commitNode.ts index 38b0bdb210712..b6be455c9ce00 100644 --- a/src/views/nodes/commitNode.ts +++ b/src/views/nodes/commitNode.ts @@ -54,10 +54,6 @@ export class CommitNode extends ViewRefNode<'commit', ViewsWithCommits | FileHis this.children = undefined; } - override get id(): string { - return this._uniqueId; - } - override toClipboard(): string { return `${this.commit.shortSha}: ${this.commit.summary}`; } diff --git a/src/views/nodes/compareResultsNode.ts b/src/views/nodes/compareResultsNode.ts index 2024cad04585c..4ba4a3926b6be 100644 --- a/src/views/nodes/compareResultsNode.ts +++ b/src/views/nodes/compareResultsNode.ts @@ -58,10 +58,6 @@ export class CompareResultsNode extends SubscribeableViewNode< } } - override get id(): string { - return this._uniqueId; - } - protected override etag(): number { return this._storedAt; } diff --git a/src/views/nodes/contributorNode.ts b/src/views/nodes/contributorNode.ts index a46f5d7769502..bdcdda8846293 100644 --- a/src/views/nodes/contributorNode.ts +++ b/src/views/nodes/contributorNode.ts @@ -39,10 +39,6 @@ export class ContributorNode extends ViewNode<'contributor', ViewsWithContributo this.limit = this.view.getNodeLastKnownLimit(this); } - override get id(): string { - return this._uniqueId; - } - override toClipboard(type?: ClipboardType): string { const text = `${this.contributor.name}${this.contributor.email ? ` <${this.contributor.email}>` : ''}`; switch (type) { diff --git a/src/views/nodes/contributorsNode.ts b/src/views/nodes/contributorsNode.ts index d243de51dc9df..bc0079596a4cf 100644 --- a/src/views/nodes/contributorsNode.ts +++ b/src/views/nodes/contributorsNode.ts @@ -30,10 +30,6 @@ export class ContributorsNode extends CacheableChildrenViewNode< this._uniqueId = getViewNodeId(this.type, this.context); } - override get id(): string { - return this._uniqueId; - } - get repoPath(): string { return this.repo.path; } diff --git a/src/views/nodes/draftNode.ts b/src/views/nodes/draftNode.ts index 4461660542366..b8612c129f1ad 100644 --- a/src/views/nodes/draftNode.ts +++ b/src/views/nodes/draftNode.ts @@ -22,10 +22,6 @@ export class DraftNode extends ViewNode<'draft', ViewsWithCommits | DraftsView> this._uniqueId = getViewNodeId(this.type, this.context); } - override get id(): string { - return this._uniqueId; - } - override toClipboard(): string { return this.getUrl(); } diff --git a/src/views/nodes/fileHistoryNode.ts b/src/views/nodes/fileHistoryNode.ts index 5b235a1cc48b1..5a0fbfeff809f 100644 --- a/src/views/nodes/fileHistoryNode.ts +++ b/src/views/nodes/fileHistoryNode.ts @@ -45,10 +45,6 @@ export class FileHistoryNode this.limit = this.view.getNodeLastKnownLimit(this); } - override get id(): string { - return this._uniqueId; - } - override toClipboard(): string { return this.uri.fileName; } diff --git a/src/views/nodes/fileRevisionAsCommitNode.ts b/src/views/nodes/fileRevisionAsCommitNode.ts index a1f13b41eef33..fb68e052f3cd2 100644 --- a/src/views/nodes/fileRevisionAsCommitNode.ts +++ b/src/views/nodes/fileRevisionAsCommitNode.ts @@ -42,6 +42,8 @@ export class FileRevisionAsCommitNode extends ViewRefFileNode< } = {}, ) { super('file-commit', GitUri.fromFile(file, commit.repoPath, commit.sha), view, parent, file); + + this._uniqueId = `${this.type}(${this.commit.repoPath}|${this.commit.sha}:${this.file.path}+${this.file.status})`; } override toClipboard(): string { diff --git a/src/views/nodes/folderNode.ts b/src/views/nodes/folderNode.ts index cb03e6c452a42..8b7018ac99ec9 100644 --- a/src/views/nodes/folderNode.ts +++ b/src/views/nodes/folderNode.ts @@ -35,10 +35,6 @@ export class FolderNode extends ViewNode<'folder', ViewsWithCommits | StashesVie this._uniqueId = getViewNodeId(`${this.type}+${relativePath ?? folderName}`, this.context); } - override get id(): string { - return this._uniqueId; - } - override toClipboard(): string { return this.folderName; } diff --git a/src/views/nodes/lineHistoryNode.ts b/src/views/nodes/lineHistoryNode.ts index 18b63afb9cc4b..ad19f75a7eb4c 100644 --- a/src/views/nodes/lineHistoryNode.ts +++ b/src/views/nodes/lineHistoryNode.ts @@ -52,10 +52,6 @@ export class LineHistoryNode this.limit = this.view.getNodeLastKnownLimit(this); } - override get id(): string { - return this._uniqueId; - } - override toClipboard(): string { return this.uri.fileName; } diff --git a/src/views/nodes/pullRequestNode.ts b/src/views/nodes/pullRequestNode.ts index f67f4bd5a247c..5df1741411465 100644 --- a/src/views/nodes/pullRequestNode.ts +++ b/src/views/nodes/pullRequestNode.ts @@ -53,12 +53,10 @@ export class PullRequestNode extends CacheableChildrenViewNode<'pullrequest', Vi } this.updateContext({ pullRequest: pullRequest }); - this._uniqueId = getViewNodeId(this.type, this.context); - this.repoPath = repoPath; - } + // this._uniqueId = getViewNodeId(this.type, this.context); + this._uniqueId = `${this.type}(${this.pullRequest.url})`; - override get id(): string { - return this._uniqueId; + this.repoPath = repoPath; } override toClipboard(type?: ClipboardType): string { diff --git a/src/views/nodes/reflogNode.ts b/src/views/nodes/reflogNode.ts index 2672ac7166996..ba7b5eb027fa9 100644 --- a/src/views/nodes/reflogNode.ts +++ b/src/views/nodes/reflogNode.ts @@ -30,10 +30,6 @@ export class ReflogNode this.limit = this.view.getNodeLastKnownLimit(this); } - override get id(): string { - return this._uniqueId; - } - async getChildren(): Promise { if (this.children === undefined) { const children = []; diff --git a/src/views/nodes/reflogRecordNode.ts b/src/views/nodes/reflogRecordNode.ts index 7774d9878db08..df051186f092c 100644 --- a/src/views/nodes/reflogRecordNode.ts +++ b/src/views/nodes/reflogRecordNode.ts @@ -27,10 +27,6 @@ export class ReflogRecordNode extends ViewNode<'reflog-record', ViewsWithCommits this.limit = this.view.getNodeLastKnownLimit(this); } - override get id(): string { - return this._uniqueId; - } - async getChildren(): Promise { const log = await this.getLog(); if (log === undefined) return [new MessageNode(this.view, this, 'No commits could be found.')]; diff --git a/src/views/nodes/remoteNode.ts b/src/views/nodes/remoteNode.ts index cbf0f1842a394..ce1fbf355131b 100644 --- a/src/views/nodes/remoteNode.ts +++ b/src/views/nodes/remoteNode.ts @@ -27,10 +27,6 @@ export class RemoteNode extends ViewNode<'remote', ViewsWithRemotes> { this._uniqueId = getViewNodeId(this.type, this.context); } - override get id(): string { - return this._uniqueId; - } - override toClipboard(): string { return this.remote.name; } diff --git a/src/views/nodes/remotesNode.ts b/src/views/nodes/remotesNode.ts index 0dc945dd1847d..5e18678e14c8d 100644 --- a/src/views/nodes/remotesNode.ts +++ b/src/views/nodes/remotesNode.ts @@ -22,10 +22,6 @@ export class RemotesNode extends CacheableChildrenViewNode<'remotes', ViewsWithR this._uniqueId = getViewNodeId(this.type, this.context); } - override get id(): string { - return this._uniqueId; - } - get repoPath(): string { return this.repo.path; } diff --git a/src/views/nodes/repositoryNode.ts b/src/views/nodes/repositoryNode.ts index 93cceb98070f8..30c621db448fd 100644 --- a/src/views/nodes/repositoryNode.ts +++ b/src/views/nodes/repositoryNode.ts @@ -58,10 +58,6 @@ export class RepositoryNode extends SubscribeableViewNode<'repository', ViewsWit this._status = this.repo.git.getStatus(); } - override get id(): string { - return this._uniqueId; - } - override toClipboard(): string { return this.repo.path; } diff --git a/src/views/nodes/resultsCommitsNode.ts b/src/views/nodes/resultsCommitsNode.ts index b78f84074b796..27089d436990b 100644 --- a/src/views/nodes/resultsCommitsNode.ts +++ b/src/views/nodes/resultsCommitsNode.ts @@ -62,10 +62,6 @@ export class ResultsCommitsNode this.limit = this.view.getNodeLastKnownLimit(this); } - override get id(): string { - return this._uniqueId; - } - override toClipboard(): string { return this.tag.name; } diff --git a/src/views/nodes/tagsNode.ts b/src/views/nodes/tagsNode.ts index bd2a42d2f1ef5..279282e076561 100644 --- a/src/views/nodes/tagsNode.ts +++ b/src/views/nodes/tagsNode.ts @@ -24,10 +24,6 @@ export class TagsNode extends CacheableChildrenViewNode<'tags', ViewsWithTagsNod this._uniqueId = getViewNodeId(this.type, this.context); } - override get id(): string { - return this._uniqueId; - } - get repoPath(): string { return this.repo.path; } diff --git a/src/views/nodes/workspaceMissingRepositoryNode.ts b/src/views/nodes/workspaceMissingRepositoryNode.ts index ebac55b05344f..bac8a9f00647b 100644 --- a/src/views/nodes/workspaceMissingRepositoryNode.ts +++ b/src/views/nodes/workspaceMissingRepositoryNode.ts @@ -24,10 +24,6 @@ export class WorkspaceMissingRepositoryNode extends ViewNode<'workspace-missing- this._uniqueId = getViewNodeId(this.type, this.context); } - override get id(): string { - return this._uniqueId; - } - override toClipboard(): string { return this.name; } diff --git a/src/views/nodes/workspaceNode.ts b/src/views/nodes/workspaceNode.ts index 2ea5452636474..bd3448ed0a6ea 100644 --- a/src/views/nodes/workspaceNode.ts +++ b/src/views/nodes/workspaceNode.ts @@ -31,10 +31,6 @@ export class WorkspaceNode extends SubscribeableViewNode< this._uniqueId = getViewNodeId(this.type, this.context); } - override get id(): string { - return this._uniqueId; - } - override toClipboard(): string { return this.workspace.name; } diff --git a/src/views/nodes/worktreeNode.ts b/src/views/nodes/worktreeNode.ts index 857dc222eb296..10fa2e983e1ed 100644 --- a/src/views/nodes/worktreeNode.ts +++ b/src/views/nodes/worktreeNode.ts @@ -53,10 +53,6 @@ export class WorktreeNode extends CacheableChildrenViewNode<'worktree', ViewsWit this.limit = this.view.getNodeLastKnownLimit(this); } - override get id(): string { - return this._uniqueId; - } - override toClipboard(): string { return this.worktree.uri.fsPath; } diff --git a/src/views/nodes/worktreesNode.ts b/src/views/nodes/worktreesNode.ts index 46c6d0b8f105f..9bfdaac6ec4e8 100644 --- a/src/views/nodes/worktreesNode.ts +++ b/src/views/nodes/worktreesNode.ts @@ -28,10 +28,6 @@ export class WorktreesNode extends CacheableChildrenViewNode<'worktrees', ViewsW this._uniqueId = getViewNodeId(this.type, this.context); } - override get id(): string { - return this._uniqueId; - } - get repoPath(): string { return this.repo.path; } diff --git a/src/views/viewBase.ts b/src/views/viewBase.ts index 9d2ad519dda1c..dd58206c3d35e 100644 --- a/src/views/viewBase.ts +++ b/src/views/viewBase.ts @@ -426,13 +426,21 @@ export abstract class ViewBase< if (this.root == null || force) { this.root?.dispose(); this.root = this.getRoot(); + // if (this.root.childrenIds.size > 0) { + // debugger; + // this.root.childrenIds.clear(); + // } } return this.root; } getChildren(node?: ViewNode): ViewNode[] | Promise { - if (node != null) return node.getChildren(); + if (node != null) { + // node.childrenIds.clear(); + node.childrenCount = 0; + return node.getChildren(); + } const root = this.ensureRoot(); const children = root.getChildren(); @@ -462,7 +470,20 @@ export abstract class ViewBase< debugger; node.splatted = false; } - return node.getTreeItem(); + + const item = node.getTreeItem(); + if (isPromise(item)) { + return item.then(i => { + i.id = node.treeId; + console.log('#######', node.type, node.splatted, node.id, i.id); + + return i; + }); + } + + item.id = node.treeId; + console.log('#######', node.type, node.splatted, node.id, item.id); + return item; } getViewDescription(count?: number) {