Browse Source

Fixes issues with auto-refresh

main
Eric Amodio 7 years ago
parent
commit
695889f61c
5 changed files with 49 additions and 39 deletions
  1. +4
    -0
      src/views/explorerNode.ts
  2. +18
    -18
      src/views/fileHistoryNode.ts
  3. +7
    -0
      src/views/gitExplorer.ts
  4. +14
    -15
      src/views/repositoryNode.ts
  5. +6
    -6
      src/views/statusNode.ts

+ 4
- 0
src/views/explorerNode.ts View File

@ -27,17 +27,21 @@ export declare type ResourceType =
'gitlens:status-file-commits' |
'gitlens:status-upstream';
// let id = 0;
export abstract class ExplorerNode extends Disposable {
abstract readonly resourceType: ResourceType;
protected children: ExplorerNode[] | undefined;
protected disposable: Disposable | undefined;
// protected readonly id: number;
constructor(
public readonly uri: GitUri
) {
super(() => this.dispose());
// this.id = id++;
}
dispose() {

+ 18
- 18
src/views/fileHistoryNode.ts View File

@ -20,6 +20,8 @@ export class FileHistoryNode extends ExplorerNode {
}
async getChildren(): Promise<ExplorerNode[]> {
this.updateSubscription();
const log = await this.explorer.git.getLogForFile(this.uri.repoPath, this.uri.fsPath, this.uri.sha);
if (log === undefined) return [new MessageNode('No file history')];
@ -27,18 +29,7 @@ export class FileHistoryNode extends ExplorerNode {
}
getTreeItem(): TreeItem {
if (this.disposable !== undefined) {
this.disposable.dispose();
this.disposable = undefined;
}
// We only need to subscribe if auto-refresh is enabled, because if it becomes enabled we will be refreshed
if (this.explorer.autoRefresh) {
this.disposable = Disposable.from(
this.explorer.onDidChangeAutoRefresh(this.onAutoRefreshChanged, this),
this.repo.onDidChange(this.onRepoChanged, this)
);
}
this.updateSubscription();
const item = new TreeItem(`${this.uri.getFormattedPath()}`, TreeItemCollapsibleState.Expanded);
item.contextValue = this.resourceType;
@ -51,13 +42,22 @@ export class FileHistoryNode extends ExplorerNode {
return item;
}
private onAutoRefreshChanged() {
if (this.disposable === undefined) return;
private updateSubscription() {
// We only need to subscribe if auto-refresh is enabled, because if it becomes enabled we will be refreshed
if (this.explorer.autoRefresh) {
this.disposable = this.disposable || Disposable.from(
this.explorer.onDidChangeAutoRefresh(this.onAutoRefreshChanged, this),
this.repo.onDidChange(this.onRepoChanged, this)
);
}
else if (this.disposable !== undefined) {
this.disposable.dispose();
this.disposable = undefined;
}
}
// If auto-refresh changes, just kill the subscriptions
// (if it was enabled -- we will get refreshed so we don't have to worry about re-hooking it up here)
this.disposable.dispose();
this.disposable = undefined;
private onAutoRefreshChanged() {
this.updateSubscription();
}
private onRepoChanged(e: RepositoryChangeEvent) {

+ 7
- 0
src/views/gitExplorer.ts View File

@ -235,6 +235,13 @@ export class GitExplorer implements TreeDataProvider {
refreshNode(node: ExplorerNode, args?: RefreshNodeCommandArgs) {
Logger.log(`GitExplorer[view=${this._view}].refreshNode`);
// Since the root node won't actually refresh, force it
if (node === this._root) {
this._onDidChangeTreeData.fire();
return;
}
if (args !== undefined && node instanceof BranchHistoryNode) {
node.maxCount = args.maxCount;
}

+ 14
- 15
src/views/repositoryNode.ts View File

@ -25,6 +25,7 @@ export class RepositoryNode extends ExplorerNode {
async getChildren(): Promise<ExplorerNode[]> {
this.resetChildren();
this.updateSubscription();
this.children = [
new StatusNode(this.uri, this.repo, this, this.explorer),
@ -36,31 +37,29 @@ export class RepositoryNode extends ExplorerNode {
}
getTreeItem(): TreeItem {
if (this.disposable !== undefined) {
this.disposable.dispose();
this.disposable = undefined;
}
this.updateSubscription();
const item = new TreeItem(`Repository ${Strings.pad(GlyphChars.Dash, 1, 1)} ${this.repo.name || this.uri.repoPath}`, TreeItemCollapsibleState.Expanded);
item.contextValue = this.resourceType;
return item;
}
private updateSubscription() {
// We only need to subscribe if auto-refresh is enabled, because if it becomes enabled we will be refreshed
if (this.explorer.autoRefresh) {
this.disposable = Disposable.from(
this.disposable = this.disposable || Disposable.from(
this.explorer.onDidChangeAutoRefresh(this.onAutoRefreshChanged, this),
this.repo.onDidChange(this.onRepoChanged, this)
);
}
const item = new TreeItem(`Repository ${Strings.pad(GlyphChars.Dash, 1, 1)} ${this.repo.name || this.uri.repoPath}`, TreeItemCollapsibleState.Expanded);
item.contextValue = this.resourceType;
return item;
else if (this.disposable !== undefined) {
this.disposable.dispose();
this.disposable = undefined;
}
}
private onAutoRefreshChanged() {
if (this.disposable === undefined) return;
// If auto-refresh changes, just kill the subscriptions
// (if it was enabled -- we will get refreshed so we don't have to worry about re-hooking it up here)
this.disposable.dispose();
this.disposable = undefined;
this.updateSubscription();
}
private onRepoChanged(e: RepositoryChangeEvent) {

+ 6
- 6
src/views/statusNode.ts View File

@ -1,4 +1,4 @@
import { commands, Disposable, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { Disposable, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { ExplorerNode, ResourceType } from './explorerNode';
import { GitExplorer } from './gitExplorer';
import { GitStatus, GitUri, Repository, RepositoryFileSystemChangeEvent } from '../gitService';
@ -24,7 +24,7 @@ export class StatusNode extends ExplorerNode {
this.children = [];
const status = await this.explorer.git.getStatusForRepo(this.uri.repoPath!);
const status = await this.repo.getStatus();
if (status === undefined) return this.children;
if (status.state.behind) {
@ -53,7 +53,7 @@ export class StatusNode extends ExplorerNode {
this.disposable = undefined;
}
const status = await this.explorer.git.getStatusForRepo(this.uri.repoPath!);
const status = await this.repo.getStatus();
if (status === undefined) return new TreeItem('No repo status');
if (this.explorer.autoRefresh && this.includeWorkingTree) {
@ -120,7 +120,7 @@ export class StatusNode extends ExplorerNode {
}
private async onFileSystemChanged(e: RepositoryFileSystemChangeEvent) {
const status = await this.explorer.git.getStatusForRepo(this.uri.repoPath!);
const status = await this.repo.getStatus();
// If we haven't changed from having some working changes to none or vice versa then just refresh the node
// This is because of https://github.com/Microsoft/vscode/issues/34789
@ -128,12 +128,12 @@ export class StatusNode extends ExplorerNode {
((this._status.files.length === status.files.length) || (this._status.files.length > 0 && status.files.length > 0))) {
Logger.log(`StatusNode.onFileSystemChanged; triggering node refresh`);
commands.executeCommand('gitlens.gitExplorer.refreshNode', this);
this.explorer.refreshNode(this);
return;
}
Logger.log(`StatusNode.onFileSystemChanged; triggering parent node refresh`);
commands.executeCommand('gitlens.gitExplorer.refreshNode', this.parent);
this.explorer.refreshNode(this.parent);
}
}

Loading…
Cancel
Save