Skip to content

Commit 097c74f

Browse files
committed
Consolidates view node splatting
1 parent ba5dfbb commit 097c74f

23 files changed

+49
-73
lines changed

src/views/branchesView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class BranchesViewNode extends RepositoriesSubscribeableNode<BranchesView
7676

7777
const splat = repositories.length === 1;
7878
this.children = repositories.map(
79-
r => new BranchesRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, splat),
79+
r => new BranchesRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, splat, r),
8080
);
8181
}
8282

src/views/commitsView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export class CommitsViewNode extends RepositoriesSubscribeableNode<CommitsView,
136136
const splat = repositories.length === 1;
137137
this.children = repositories.map(
138138
r =>
139-
new CommitsRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, splat, {
139+
new CommitsRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, splat, r, {
140140
showBranchAndLastFetched: true,
141141
}),
142142
);

src/views/contributorsView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class ContributorsViewNode extends RepositoriesSubscribeableNode<Contribu
7676

7777
const splat = repositories.length === 1;
7878
this.children = repositories.map(
79-
r => new ContributorsRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, splat),
79+
r => new ContributorsRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, splat, r),
8080
);
8181
}
8282

src/views/nodes/abstract/repositoriesSubscribeableNode.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ export abstract class RepositoriesSubscribeableNode<
1313
TView extends View = View,
1414
TChild extends ViewNode = ViewNode,
1515
> extends SubscribeableViewNode<'repositories', TView, TChild> {
16-
protected override splatted = true;
17-
1816
constructor(view: TView) {
19-
super('repositories', unknownGitUri, view);
17+
super('repositories', unknownGitUri, view, undefined, true);
2018
}
2119

2220
override async getSplattedChild() {

src/views/nodes/abstract/repositoryFolderNode.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,18 @@ export abstract class RepositoryFolderNode<
1919
TView extends View = View,
2020
TChild extends ViewNode = ViewNode,
2121
> extends SubscribeableViewNode<'repo-folder', TView> {
22-
protected override splatted = true;
23-
2422
constructor(
2523
uri: GitUri,
2624
view: TView,
2725
protected override readonly parent: ViewNode,
28-
public readonly repo: Repository,
2926
splatted: boolean,
27+
public readonly repo: Repository,
3028
private readonly options?: { showBranchAndLastFetched?: boolean },
3129
) {
32-
super('repo-folder', uri, view, parent);
30+
super('repo-folder', uri, view, parent, splatted);
3331

3432
this.updateContext({ repository: this.repo });
3533
this._uniqueId = getViewNodeId(this.type, this.context);
36-
37-
this.splatted = splatted;
3834
}
3935

4036
private _child: TChild | undefined;
@@ -66,8 +62,6 @@ export abstract class RepositoryFolderNode<
6662
}
6763

6864
async getTreeItem(): Promise<TreeItem> {
69-
this.splatted = false;
70-
7165
const branch = await this.repo.git.getBranch();
7266
const ahead = (branch?.state.ahead ?? 0) > 0;
7367
const behind = (branch?.state.behind ?? 0) > 0;

src/views/nodes/abstract/subscribeableViewNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export abstract class SubscribeableViewNode<
2121

2222
protected loaded: boolean = false;
2323

24-
constructor(type: Type, uri: GitUri, view: TView, parent?: ViewNode) {
25-
super(type, uri, view, parent);
24+
constructor(type: Type, uri: GitUri, view: TView, parent?: ViewNode, splatted?: boolean) {
25+
super(type, uri, view, parent, splatted);
2626

2727
const disposables = [
2828
weakEvent(this.view.onDidChangeVisibility, this.onVisibilityChanged, this),

src/views/nodes/abstract/viewNode.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ export abstract class ViewNode<
253253
}
254254

255255
protected _uniqueId!: string;
256-
protected splatted = false;
256+
splatted = false;
257257
// NOTE: @eamodio uncomment to track node leaks
258258
// readonly uuid = uuid();
259259

@@ -262,8 +262,12 @@ export abstract class ViewNode<
262262
// public readonly id: string | undefined,
263263
uri: GitUri,
264264
public readonly view: TView,
265-
protected parent?: ViewNode,
265+
protected parent?: ViewNode | undefined,
266+
//** Indicates if this node is only shown as its children, not itself */
267+
splatted?: boolean,
266268
) {
269+
this.splatted = splatted ?? false;
270+
267271
// NOTE: @eamodio uncomment to track node leaks
268272
// queueMicrotask(() => this.view.registerNode(this));
269273
this._uri = uri;
@@ -339,32 +343,36 @@ export abstract class ViewNode<
339343

340344
getSplattedChild?(): Promise<ViewNode | undefined>;
341345

346+
protected get storedId(): string | undefined {
347+
return this.id;
348+
}
349+
342350
deleteState<T extends StateKey<State> = StateKey<State>>(key?: T): void {
343-
if (this.id == null) {
351+
if (this.storedId == null) {
344352
debugger;
345353
throw new Error('Id is required to delete state');
346354
}
347-
this.view.nodeState.deleteState(this.id, key as string);
355+
this.view.nodeState.deleteState(this.storedId, key as string);
348356
}
349357

350358
getState<T extends StateKey<State> = StateKey<State>>(key: T): StateValue<State, T> | undefined {
351-
if (this.id == null) {
359+
if (this.storedId == null) {
352360
debugger;
353361
throw new Error('Id is required to get state');
354362
}
355-
return this.view.nodeState.getState(this.id, key as string);
363+
return this.view.nodeState.getState(this.storedId, key as string);
356364
}
357365

358366
storeState<T extends StateKey<State> = StateKey<State>>(
359367
key: T,
360368
value: StateValue<State, T>,
361369
sticky?: boolean,
362370
): void {
363-
if (this.id == null) {
371+
if (this.storedId == null) {
364372
debugger;
365373
throw new Error('Id is required to store state');
366374
}
367-
this.view.nodeState.storeState(this.id, key as string, value, sticky);
375+
this.view.nodeState.storeState(this.storedId, key as string, value, sticky);
368376
}
369377
}
370378

src/views/nodes/abstract/viewRefNode.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ export abstract class ViewRefNode<
1717
uri: GitUri,
1818
view: TView,
1919
protected override readonly parent: ViewNode,
20+
splatted?: boolean,
2021
) {
21-
super(type, uri, view, parent);
22+
super(type, uri, view, parent, splatted);
2223
}
2324

2425
abstract get ref(): TReference;

src/views/nodes/branchNode.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ export class BranchNode
6969
limit: number | undefined;
7070

7171
private readonly options: Options;
72-
protected override splatted = true;
7372

7473
constructor(
7574
uri: GitUri,
@@ -81,7 +80,7 @@ export class BranchNode
8180
public readonly root: boolean,
8281
options?: Partial<Options>,
8382
) {
84-
super('branch', uri, view, parent);
83+
super('branch', uri, view, parent, root);
8584

8685
this.updateContext({ repository: repo, branch: branch, root: root });
8786
this._uniqueId = getViewNodeId(this.type, this.context);
@@ -418,8 +417,6 @@ export class BranchNode
418417
}
419418

420419
async getTreeItem(): Promise<TreeItem> {
421-
this.splatted = false;
422-
423420
const parts = await getBranchNodeParts(this.view.container, this.branch, this.current, {
424421
pendingPullRequest: this.getState('pendingPullRequest'),
425422
showAsCommits: this.options.showAsCommits,

src/views/nodes/branchesNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class BranchesNode extends CacheableChildrenViewNode<'branches', ViewsWit
1919
protected override readonly parent: ViewNode,
2020
public readonly repo: Repository,
2121
) {
22-
super('branches', uri, view, parent);
22+
super('branches', uri, view, parent, true);
2323

2424
this.updateContext({ repository: repo });
2525
this._uniqueId = getViewNodeId(this.type, this.context);

src/views/nodes/contributorsNode.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@ export class ContributorsNode extends CacheableChildrenViewNode<
1717
ViewsWithContributorsNode,
1818
ContributorNode
1919
> {
20-
protected override splatted = true;
21-
2220
constructor(
2321
uri: GitUri,
2422
view: ViewsWithContributorsNode,
2523
protected override readonly parent: ViewNode,
2624
public readonly repo: Repository,
2725
private readonly options?: { all?: boolean; showMergeCommits?: boolean; stats?: boolean },
2826
) {
29-
super('contributors', uri, view, parent);
27+
super('contributors', uri, view, parent, true);
3028

3129
this.updateContext({ repository: repo });
3230
this._uniqueId = getViewNodeId(this.type, this.context);
@@ -83,8 +81,6 @@ export class ContributorsNode extends CacheableChildrenViewNode<
8381
}
8482

8583
getTreeItem(): TreeItem {
86-
this.splatted = false;
87-
8884
const item = new TreeItem('Contributors', TreeItemCollapsibleState.Collapsed);
8985
item.id = this.id;
9086
item.contextValue = ContextValues.Contributors;

src/views/nodes/fileHistoryNode.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,14 @@ export class FileHistoryNode
2929
{
3030
limit: number | undefined;
3131

32-
protected override splatted = true;
33-
3432
constructor(
3533
uri: GitUri,
3634
view: FileHistoryView,
3735
protected override readonly parent: ViewNode,
3836
private readonly folder: boolean,
3937
private readonly branch: GitBranch | undefined,
4038
) {
41-
super('file-history', uri, view, parent);
39+
super('file-history', uri, view, parent, true);
4240

4341
if (branch != null) {
4442
this.updateContext({ branch: branch });
@@ -148,8 +146,6 @@ export class FileHistoryNode
148146
}
149147

150148
getTreeItem(): TreeItem {
151-
this.splatted = false;
152-
153149
const label = this.label;
154150
const item = new TreeItem(label, TreeItemCollapsibleState.Expanded);
155151
item.contextValue = ContextValues.FileHistory;

src/views/nodes/fileHistoryTrackerNode.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ import { FileHistoryNode } from './fileHistoryNode';
2222

2323
export class FileHistoryTrackerNode extends SubscribeableViewNode<'file-history-tracker', FileHistoryView> {
2424
private _base: string | undefined;
25-
protected override splatted = true;
2625

2726
constructor(view: FileHistoryView) {
28-
super('file-history-tracker', unknownGitUri, view);
27+
super('file-history-tracker', unknownGitUri, view, undefined, true);
2928
}
3029

3130
override dispose() {
@@ -85,8 +84,6 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode<'file-history-
8584
}
8685

8786
getTreeItem(): TreeItem {
88-
this.splatted = false;
89-
9087
const item = new TreeItem('File History', TreeItemCollapsibleState.Expanded);
9188
item.contextValue = ContextValues.ActiveFileHistory;
9289

src/views/nodes/lineHistoryNode.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ export class LineHistoryNode
3030
{
3131
limit: number | undefined;
3232

33-
protected override splatted = true;
34-
3533
constructor(
3634
uri: GitUri,
3735
view: FileHistoryView | LineHistoryView,
@@ -40,7 +38,7 @@ export class LineHistoryNode
4038
public readonly selection: Selection,
4139
private readonly editorContents: string | undefined,
4240
) {
43-
super('line-history', uri, view, parent);
41+
super('line-history', uri, view, parent, true);
4442

4543
if (branch != null) {
4644
this.updateContext({ branch: branch });
@@ -163,8 +161,6 @@ export class LineHistoryNode
163161
}
164162

165163
getTreeItem(): TreeItem {
166-
this.splatted = false;
167-
168164
const label = this.label;
169165
const item = new TreeItem(label, TreeItemCollapsibleState.Expanded);
170166
item.contextValue = ContextValues.LineHistory;

src/views/nodes/lineHistoryTrackerNode.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ export class LineHistoryTrackerNode extends SubscribeableViewNode<
2828
private _base: string | undefined;
2929
private _editorContents: string | undefined;
3030
private _selection: Selection | undefined;
31-
protected override splatted = true;
3231

3332
constructor(view: FileHistoryView | LineHistoryView) {
34-
super('line-history-tracker', unknownGitUri, view);
33+
super('line-history-tracker', unknownGitUri, view, undefined, true);
3534
}
3635

3736
override dispose() {
@@ -96,8 +95,6 @@ export class LineHistoryTrackerNode extends SubscribeableViewNode<
9695
}
9796

9897
getTreeItem(): TreeItem {
99-
this.splatted = false;
100-
10198
const item = new TreeItem('Line History', TreeItemCollapsibleState.Expanded);
10299
item.contextValue = ContextValues.ActiveLineHistory;
103100

src/views/nodes/resultsCommitsNode.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class ResultsCommitsNode<View extends ViewsWithCommits = ViewsWithCommits
5151
options?: Partial<Options>,
5252
splatted?: boolean,
5353
) {
54-
super('results-commits', GitUri.fromRepoPath(repoPath), view, parent);
54+
super('results-commits', GitUri.fromRepoPath(repoPath), view, parent, splatted);
5555

5656
if (_results.direction != null) {
5757
this.updateContext({ branchStatusUpstreamType: _results.direction });
@@ -60,9 +60,6 @@ export class ResultsCommitsNode<View extends ViewsWithCommits = ViewsWithCommits
6060
this.limit = this.view.getNodeLastKnownLimit(this);
6161

6262
this._options = { autolinks: true, expand: true, ...options };
63-
if (splatted != null) {
64-
this.splatted = splatted;
65-
}
6663
}
6764

6865
override get id(): string {

src/views/nodes/worktreeNode.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,6 @@ export class WorktreeNode extends CacheableChildrenViewNode<'worktree', ViewsWit
190190
}
191191

192192
async getTreeItem(): Promise<TreeItem> {
193-
this.splatted = false;
194-
195193
let description = '';
196194
let icon: IconPath | undefined;
197195
let hasChanges = false;

src/views/remotesView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class RemotesViewNode extends RepositoriesSubscribeableNode<RemotesView,
6868

6969
const splat = repositories.length === 1;
7070
this.children = repositories.map(
71-
r => new RemotesRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, splat),
71+
r => new RemotesRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, splat, r),
7272
);
7373
}
7474

src/views/searchAndCompareView.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ import { disposeChildren, ViewBase } from './viewBase';
2929
import { registerViewCommand } from './viewCommands';
3030

3131
export class SearchAndCompareViewNode extends ViewNode<'search-compare', SearchAndCompareView> {
32-
protected override splatted = true;
3332
private comparePicker: ComparePickerNode | undefined;
3433

3534
constructor(view: SearchAndCompareView) {
36-
super('search-compare', unknownGitUri, view);
35+
super('search-compare', unknownGitUri, view, undefined, true);
3736
}
3837

3938
override dispose() {
@@ -73,8 +72,6 @@ export class SearchAndCompareViewNode extends ViewNode<'search-compare', SearchA
7372
}
7473

7574
getTreeItem(): TreeItem {
76-
this.splatted = false;
77-
7875
const item = new TreeItem('SearchAndCompare', TreeItemCollapsibleState.Expanded);
7976
item.contextValue = ContextValues.SearchAndCompare;
8077
return item;

src/views/stashesView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class StashesViewNode extends RepositoriesSubscribeableNode<StashesView,
5454

5555
const splat = repositories.length === 1;
5656
this.children = repositories.map(
57-
r => new StashesRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, splat),
57+
r => new StashesRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, splat, r),
5858
);
5959
}
6060

src/views/tagsView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class TagsViewNode extends RepositoriesSubscribeableNode<TagsView, TagsRe
5555

5656
const splat = repositories.length === 1;
5757
this.children = repositories.map(
58-
r => new TagsRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, splat),
58+
r => new TagsRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, splat, r),
5959
);
6060
}
6161

0 commit comments

Comments
 (0)