diff --git a/src/extension.ts b/src/extension.ts index 943ea27..10a8c8c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,5 +1,4 @@ 'use strict'; - import { commands, ExtensionContext, extensions, window, workspace } from 'vscode'; import { Commands, configureCommands } from './commands'; import { Config, configuration, Configuration } from './configuration'; diff --git a/src/views/nodes/common.ts b/src/views/nodes/common.ts index aa1e888..075f759 100644 --- a/src/views/nodes/common.ts +++ b/src/views/nodes/common.ts @@ -126,7 +126,7 @@ export class UpdateableMessageNode extends ViewNode { this._iconPath = changes.iconPath === null ? undefined : changes.iconPath; } - view.triggerNodeUpdate(this); + view.triggerNodeChange(this); } } diff --git a/src/views/nodes/fileHistoryNode.ts b/src/views/nodes/fileHistoryNode.ts index 21f2f7e..b7495c9 100644 --- a/src/views/nodes/fileHistoryNode.ts +++ b/src/views/nodes/fileHistoryNode.ts @@ -120,7 +120,7 @@ export class FileHistoryNode extends SubscribeableViewNode { Logger.log(`FileHistoryNode.onRepoChanged(${e.changes.join()}); triggering node refresh`); - void this.view.refreshNode(this); + void this.triggerChange(); } private onRepoFileSystemChanged(e: RepositoryFileSystemChangeEvent) { @@ -128,6 +128,6 @@ export class FileHistoryNode extends SubscribeableViewNode { Logger.log(`FileHistoryNode.onRepoFileSystemChanged; triggering node refresh`); - void this.view.refreshNode(this); + void this.triggerChange(); } } diff --git a/src/views/nodes/fileHistoryTrackerNode.ts b/src/views/nodes/fileHistoryTrackerNode.ts index ddc4ee9..29d1368 100644 --- a/src/views/nodes/fileHistoryTrackerNode.ts +++ b/src/views/nodes/fileHistoryTrackerNode.ts @@ -113,6 +113,6 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode { Logger.log(`LineHistoryNode.onRepoChanged(${e.changes.join()}); triggering node refresh`); - void this.view.refreshNode(this); + void this.triggerChange(); } private onRepoFileSystemChanged(e: RepositoryFileSystemChangeEvent) { @@ -152,6 +152,6 @@ export class LineHistoryNode extends SubscribeableViewNode { Logger.log(`LineHistoryNode.onRepoFileSystemChanged; triggering node refresh`); - void this.view.refreshNode(this); + void this.triggerChange(); } } diff --git a/src/views/nodes/lineHistoryTrackerNode.ts b/src/views/nodes/lineHistoryTrackerNode.ts index f0a6750..d849ad5 100644 --- a/src/views/nodes/lineHistoryTrackerNode.ts +++ b/src/views/nodes/lineHistoryTrackerNode.ts @@ -116,6 +116,6 @@ export class LineHistoryTrackerNode extends SubscribeableViewNode { // Reset our subscription if the configuration changed if (reason === RefreshReason.ConfigurationChanged) { - this.unsubscribe(); + await this.unsubscribe(); } void this.ensureSubscription(); @@ -196,6 +196,6 @@ export class RepositoriesNode extends SubscribeableViewNode { } private onRepositoriesChanged() { - void this.view.refreshNode(this); + void this.triggerChange(); } } diff --git a/src/views/nodes/repositoryNode.ts b/src/views/nodes/repositoryNode.ts index 94470e0..9002bcd 100644 --- a/src/views/nodes/repositoryNode.ts +++ b/src/views/nodes/repositoryNode.ts @@ -186,7 +186,7 @@ export class RepositoryNode extends SubscribeableViewNode { await commands.executeCommand('git.fetch', this.repo.path); await this.updateLastFetched(); - this.view.triggerNodeUpdate(this); + this.view.triggerNodeChange(this); } async pull(progress: boolean = true) { @@ -206,7 +206,7 @@ export class RepositoryNode extends SubscribeableViewNode { await commands.executeCommand('git.pull', this.repo.path); await this.updateLastFetched(); - this.view.triggerNodeUpdate(this); + this.view.triggerNodeChange(this); } async push(progress: boolean = true) { @@ -225,7 +225,7 @@ export class RepositoryNode extends SubscribeableViewNode { private async pushCore() { await commands.executeCommand('git.push', this.repo.path); - this.view.triggerNodeUpdate(this); + this.view.triggerNodeChange(this); } refresh() { @@ -258,7 +258,7 @@ export class RepositoryNode extends SubscribeableViewNode { } private onFileSystemChanged(e: RepositoryFileSystemChangeEvent) { - void this.view.refreshNode(this); + void this.triggerChange(); } private onRepoChanged(e: RepositoryChangeEvent) { @@ -275,7 +275,7 @@ export class RepositoryNode extends SubscribeableViewNode { e.changed(RepositoryChange.Repository) || e.changed(RepositoryChange.Config) ) { - void this.view.refreshNode(this); + void this.triggerChange(); return; } @@ -283,21 +283,21 @@ export class RepositoryNode extends SubscribeableViewNode { if (e.changed(RepositoryChange.Stashes)) { const node = this._children.find(c => c instanceof StashesNode); if (node !== undefined) { - void this.view.refreshNode(node); + void this.triggerChange(); } } if (e.changed(RepositoryChange.Remotes)) { const node = this._children.find(c => c instanceof RemotesNode); if (node !== undefined) { - void this.view.refreshNode(node); + void this.triggerChange(); } } if (e.changed(RepositoryChange.Tags)) { const node = this._children.find(c => c instanceof TagsNode); if (node !== undefined) { - void this.view.refreshNode(node); + void this.triggerChange(); } } } @@ -332,6 +332,6 @@ export class RepositoryNode extends SubscribeableViewNode { // If the fetched date hasn't changed and it was over a day ago, kick out if (this._lastFetched === prevLastFetched && Date.now() - this._lastFetched >= Dates.MillisecondsPerDay) return; - this.view.triggerNodeUpdate(this); + this.view.triggerNodeChange(this); } } diff --git a/src/views/nodes/resultsComparisonNode.ts b/src/views/nodes/resultsComparisonNode.ts index baaa79d..bdd909d 100644 --- a/src/views/nodes/resultsComparisonNode.ts +++ b/src/views/nodes/resultsComparisonNode.ts @@ -62,7 +62,7 @@ export class ResultsComparisonNode extends ViewNode { this._ref1 = this._ref2; this._ref2 = ref1; - this.view.triggerNodeUpdate(this); + this.view.triggerNodeChange(this); } private async getCommitsQuery(maxCount: number | undefined): Promise { diff --git a/src/views/nodes/resultsNode.ts b/src/views/nodes/resultsNode.ts index 3e26e3f..72849b7 100644 --- a/src/views/nodes/resultsNode.ts +++ b/src/views/nodes/resultsNode.ts @@ -111,14 +111,14 @@ export class ResultsNode extends ViewNode { this._children.splice(0, 0, results); } - this.view.triggerNodeUpdate(); + this.view.triggerNodeChange(); } clear() { if (this._children.length === 0) return; this._children.length = 0; - this.view.triggerNodeUpdate(); + this.view.triggerNodeChange(); } dismiss(node: ViewNode) { @@ -128,7 +128,7 @@ export class ResultsNode extends ViewNode { if (index === -1) return; this._children.splice(index, 1); - this.view.triggerNodeUpdate(); + this.view.triggerNodeChange(); } async refresh() { diff --git a/src/views/nodes/viewNode.ts b/src/views/nodes/viewNode.ts index 4174c72..10fd90a 100644 --- a/src/views/nodes/viewNode.ts +++ b/src/views/nodes/viewNode.ts @@ -54,7 +54,7 @@ export const unknownGitUri = new GitUri(); export abstract class ViewNode { constructor( uri: GitUri, - private readonly _parent: ViewNode | undefined + protected readonly _parent: ViewNode | undefined ) { this._uri = uri; } @@ -65,9 +65,11 @@ export abstract class ViewNode { } abstract getChildren(): ViewNode[] | Promise; + getParent(): ViewNode | undefined { return this._parent; } + abstract getTreeItem(): TreeItem | Promise; getCommand(): Command | undefined { @@ -104,7 +106,7 @@ export function supportsAutoRefresh( export abstract class SubscribeableViewNode extends ViewNode { protected _disposable: Disposable; - protected _subscription: Disposable | undefined; + protected _subscription: Promise | undefined; constructor( uri: GitUri, @@ -141,15 +143,25 @@ export abstract class SubscribeableViewNode extends ViewNode void this.ensureSubscription(); if (value) { - void this.view.refreshNode(this); + void this.triggerChange(); } } + async triggerChange() { + return this.view.refreshNode(this); + } + protected abstract async subscribe(): Promise; - protected unsubscribe(): void { + + protected async unsubscribe(): Promise { if (this._subscription !== undefined) { - this._subscription.dispose(); + const subscriptionPromise = this._subscription; this._subscription = undefined; + + const subscription = await subscriptionPromise; + if (subscription !== undefined) { + subscription.dispose(); + } } } @@ -161,14 +173,14 @@ export abstract class SubscribeableViewNode extends ViewNode void this.ensureSubscription(); if (e.visible) { - void this.view.refreshNode(this); + void this.triggerChange(); } } async ensureSubscription() { // We only need to subscribe if we are visible and if auto-refresh enabled (when supported) if (!this.canSubscribe || !this.view.visible || (supportsAutoRefresh(this.view) && !this.view.autoRefresh)) { - this.unsubscribe(); + await this.unsubscribe(); return; } @@ -176,6 +188,7 @@ export abstract class SubscribeableViewNode extends ViewNode // If we already have a subscription, just kick out if (this._subscription !== undefined) return; - this._subscription = await this.subscribe(); + this._subscription = this.subscribe(); + await this._subscription; } } diff --git a/src/views/viewBase.ts b/src/views/viewBase.ts index 5ba38df..710da49 100644 --- a/src/views/viewBase.ts +++ b/src/views/viewBase.ts @@ -123,7 +123,7 @@ export abstract class ViewBase implements TreeDataProvid await this._root.refresh(reason); } - this.triggerNodeUpdate(); + this.triggerNodeChange(); } async refreshNode(node: ViewNode, args?: RefreshNodeCommandArgs) { @@ -143,7 +143,7 @@ export abstract class ViewBase implements TreeDataProvid const cancel = await node.refresh(); if (cancel === true) return; - this.triggerNodeUpdate(node); + this.triggerNodeChange(node); } async reveal( @@ -171,7 +171,7 @@ export abstract class ViewBase implements TreeDataProvid return this.reveal(child, { select: false, focus: true }); } - triggerNodeUpdate(node?: ViewNode) { + triggerNodeChange(node?: ViewNode) { // Since the root node won't actually refresh, force everything this._onDidChangeTreeData.fire(node !== undefined && node !== this._root ? node : undefined); }