Skip to content

Commit ed48f63

Browse files
committed
Improves splat tracking (now automatic)
Improves view initialization & reveal
1 parent 6ab7426 commit ed48f63

23 files changed

+125
-87
lines changed

src/views/branchesView.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class BranchesViewNode extends RepositoriesSubscribeableNode<BranchesView
6464
}
6565

6666
let repositories = this.view.container.git.openRepositories;
67-
if (repositories.length === 0) {
67+
if (!repositories.length) {
6868
this.view.message = 'No branches could be found.';
6969
return [];
7070
}
@@ -80,9 +80,8 @@ export class BranchesViewNode extends RepositoriesSubscribeableNode<BranchesView
8080
worktreesByBranch: worktreesByBranch?.size ? worktreesByBranch : undefined,
8181
});
8282

83-
const splat = repositories.length === 1;
8483
this.children = repositories.map(
85-
r => new BranchesRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, splat, r),
84+
r => new BranchesRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r),
8685
);
8786
}
8887

@@ -98,7 +97,7 @@ export class BranchesViewNode extends RepositoriesSubscribeableNode<BranchesView
9897
filter: b =>
9998
!b.remote || (showRemoteBranches && defaultRemote != null && b.getRemoteName() === defaultRemote),
10099
});
101-
if (branches.values.length === 0) {
100+
if (!branches.values.length) {
102101
this.view.message = 'No branches could be found.';
103102
void child.ensureSubscription();
104103

src/views/commitsView.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,15 @@ export class CommitsViewNode extends RepositoriesSubscribeableNode<CommitsView,
137137
}
138138

139139
const repositories = this.view.container.git.openRepositories;
140-
if (repositories.length === 0) {
140+
if (!repositories.length) {
141141
this.view.message = 'No commits could be found.';
142142

143143
return [];
144144
}
145145

146-
const splat = repositories.length === 1;
147146
this.children = repositories.map(
148147
r =>
149-
new CommitsRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, splat, r, {
148+
new CommitsRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, {
150149
showBranchAndLastFetched: true,
151150
}),
152151
);

src/views/contributorsView.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class ContributorsViewNode extends RepositoriesSubscribeableNode<Contribu
6565
}
6666

6767
let repositories = this.view.container.git.openRepositories;
68-
if (repositories.length === 0) {
68+
if (!repositories.length) {
6969
this.view.message = 'No contributors could be found.';
7070
return [];
7171
}
@@ -78,9 +78,8 @@ export class ContributorsViewNode extends RepositoriesSubscribeableNode<Contribu
7878
repositories = [...grouped.keys()];
7979
}
8080

81-
const splat = repositories.length === 1;
8281
this.children = repositories.map(
83-
r => new ContributorsRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, splat, r),
82+
r => new ContributorsRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r),
8483
);
8584
}
8685

@@ -103,7 +102,7 @@ export class ContributorsViewNode extends RepositoriesSubscribeableNode<Contribu
103102
// }
104103

105104
// const contributors = await child.repo.getContributors({ all: all, ref: ref });
106-
if (children.length === 0) {
105+
if (!children.length) {
107106
this.view.message = 'No contributors could be found.';
108107
void child.ensureSubscription();
109108

src/views/nodes/abstract/repositoriesSubscribeableNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export abstract class RepositoriesSubscribeableNode<
1414
TChild extends ViewNode = ViewNode,
1515
> extends SubscribeableViewNode<'repositories', TView, TChild> {
1616
constructor(view: TView) {
17-
super('repositories', unknownGitUri, view, undefined, true);
17+
super('repositories', unknownGitUri, view);
1818
}
1919

2020
override async getSplattedChild(): Promise<TChild | undefined> {

src/views/nodes/abstract/repositoryFolderNode.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ export abstract class RepositoryFolderNode<
2424
uri: GitUri,
2525
view: TView,
2626
protected override readonly parent: ViewNode,
27-
splatted: boolean,
2827
public readonly repo: Repository,
2928
private readonly options?: { showBranchAndLastFetched?: boolean },
3029
) {
31-
super('repo-folder', uri, view, parent, splatted);
30+
super('repo-folder', uri, view, parent);
3231

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

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, splatted?: boolean) {
25-
super(type, uri, view, parent, splatted);
24+
constructor(type: Type, uri: GitUri, view: TView, parent?: ViewNode) {
25+
super(type, uri, view, parent);
2626

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

src/views/nodes/abstract/viewNode.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export function getViewNodeId(type: string, context: AmbientContext): string {
157157
uniqueness += `/worktree/${context.worktree.uri.path}`;
158158
}
159159
if (context.remote != null) {
160-
uniqueness += `/remote/${context.remote.name}`;
160+
uniqueness += `/remote/${context.remote.id}`;
161161
}
162162
if (context.tag != null) {
163163
uniqueness += `/tag/${context.tag.id}`;
@@ -237,25 +237,35 @@ export abstract class ViewNode<
237237
return types.includes(this.type as unknown as T[number]);
238238
}
239239

240-
protected _uniqueId!: string;
241-
splatted = false;
240+
splatted: boolean | undefined;
241+
242242
// NOTE: @eamodio uncomment to track node leaks
243243
// readonly uuid = uuid();
244244

245+
protected _uniqueId!: string;
246+
245247
constructor(
246248
public readonly type: Type,
247249
// public readonly id: string | undefined,
248250
uri: GitUri,
249251
public readonly view: TView,
250252
protected parent?: ViewNode | undefined,
251-
//** Indicates if this node is only shown as its children, not itself */
252-
splatted?: boolean,
253253
) {
254-
this.splatted = splatted ?? false;
255-
256254
// NOTE: @eamodio uncomment to track node leaks
257255
// queueMicrotask(() => this.view.registerNode(this));
258256
this._uri = uri;
257+
258+
const originalGetChildren = this.getChildren;
259+
this.getChildren = function (this: ViewNode) {
260+
this.splatted ??= true;
261+
return originalGetChildren.call(this);
262+
};
263+
264+
const originalGetTreeItem = this.getTreeItem;
265+
this.getTreeItem = function (this: ViewNode) {
266+
this.splatted = false;
267+
return originalGetTreeItem.call(this);
268+
};
259269
}
260270

261271
protected _disposed = false;

src/views/nodes/abstract/viewRefNode.ts

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

2524
abstract get ref(): TReference;

src/views/nodes/branchNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class BranchNode
8282
public readonly root: boolean,
8383
options?: Partial<Options>,
8484
) {
85-
super('branch', uri, view, parent, root);
85+
super('branch', uri, view, parent);
8686

8787
this.updateContext({ repository: repo, branch: branch, root: root });
8888
this._uniqueId = getViewNodeId(this.type, this.context);

src/views/nodes/branchesNode.ts

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

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

0 commit comments

Comments
 (0)