Bladeren bron

Adds ViewFileNode base for consolidation

Avoids dangerous `any` cast when setting FileNode parent in FolderNode
main
Eric Amodio 2 jaren geleden
bovenliggende
commit
b41804fb55
13 gewijzigde bestanden met toevoegingen van 59 en 47 verwijderingen
  1. +4
    -9
      src/views/nodes/UncommittedFileNode.ts
  2. +1
    -1
      src/views/nodes/branchTrackingStatusFilesNode.ts
  3. +2
    -2
      src/views/nodes/commitFileNode.ts
  4. +2
    -2
      src/views/nodes/fileRevisionAsCommitNode.ts
  5. +9
    -6
      src/views/nodes/folderNode.ts
  6. +5
    -8
      src/views/nodes/mergeConflictFileNode.ts
  7. +1
    -1
      src/views/nodes/mergeStatusNode.ts
  8. +1
    -1
      src/views/nodes/rebaseStatusNode.ts
  9. +2
    -2
      src/views/nodes/resultsFileNode.ts
  10. +1
    -1
      src/views/nodes/resultsFilesNode.ts
  11. +5
    -8
      src/views/nodes/statusFileNode.ts
  12. +1
    -1
      src/views/nodes/statusFilesNode.ts
  13. +25
    -5
      src/views/nodes/viewNode.ts

+ 4
- 9
src/views/nodes/UncommittedFileNode.ts Bestand weergeven

