Skip to content

Commit

Permalink
Splits & moves abstract node classes to new files
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Oct 26, 2023
1 parent 7cc24e4 commit 8aa81e9
Show file tree
Hide file tree
Showing 77 changed files with 1,115 additions and 1,044 deletions.
3 changes: 2 additions & 1 deletion src/commands/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import { isTag } from '../git/models/tag';
import { CloudWorkspace, LocalWorkspace } from '../plus/workspaces/models';
import { registerCommand } from '../system/command';
import { sequentialize } from '../system/function';
import { ViewNode, ViewRefFileNode, ViewRefNode } from '../views/nodes/viewNode';
import { ViewNode } from '../views/nodes/abstract/viewNode';
import { ViewRefFileNode, ViewRefNode } from '../views/nodes/abstract/viewRefNode';

export function getCommandUri(uri?: Uri, editor?: TextEditor): Uri | undefined {
// Always use the editor.uri (if we have one), so we are correct for a split diff
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { flatten } from './system/object';
import { Stopwatch } from './system/stopwatch';
import { Storage } from './system/storage';
import { compare, fromString, satisfies } from './system/version';
import { isViewNode } from './views/nodes/viewNode';
import { isViewNode } from './views/nodes/abstract/viewNode';
import './commands';

export async function activate(context: ExtensionContext): Promise<GitLensApi | undefined> {
Expand Down
2 changes: 1 addition & 1 deletion src/plus/webviews/graph/graphWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import { updateRecordValue } from '../../../system/object';
import { getSettledValue } from '../../../system/promise';
import { isDarkTheme, isLightTheme } from '../../../system/utils';
import { isWebviewItemContext, isWebviewItemGroupContext, serializeWebviewItemContext } from '../../../system/webview';
import { RepositoryFolderNode } from '../../../views/nodes/viewNode';
import { RepositoryFolderNode } from '../../../views/nodes/abstract/repositoryFolderNode';
import type { IpcMessage, IpcNotificationType } from '../../../webviews/protocol';
import { onIpc } from '../../../webviews/protocol';
import type { WebviewController, WebviewProvider } from '../../../webviews/webviewController';
Expand Down
4 changes: 2 additions & 2 deletions src/plus/webviews/timeline/timelineWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import type { Deferrable } from '../../../system/function';
import { debounce } from '../../../system/function';
import { filter } from '../../../system/iterable';
import { hasVisibleTextEditor, isTextEditor } from '../../../system/utils';
import type { ViewFileNode } from '../../../views/nodes/viewNode';
import { isViewFileNode } from '../../../views/nodes/viewNode';
import type { ViewFileNode } from '../../../views/nodes/abstract/viewFileNode';
import { isViewFileNode } from '../../../views/nodes/abstract/viewFileNode';
import type { IpcMessage } from '../../../webviews/protocol';
import { onIpc } from '../../../webviews/protocol';
import type { WebviewController, WebviewProvider } from '../../../webviews/webviewController';
Expand Down
2 changes: 1 addition & 1 deletion src/system/decorators/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isContainer } from '../../container';
import { isBranch } from '../../git/models/branch';
import { isCommit } from '../../git/models/commit';
import { isTag } from '../../git/models/tag';
import { isViewNode } from '../../views/nodes/viewNode';
import { isViewNode } from '../../views/nodes/abstract/viewNode';

function replacer(key: string, value: any): any {
if (key === '') return value;
Expand Down
5 changes: 3 additions & 2 deletions src/views/branchesView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import { RepositoryChange, RepositoryChangeComparisonMode } from '../git/models/
import { executeCommand } from '../system/command';
import { configuration } from '../system/configuration';
import { gate } from '../system/decorators/gate';
import { RepositoriesSubscribeableNode } from './nodes/abstract/repositoriesSubscribeableNode';
import { RepositoryFolderNode } from './nodes/abstract/repositoryFolderNode';
import type { ViewNode } from './nodes/abstract/viewNode';
import { BranchesNode } from './nodes/branchesNode';
import { BranchNode } from './nodes/branchNode';
import { BranchOrTagFolderNode } from './nodes/branchOrTagFolderNode';
import type { ViewNode } from './nodes/viewNode';
import { RepositoriesSubscribeableNode, RepositoryFolderNode } from './nodes/viewNode';
import { ViewBase } from './viewBase';
import { registerViewCommand } from './viewCommands';

Expand Down
5 changes: 3 additions & 2 deletions src/views/commitsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import { gate } from '../system/decorators/gate';
import { debug } from '../system/decorators/log';
import { disposableInterval } from '../system/function';
import type { UsageChangeEvent } from '../telemetry/usageTracker';
import { RepositoriesSubscribeableNode } from './nodes/abstract/repositoriesSubscribeableNode';
import { RepositoryFolderNode } from './nodes/abstract/repositoryFolderNode';
import type { ViewNode } from './nodes/abstract/viewNode';
import { BranchNode } from './nodes/branchNode';
import { BranchTrackingStatusNode } from './nodes/branchTrackingStatusNode';
import { CommandMessageNode } from './nodes/common';
import type { ViewNode } from './nodes/viewNode';
import { RepositoriesSubscribeableNode, RepositoryFolderNode } from './nodes/viewNode';
import { ViewBase } from './viewBase';
import { registerViewCommand } from './viewCommands';

Expand Down
5 changes: 3 additions & 2 deletions src/views/contributorsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import { executeCommand } from '../system/command';
import { configuration } from '../system/configuration';
import { gate } from '../system/decorators/gate';
import { debug } from '../system/decorators/log';
import { RepositoriesSubscribeableNode } from './nodes/abstract/repositoriesSubscribeableNode';
import { RepositoryFolderNode } from './nodes/abstract/repositoryFolderNode';
import type { ViewNode } from './nodes/abstract/viewNode';
import { ContributorNode } from './nodes/contributorNode';
import { ContributorsNode } from './nodes/contributorsNode';
import type { ViewNode } from './nodes/viewNode';
import { RepositoriesSubscribeableNode, RepositoryFolderNode } from './nodes/viewNode';
import { ViewBase } from './viewBase';
import { registerViewCommand } from './viewCommands';

Expand Down
5 changes: 3 additions & 2 deletions src/views/nodes/UncommittedFileNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import type { GitFile } from '../../git/models/file';
import { getGitFileStatusIcon } from '../../git/models/file';
import { dirname, joinPaths } from '../../system/path';
import type { ViewsWithCommits } from '../viewBase';
import { ViewFileNode } from './abstract/viewFileNode';
import type { ViewNode } from './abstract/viewNode';
import { ContextValues } from './abstract/viewNode';
import type { FileNode } from './folderNode';
import type { ViewNode } from './viewNode';
import { ContextValues, ViewFileNode } from './viewNode';

export class UncommittedFileNode extends ViewFileNode<'uncommitted-file', ViewsWithCommits> implements FileNode {
constructor(view: ViewsWithCommits, parent: ViewNode, repoPath: string, file: GitFile) {
Expand Down
2 changes: 1 addition & 1 deletion src/views/nodes/UncommittedFilesNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { groupBy, makeHierarchical } from '../../system/array';
import { flatMap } from '../../system/iterable';
import { joinPaths, normalizePath } from '../../system/path';
import type { ViewsWithWorkingTree } from '../viewBase';
import { ContextValues, getViewNodeId, ViewNode } from './abstract/viewNode';
import type { FileNode } from './folderNode';
import { FolderNode } from './folderNode';
import { UncommittedFileNode } from './UncommittedFileNode';
import { ContextValues, getViewNodeId, ViewNode } from './viewNode';

export class UncommittedFilesNode extends ViewNode<'uncommitted-files', ViewsWithWorkingTree> {
constructor(
Expand Down
36 changes: 36 additions & 0 deletions src/views/nodes/abstract/cacheableChildrenViewNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { TreeViewNodeTypes } from '../../../constants';
import { debug } from '../../../system/decorators/log';
import type { View } from '../../viewBase';
import { disposeChildren } from '../../viewBase';
import { ViewNode } from './viewNode';

export abstract class CacheableChildrenViewNode<
Type extends TreeViewNodeTypes = TreeViewNodeTypes,
TView extends View = View,
TChild extends ViewNode = ViewNode,
State extends object = any,
> extends ViewNode<Type, TView, State> {
private _children: TChild[] | undefined;
protected get children(): TChild[] | undefined {
return this._children;
}
protected set children(value: TChild[] | undefined) {
if (this._children === value) return;

disposeChildren(this._children, value);
this._children = value;
}

@debug()
override dispose() {
super.dispose();
this.children = undefined;
}

@debug()
override refresh(reset: boolean = false) {
if (reset) {
this.children = undefined;
}
}
}
51 changes: 51 additions & 0 deletions src/views/nodes/abstract/repositoriesSubscribeableNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Disposable } from 'vscode';
import type { RepositoriesChangeEvent } from '../../../git/gitProviderService';
import { unknownGitUri } from '../../../git/gitUri';
import type { SubscriptionChangeEvent } from '../../../plus/subscription/subscriptionService';
import { debug } from '../../../system/decorators/log';
import { weakEvent } from '../../../system/event';
import { szudzikPairing } from '../../../system/function';
import type { View } from '../../viewBase';
import { SubscribeableViewNode } from './subscribeableViewNode';
import type { ViewNode } from './viewNode';

export abstract class RepositoriesSubscribeableNode<
TView extends View = View,
TChild extends ViewNode = ViewNode,
> extends SubscribeableViewNode<'repositories', TView, TChild> {
protected override splatted = true;

constructor(view: TView) {
super('repositories', unknownGitUri, view);
}

override async getSplattedChild() {
if (this.children == null) {
await this.getChildren();
}

return this.children?.length === 1 ? this.children[0] : undefined;
}

protected override etag(): number {
return szudzikPairing(this.view.container.git.etag, this.view.container.subscription.etag);
}

@debug()
protected subscribe(): Disposable | Promise<Disposable> {
return Disposable.from(
weakEvent(this.view.container.git.onDidChangeRepositories, this.onRepositoriesChanged, this),
weakEvent(this.view.container.subscription.onDidChange, this.onSubscriptionChanged, this),
);
}

private onRepositoriesChanged(_e: RepositoriesChangeEvent) {
void this.triggerChange(true);
}

private onSubscriptionChanged(e: SubscriptionChangeEvent) {
if (e.current.plan !== e.previous.plan) {
void this.triggerChange(true);
}
}
}
Loading

0 comments on commit 8aa81e9

Please sign in to comment.