Skip to content

Commit b6b8f36

Browse files
committed
Adds type discriminator to ViewNode
1 parent 92e37bd commit b6b8f36

56 files changed

Lines changed: 426 additions & 342 deletions

Some content is hidden

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

src/constants.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,63 @@ export const viewIdsByDefaultContainerId = new Map<ViewContainerIds | CoreViewCo
509509
['workbench.view.extension.gitlens', ['home', 'workspaces', 'account']],
510510
]);
511511

512+
export type TreeViewRefNodeTypes = 'branch' | 'commit' | 'stash' | 'tag';
513+
export type TreeViewRefFileNodeTypes = 'commit-file' | 'file-commit' | 'results-file' | 'stash-file';
514+
export type TreeViewFileNodeTypes =
515+
| TreeViewRefFileNodeTypes
516+
| 'conflict-file'
517+
| 'folder'
518+
| 'status-file'
519+
| 'uncommitted-file';
520+
export type TreeViewSubscribableNodeTypes =
521+
| 'compare-branch'
522+
| 'compare-results'
523+
| 'file-history'
524+
| 'file-history-tracker'
525+
| 'line-history'
526+
| 'line-history-tracker'
527+
| 'repositories'
528+
| 'repository'
529+
| 'repository-folder'
530+
| 'search-results'
531+
| 'workspace';
532+
export type TreeViewNodeTypes =
533+
| TreeViewRefNodeTypes
534+
| TreeViewFileNodeTypes
535+
| TreeViewSubscribableNodeTypes
536+
| 'autolink'
537+
| 'autolinks'
538+
| 'branch-tag-folder'
539+
| 'branches'
540+
| 'compare-picker'
541+
| 'contributor'
542+
| 'contributors'
543+
| 'conflict-files'
544+
| 'conflict-current-changes'
545+
| 'conflict-incoming-changes'
546+
| 'merge-status'
547+
| 'message'
548+
| 'pager'
549+
| 'pullrequest'
550+
| 'rebase-status'
551+
| 'reflog'
552+
| 'reflog-record'
553+
| 'remote'
554+
| 'remotes'
555+
| 'results-commits'
556+
| 'results-files'
557+
| 'search-compare'
558+
| 'stashes'
559+
| 'status-files'
560+
| 'tags'
561+
| 'tracking-status'
562+
| 'tracking-status-files'
563+
| 'uncommitted-files'
564+
| 'workspace-missing-repository'
565+
| 'workspaces-view'
566+
| 'worktree'
567+
| 'worktrees';
568+
512569
export type ContextKeys =
513570
| `${typeof extensionPrefix}:action:${string}`
514571
| `${typeof extensionPrefix}:key:${Keys}`

src/views/nodes/UncommittedFileNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import type { FileNode } from './folderNode';
1212
import type { ViewNode } from './viewNode';
1313
import { ContextValues, ViewFileNode } from './viewNode';
1414

