Browse Source

Fixes subscription issues with nodes

main
Eric Amodio 6 years ago
parent
commit
3d8141fd85
12 changed files with 46 additions and 34 deletions
  1. +0
    -1
      src/extension.ts
  2. +1
    -1
      src/views/nodes/common.ts
  3. +2
    -2
      src/views/nodes/fileHistoryNode.ts
  4. +1
    -1
      src/views/nodes/fileHistoryTrackerNode.ts
  5. +2
    -2
      src/views/nodes/lineHistoryNode.ts
  6. +1
    -1
      src/views/nodes/lineHistoryTrackerNode.ts
  7. +2
    -2
      src/views/nodes/repositoriesNode.ts
  8. +9
    -9
      src/views/nodes/repositoryNode.ts
  9. +1
    -1
      src/views/nodes/resultsComparisonNode.ts
  10. +3
    -3
      src/views/nodes/resultsNode.ts
  11. +21
    -8
      src/views/nodes/viewNode.ts
  12. +3
    -3
      src/views/viewBase.ts

+ 0
- 1
src/extension.ts View File

@ -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';

+ 1
- 1
src/views/nodes/common.ts View File

@ -126,7 +126,7 @@ export class UpdateableMessageNode extends ViewNode {
this._iconPath = changes.iconPath === null ? undefined : changes.iconPath;
}
view.triggerNodeUpdate(this);
view.triggerNodeChange(this);
}
}

+ 2
- 2
src/views/nodes/fileHistoryNode.ts View File

@ -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();
}
}

+ 1
- 1
src/views/nodes/fileHistoryTrackerNode.ts View File

@ -113,6 +113,6 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode
}
private onActiveEditorChanged(editor: TextEditor | undefined) {
void this.view.refreshNode(this);
void this.triggerChange();
}
}

+ 2
- 2
src/views/nodes/lineHistoryNode.ts View File

@ -144,7 +144,7 @@ export class LineHistoryNode 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();
}
}

+ 1
- 1
src/views/nodes/lineHistoryTrackerNode.ts View File

@ -116,6 +116,6 @@ export class LineHistoryTrackerNode extends SubscribeableViewNode
}
private onActiveLinesChanged(e: LinesChangeEvent) {
void this.view.refreshNode(this);
void this.triggerChange();
}
}

+ 2
- 2
src/views/nodes/repositoriesNode.ts View File

@ -147,7 +147,7 @@ export class RepositoriesNode 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();
}
}

+ 9
- 9
src/views/nodes/repositoryNode.ts View File

@ -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);
}
}

+ 1
- 1
src/views/nodes/resultsComparisonNode.ts View File

@ -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<CommitsQueryResults> {

+ 3
- 3
src/views/nodes/resultsNode.ts View File

@ -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() {

+ 21
- 8
src/views/nodes/viewNode.ts View File

@ -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<ViewNode[]>;
getParent(): ViewNode | undefined {
return this._parent;
}
abstract getTreeItem(): TreeItem | Promise<TreeItem>;
getCommand(): Command | undefined {
@ -104,7 +106,7 @@ export function supportsAutoRefresh(
export abstract class SubscribeableViewNode<TView extends View> extends ViewNode {
protected _disposable: Disposable;
protected _subscription: Disposable | undefined;
protected _subscription: Promise<Disposable | undefined> | 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<Disposable | undefined>;
protected unsubscribe(): void {
protected async unsubscribe(): Promise<void> {
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;
}
}

+ 3
- 3
src/views/viewBase.ts View File

@ -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);
}

Loading…
Cancel
Save