Skip to content

Commit

Permalink
(WIP) Adds new view ids
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Nov 26, 2024
1 parent e68c69e commit 001de0e
Show file tree
Hide file tree
Showing 41 changed files with 108 additions and 158 deletions.
4 changes: 0 additions & 4 deletions src/views/launchpadView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 0 additions & 4 deletions src/views/nodes/UncommittedFilesNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 0 additions & 4 deletions src/views/nodes/abstract/repositoryFolderNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
78 changes: 73 additions & 5 deletions src/views/nodes/abstract/viewNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,29 @@ export interface AmbientContext {
readonly worktreesByBranch?: Map<string, GitWorktree>;
}

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';
Expand Down Expand Up @@ -252,8 +274,22 @@ export abstract class ViewNode<
return types.includes(this.type as unknown as T[number]);
}

public childrenIds = new Set<string>();
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();

Expand All @@ -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));
Expand All @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions src/views/nodes/autolinkedItemNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
const enriched = await this.maybeEnriched;
switch (type) {
Expand Down
4 changes: 0 additions & 4 deletions src/views/nodes/autolinkedItemsNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ViewNode[]> {
if (this.children == null) {
const commits = [...this.log.commits.values()];
Expand Down
8 changes: 3 additions & 5 deletions src/views/nodes/branchNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -106,10 +108,6 @@ export class BranchNode
this.children = undefined;
}

override get id(): string {
return this._uniqueId;
}

override toClipboard(): string {
return this.branch.name;
}
Expand Down
4 changes: 0 additions & 4 deletions src/views/nodes/branchOrTagFolderNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 1 addition & 5 deletions src/views/nodes/branchTrackingStatusNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!;
}
Expand Down
4 changes: 0 additions & 4 deletions src/views/nodes/branchesNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 0 additions & 4 deletions src/views/nodes/codeSuggestionsNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ViewNode[]> {
if (this.children == null) {
const drafts = await this.getSuggestedChanges();
Expand Down
6 changes: 2 additions & 4 deletions src/views/nodes/commitFileNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions src/views/nodes/commitNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
Expand Down
4 changes: 0 additions & 4 deletions src/views/nodes/compareResultsNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ export class CompareResultsNode extends SubscribeableViewNode<
}
}

override get id(): string {
return this._uniqueId;
}

protected override etag(): number {
return this._storedAt;
}
Expand Down
4 changes: 0 additions & 4 deletions src/views/nodes/contributorNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 0 additions & 4 deletions src/views/nodes/contributorsNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 0 additions & 4 deletions src/views/nodes/draftNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 0 additions & 4 deletions src/views/nodes/fileHistoryNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/views/nodes/fileRevisionAsCommitNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions src/views/nodes/folderNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 0 additions & 4 deletions src/views/nodes/lineHistoryNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 3 additions & 5 deletions src/views/nodes/pullRequestNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions src/views/nodes/reflogNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ export class ReflogNode
this.limit = this.view.getNodeLastKnownLimit(this);
}

override get id(): string {
return this._uniqueId;
}

async getChildren(): Promise<ViewNode[]> {
if (this.children === undefined) {
const children = [];
Expand Down
4 changes: 0 additions & 4 deletions src/views/nodes/reflogRecordNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ViewNode[]> {
const log = await this.getLog();
if (log === undefined) return [new MessageNode(this.view, this, 'No commits could be found.')];
Expand Down
4 changes: 0 additions & 4 deletions src/views/nodes/remoteNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading

0 comments on commit 001de0e

Please sign in to comment.