15-
export class UncommittedFileNode extends ViewFileNode<ViewsWithCommits> implements FileNode {
15+
export class UncommittedFileNode extends ViewFileNode<'uncommitted-file', ViewsWithCommits> implements FileNode {
1616
constructor(view: ViewsWithCommits, parent: ViewNode, repoPath: string, file: GitFile) {
17-
super(GitUri.fromFile(file, repoPath), view, parent, file);
17+
super('uncommitted-file', GitUri.fromFile(file, repoPath), view, parent, file);
1818
}
1919

2020
override toClipboard(): string {

src/views/nodes/UncommittedFilesNode.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { FolderNode } from './folderNode';
1212
import { UncommittedFileNode } from './UncommittedFileNode';
1313
import { ContextValues, getViewNodeId, ViewNode } from './viewNode';
1414

15-
export class UncommittedFilesNode extends ViewNode<ViewsWithWorkingTree> {
15+
export class UncommittedFilesNode extends ViewNode<'uncommitted-files', ViewsWithWorkingTree> {
1616
constructor(
1717
view: ViewsWithWorkingTree,
1818
protected override readonly parent: ViewNode,
@@ -26,9 +26,9 @@ export class UncommittedFilesNode extends ViewNode<ViewsWithWorkingTree> {
2626
},
2727
public readonly range: string | undefined,
2828
) {
29-
super(GitUri.fromRepoPath(status.repoPath), view, parent);
29+
super('uncommitted-files', GitUri.fromRepoPath(status.repoPath), view, parent);
3030

31-
this._uniqueId = getViewNodeId('uncommitted-files', this.context);
31+
this._uniqueId = getViewNodeId(this.type, this.context);
3232
}
3333

3434
override get id(): string {

src/views/nodes/autolinkedItemNode.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ import { isPromise } from '../../system/promise';
88
import type { ViewsWithCommits } from '../viewBase';
99
import { ContextValues, getViewNodeId, ViewNode } from './viewNode';
1010

11-
export class AutolinkedItemNode extends ViewNode<ViewsWithCommits> {
11+
export class AutolinkedItemNode extends ViewNode<'autolink', ViewsWithCommits> {
1212
constructor(
1313
view: ViewsWithCommits,
1414
protected override readonly parent: ViewNode,
1515
public readonly repoPath: string,
1616
public readonly item: Autolink,
1717
private enrichedItem: Promise<IssueOrPullRequest | undefined> | IssueOrPullRequest | undefined,
1818
) {
19-
super(GitUri.fromRepoPath(repoPath), view, parent);
19+
super('autolink', GitUri.fromRepoPath(repoPath), view, parent);
2020

21-
this._uniqueId = getViewNodeId(`autolink+${item.id}`, this.context);
21+
this._uniqueId = getViewNodeId(`${this.type}+${item.id}`, this.context);
2222
}
2323

2424
override get id(): string {

src/views/nodes/autolinkedItemsNode.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { ContextValues, getViewNodeId, ViewNode } from './viewNode';
1414

1515
let instanceId = 0;
1616

17-
export class AutolinkedItemsNode extends ViewNode<ViewsWithCommits> {
17+
export class AutolinkedItemsNode extends ViewNode<'autolinks', ViewsWithCommits> {
1818
private _instanceId: number;
1919

2020
constructor(
@@ -24,11 +24,11 @@ export class AutolinkedItemsNode extends ViewNode<ViewsWithCommits> {
2424
public readonly log: GitLog,
2525
private expand: boolean,
2626
) {
27-
super(GitUri.fromRepoPath(repoPath), view, parent);
27+
super('autolinks', GitUri.fromRepoPath(repoPath), view, parent);
2828

2929
this._instanceId = instanceId++;
3030
this.updateContext({ autolinksId: String(this._instanceId) });
31-
this._uniqueId = getViewNodeId('autolinks', this.context);
31+
this._uniqueId = getViewNodeId(this.type, this.context);
3232
}
3333

3434
override get id(): string {

src/views/nodes/branchNode.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ type State = {
3434
pendingPullRequest: Promise<PullRequest | undefined> | undefined;
3535
};
3636

37-
export class BranchNode extends ViewRefNode<ViewsWithBranches, GitBranchReference, State> implements PageableViewNode {
37+
export class BranchNode
38+
extends ViewRefNode<'branch', ViewsWithBranches, GitBranchReference, State>
39+
implements PageableViewNode
40+
{
3841
limit: number | undefined;
3942

4043
private readonly options: {
@@ -68,10 +71,10 @@ export class BranchNode extends ViewRefNode<ViewsWithBranches, GitBranchReferenc
6871
authors?: GitUser[];
6972
},
7073
) {
71-
super(uri, view, parent);
74+
super('branch', uri, view, parent);
7275

7376
this.updateContext({ repository: repo, branch: branch, root: root });
74-
this._uniqueId = getViewNodeId('branch', this.context);
77+
this._uniqueId = getViewNodeId(this.type, this.context);
7578
this.limit = this.view.getNodeLastKnownLimit(this);
7679

7780
this.options = {

src/views/nodes/branchOrTagFolderNode.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@ import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode';
22
import { GitUri } from '../../git/gitUri';
33
import type { HierarchicalItem } from '../../system/array';
44
import type { View } from '../viewBase';
5-
import { BranchNode } from './branchNode';
5+
import type { BranchNode } from './branchNode';
66
import type { TagNode } from './tagNode';
77
import { ContextValues, getViewNodeId, ViewNode } from './viewNode';
88

9-
export class BranchOrTagFolderNode extends ViewNode {
9+
export class BranchOrTagFolderNode extends ViewNode<'branch-tag-folder'> {
1010
constructor(
1111
view: View,
1212
protected override readonly parent: ViewNode,
13-
public readonly type: 'branch' | 'remote-branch' | 'tag',
13+
public readonly folderType: 'branch' | 'remote-branch' | 'tag',
1414
public readonly root: HierarchicalItem<BranchNode | TagNode>,
1515
public readonly repoPath: string,
1616
public readonly folderName: string,
1717
public readonly relativePath: string | undefined,
1818
private readonly _expanded: boolean = false,
1919
) {
20-
super(GitUri.fromRepoPath(repoPath), view, parent);
20+
super('branch-tag-folder', GitUri.fromRepoPath(repoPath), view, parent);
2121

22-
this._uniqueId = getViewNodeId(`${type}-folder+${relativePath ?? folderName}`, this.context);
22+
this._uniqueId = getViewNodeId(`${this.type}+${folderType}+${relativePath ?? folderName}`, this.context);
2323
}
2424

2525
override get id(): string {
@@ -38,12 +38,12 @@ export class BranchOrTagFolderNode extends ViewNode {
3838
for (const folder of this.root.children.values()) {
3939
if (folder.value === undefined) {
4040
// If the folder contains the current branch, expand it by default
41-
const expanded = folder.descendants?.some(n => n instanceof BranchNode && n.current);
41+
const expanded = folder.descendants?.some(n => n.is('branch') && n.current);
4242
children.push(
4343
new BranchOrTagFolderNode(
4444
this.view,
4545
this.folderName ? this : this.parent,
46-
this.type,
46+
this.folderType,
4747
folder,
4848
this.repoPath,
4949
folder.name,

src/views/nodes/branchTrackingStatusFilesNode.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ import { FolderNode } from './folderNode';
1414
import { StatusFileNode } from './statusFileNode';
1515
import { ContextValues, getViewNodeId, ViewNode } from './viewNode';
1616

17-
export class BranchTrackingStatusFilesNode extends ViewNode<ViewsWithCommits> {
17+
export class BranchTrackingStatusFilesNode extends ViewNode<'tracking-status-files', ViewsWithCommits> {
1818
constructor(
1919
view: ViewsWithCommits,
2020
protected override readonly parent: ViewNode,
2121
public readonly branch: GitBranch,
2222
public readonly status: Required<BranchTrackingStatus>,
2323
public readonly direction: 'ahead' | 'behind',
2424
) {
25-
super(GitUri.fromRepoPath(status.repoPath), view, parent);
25+
super('tracking-status-files', GitUri.fromRepoPath(status.repoPath), view, parent);
2626

2727
this.updateContext({ branch: branch, branchStatus: status, branchStatusUpstreamType: direction });
28-
this._uniqueId = getViewNodeId('tracking-status-files', this.context);
28+
this._uniqueId = getViewNodeId(this.type, this.context);
2929
}
3030

3131
get repoPath(): string {

src/views/nodes/branchTrackingStatusNode.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ export interface BranchTrackingStatus {
2626
upstream?: string;
2727
}
2828

29-
export class BranchTrackingStatusNode extends ViewNode<ViewsWithCommits> implements PageableViewNode {
29+
export class BranchTrackingStatusNode
30+
extends ViewNode<'tracking-status', ViewsWithCommits>
31+
implements PageableViewNode
32+
{
3033
limit: number | undefined;
3134

3235
constructor(
@@ -41,15 +44,15 @@ export class BranchTrackingStatusNode extends ViewNode<ViewsWithCommits> impleme
4144
showAheadCommits?: boolean;
4245
},
4346
) {
44-
super(GitUri.fromRepoPath(status.repoPath), view, parent);
47+
super('tracking-status', GitUri.fromRepoPath(status.repoPath), view, parent);
4548

4649
this.updateContext({
4750
branch: branch,
4851
branchStatus: status,
4952
branchStatusUpstreamType: upstreamType,
5053
root: root,
5154
});
52-
this._uniqueId = getViewNodeId('tracking-status', this.context);
55+
this._uniqueId = getViewNodeId(this.type, this.context);
5356
this.limit = this.view.getNodeLastKnownLimit(this);
5457
}
5558

src/views/nodes/branchesNode.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import { BranchOrTagFolderNode } from './branchOrTagFolderNode';
1010
import { MessageNode } from './common';
1111
import { ContextValues, getViewNodeId, ViewNode } from './viewNode';
1212

13-
export class BranchesNode extends ViewNode<ViewsWithBranchesNode> {
13+
export class BranchesNode extends ViewNode<'branches', ViewsWithBranchesNode> {
1414
constructor(
1515
uri: GitUri,
1616
view: ViewsWithBranchesNode,
1717
protected override readonly parent: ViewNode,
1818
public readonly repo: Repository,
1919
) {
20-
super(uri, view, parent);
20+
super('branches', uri, view, parent);
2121

2222
this.updateContext({ repository: repo });
23-
this._uniqueId = getViewNodeId('branches', this.context);
23+
this._uniqueId = getViewNodeId(this.type, this.context);
2424
}
2525

2626
override get id(): string {

0 commit comments

Comments
 (0)