@ -8,17 +8,12 @@ import { GitFile } from '../../git/models/file';
import { dirname, joinPaths } from '../../system/path';
import type { ViewsWithCommits } from '../viewBase';
import type { FileNode } from './folderNode';
import { ContextValues, ViewNode } from './viewNode';
export class UncommittedFileNode extends ViewNode<ViewsWithCommits> implements FileNode {
public readonly file: GitFile;
public readonly repoPath: string;
import type { ViewNode } from './viewNode';
import { ContextValues, ViewFileNode } from './viewNode';
export class UncommittedFileNode extends ViewFileNode<ViewsWithCommits> implements FileNode {
constructor(view: ViewsWithCommits, parent: ViewNode, repoPath: string, file: GitFile) {
super(GitUri.fromFile(file, repoPath), view, parent);
this.repoPath = repoPath;
this.file = file;
super(GitUri.fromFile(file, repoPath), view, parent, file);
}
override toClipboard(): string {

+ 1
- 1
src/views/nodes/branchTrackingStatusFilesNode.ts Bestand weergeven

@ -86,8 +86,8 @@ export class BranchTrackingStatusFilesNode extends ViewNode {
new StatusFileNode(
this.view,
this,
this.repoPath,
files[files.length - 1],
this.repoPath,
files.map(s => s.commit),
this.direction,
),

+ 2
- 2
src/views/nodes/commitFileNode.ts Bestand weergeven

@ -18,7 +18,7 @@ export class CommitFileNode
constructor(
view: TView,
parent: ViewNode,
public readonly file: GitFile,
file: GitFile,
public commit: GitCommit,
private readonly _options: {
branch?: GitBranch;
@ -26,7 +26,7 @@ export class CommitFileNode
unpublished?: boolean;
} = {},
) {
super(GitUri.fromFile(file, commit.repoPath, commit.sha), view, parent);
super(GitUri.fromFile(file, commit.repoPath, commit.sha), view, parent, file);
}
override toClipboard(): string {

+ 2
- 2
src/views/nodes/fileRevisionAsCommitNode.ts Bestand weergeven

@ -24,7 +24,7 @@ export class FileRevisionAsCommitNode extends ViewRefFileNode
constructor(
view: ViewsWithCommits | FileHistoryView | LineHistoryView,
parent: ViewNode,
public readonly file: GitFile,
file: GitFile,
public commit: GitCommit,
private readonly _options: {
branch?: GitBranch;
@ -33,7 +33,7 @@ export class FileRevisionAsCommitNode extends ViewRefFileNode
unpublished?: boolean;
} = {},
) {
super(GitUri.fromFile(file, commit.repoPath, commit.sha), view, parent);
super(GitUri.fromFile(file, commit.repoPath, commit.sha), view, parent, file);
}
override toClipboard(): string {

+ 9
- 6
src/views/nodes/folderNode.ts Bestand weergeven

@ -7,14 +7,17 @@ import { sortCompare } from '../../system/string';
import type { FileHistoryView } from '../fileHistoryView';
import type { StashesView } from '../stashesView';
import type { ViewsWithCommits } from '../viewBase';
import type { ViewFileNode } from './viewNode';
import { ContextValues, ViewNode } from './viewNode';
export interface FileNode extends ViewNode {
export interface FileNode extends ViewFileNode {
folderName: string;
label?: string;
priority: number;
label?: string;
relativePath?: string;
root?: HierarchicalItem<FileNode>;
// root?: HierarchicalItem<FileNode>;
}
export class FolderNode extends ViewNode<ViewsWithCommits | FileHistoryView | StashesView> {
@ -22,7 +25,7 @@ export class FolderNode extends ViewNode
constructor(
view: ViewsWithCommits | FileHistoryView | StashesView,
parent: ViewNode,
protected override parent: ViewNode,
public readonly repoPath: string,
public readonly folderName: string,
public readonly root: HierarchicalItem<FileNode>,
@ -56,7 +59,7 @@ export class FolderNode extends ViewNode
children.push(
new FolderNode(
this.view,
this.folderName ? this : this.parent!,
this.folderName ? this : this.parent,
this.repoPath,
folder.name,
folder,
@ -68,7 +71,7 @@ export class FolderNode extends ViewNode
}
// Make sure to set the parent
(folder.value as any).parent = this.folderName ? this : this.parent!;
folder.value.parent = this.folderName ? this : this.parent;
folder.value.relativePath = this.root.relativePath;
children.push(folder.value);
}

+ 5
- 8
src/views/nodes/mergeConflictFileNode.ts Bestand weergeven

@ -11,16 +11,17 @@ import type { ViewsWithCommits } from '../viewBase';
import type { FileNode } from './folderNode';
import { MergeConflictCurrentChangesNode } from './mergeConflictCurrentChangesNode';
import { MergeConflictIncomingChangesNode } from './mergeConflictIncomingChangesNode';
import { ContextValues, ViewNode } from './viewNode';
import type { ViewNode } from './viewNode';
import { ContextValues, ViewFileNode } from './viewNode';
export class MergeConflictFileNode extends ViewNode<ViewsWithCommits> implements FileNode {
export class MergeConflictFileNode extends ViewFileNode<ViewsWithCommits> implements FileNode {
constructor(
view: ViewsWithCommits,
parent: ViewNode,
file: GitFile,
public readonly status: GitMergeStatus | GitRebaseStatus,
public readonly file: GitFile,
) {
super(GitUri.fromFile(file, status.repoPath, status.HEAD.ref), view, parent);
super(GitUri.fromFile(file, status.repoPath, status.HEAD.ref), view, parent, file);
}
override toClipboard(): string {
@ -35,10 +36,6 @@ export class MergeConflictFileNode extends ViewNode implements
return this.file.path;
}
get repoPath(): string {
return this.status.repoPath;
}
getChildren(): ViewNode[] {
return [
new MergeConflictCurrentChangesNode(this.view, this, this.status, this.file),

+ 1
- 1
src/views/nodes/mergeStatusNode.ts Bestand weergeven

@ -45,7 +45,7 @@ export class MergeStatusNode extends ViewNode {
if (this.status?.hasConflicts !== true) return [];
let children: FileNode[] = this.status.conflicts.map(
f => new MergeConflictFileNode(this.view, this, this.mergeStatus, f),
f => new MergeConflictFileNode(this.view, this, f, this.mergeStatus),
);
if (this.view.config.files.layout !== ViewFilesLayout.List) {

+ 1
- 1
src/views/nodes/rebaseStatusNode.ts Bestand weergeven

@ -52,7 +52,7 @@ export class RebaseStatusNode extends ViewNode {
async getChildren(): Promise<ViewNode[]> {
let children: FileNode[] =
this.status?.conflicts.map(f => new MergeConflictFileNode(this.view, this, this.rebaseStatus, f)) ?? [];
this.status?.conflicts.map(f => new MergeConflictFileNode(this.view, this, f, this.rebaseStatus)) ?? [];
if (this.view.config.files.layout !== ViewFilesLayout.List) {
const hierarchy = makeHierarchical(

+ 2
- 2
src/views/nodes/resultsFileNode.ts Bestand weergeven

@ -18,12 +18,12 @@ export class ResultsFileNode extends ViewRefFileNode implements FileNode {
view: View,
parent: ViewNode,
repoPath: string,
public readonly file: GitFile,
file: GitFile,
public readonly ref1: string,
public readonly ref2: string,
private readonly direction: 'ahead' | 'behind' | undefined,
) {
super(GitUri.fromFile(file, repoPath, ref1 || ref2), view, parent);
super(GitUri.fromFile(file, repoPath, ref1 || ref2), view, parent, file);
}
override toClipboard(): string {

+ 1
- 1
src/views/nodes/resultsFilesNode.ts Bestand weergeven

@ -32,7 +32,7 @@ export interface FilesQueryResults {
export class ResultsFilesNode extends ViewNode<ViewsWithCommits> {
constructor(
view: ViewsWithCommits,
protected override readonly parent: ViewNode,
protected override parent: ViewNode,
public readonly repoPath: string,
public readonly ref1: string,
public readonly ref2: string,

+ 5
- 8
src/views/nodes/statusFileNode.ts Bestand weergeven

@ -12,12 +12,11 @@ import { pluralize } from '../../system/string';
import type { ViewsWithCommits } from '../viewBase';
import { FileRevisionAsCommitNode } from './fileRevisionAsCommitNode';
import type { FileNode } from './folderNode';
import { ContextValues, ViewNode } from './viewNode';
import type { ViewNode } from './viewNode';
import { ContextValues, ViewFileNode } from './viewNode';
export class StatusFileNode extends ViewNode<ViewsWithCommits> implements FileNode {
export class StatusFileNode extends ViewFileNode<ViewsWithCommits> implements FileNode {
public readonly commits: GitCommit[];
public readonly file: GitFile;
public readonly repoPath: string;
private readonly _direction: 'ahead' | 'behind';
private readonly _hasStagedChanges: boolean;
@ -26,8 +25,8 @@ export class StatusFileNode extends ViewNode implements FileNo
constructor(
view: ViewsWithCommits,
parent: ViewNode,
repoPath: string,
file: GitFile,
repoPath: string,
commits: GitCommit[],
direction: 'ahead' | 'behind' = 'ahead',
) {
@ -55,10 +54,8 @@ export class StatusFileNode extends ViewNode implements FileNo
}
}
super(GitUri.fromFile(file, repoPath, ref), view, parent);
super(GitUri.fromFile(file, repoPath, ref), view, parent, file);
this.repoPath = repoPath;
this.file = file;
this.commits = commits;
this._direction = direction;

+ 1
- 1
src/views/nodes/statusFilesNode.ts Bestand weergeven

@ -94,8 +94,8 @@ export class StatusFilesNode extends ViewNode
new StatusFileNode(
this.view,
this,
repoPath,
files[files.length - 1],
repoPath,
files.map(s => s.commit),
),
);

+ 25
- 5
src/views/nodes/viewNode.ts Bestand weergeven

@ -88,7 +88,7 @@ export interface ViewNode {
export abstract class ViewNode<TView extends View = View, State extends object = any> {
protected splatted = false;
constructor(uri: GitUri, public readonly view: TView, protected readonly parent?: ViewNode) {
constructor(uri: GitUri, public readonly view: TView, protected parent?: ViewNode) {
this._uri = uri;
}
@ -100,7 +100,7 @@ export abstract class ViewNode
}
protected _uri: GitUri;
get uri() {
get uri() class="o">: GitUri {
return this._uri;
}
@ -168,6 +168,23 @@ export function isViewNode(node: any): node is ViewNode {
type StateKey<T> = keyof T;
type StateValue<T, P extends StateKey<T>> = P extends keyof T ? T[P] : never;
export abstract class ViewFileNode<TView extends View = View, State extends object = any> extends ViewNode<
TView,
State
> {
constructor(uri: GitUri, view: TView, public override parent: ViewNode, public readonly file: GitFile) {
super(uri, view, parent);
}
get repoPath(): string {
return this.uri.repoPath!;
}
override toString(): string {
return `${super.toString()}:${this.file.path}`;
}
}
export abstract class ViewRefNode<
TView extends View = View,
TReference extends GitReference = GitReference,
@ -184,12 +201,15 @@ export abstract class ViewRefNode<
}
}
export abstract class ViewRefFileNode<TView extends View = View, State extends object = any> extends ViewRefNode<
export abstract class ViewRefFileNode<TView extends View = View, State extends object = any> extends ViewFileNode<
TView,
GitRevisionReference,
State
> {
abstract get file(): GitFile;
constructor(uri: GitUri, view: TView, parent: ViewNode, file: GitFile) {
super(uri, view, parent, file);
}
abstract get ref(): GitRevisionReference;
override toString(): string {
return `${super.toString()}:${this.file.path}`;

||||||
x
 
000:0
Laden…
Annuleren
Opslaan