From 3dd302ce741f9e7af58a90c7fd053391b373f6a5 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Fri, 27 Oct 2017 16:17:05 -0400 Subject: [PATCH] Adds logging to explorer refresh --- src/views/gitExplorer.ts | 32 +++++++++++++++++++++++++------- src/views/statusNode.ts | 4 ++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/views/gitExplorer.ts b/src/views/gitExplorer.ts index b4f5459..14b532a 100644 --- a/src/views/gitExplorer.ts +++ b/src/views/gitExplorer.ts @@ -7,9 +7,20 @@ import { ExtensionKey, GitExplorerFilesLayout, IConfig } from '../configuration' import { CommandContext, GlyphChars, setCommandContext, WorkspaceState } from '../constants'; import { BranchHistoryNode, CommitFileNode, CommitNode, ExplorerNode, HistoryNode, MessageNode, RepositoriesNode, RepositoryNode, StashNode } from './explorerNodes'; import { GitService, GitUri, RepoChangedReasons } from '../gitService'; +import { Logger } from '../logger'; export * from './explorerNodes'; +enum RefreshReason { + ActiveEditorChanged = 'active-editor-changed', + AutoRefreshChanged = 'auto-refresh-changed', + Command = 'command', + NodeCommand = 'node-command', + RepoChanged = 'repo-changed', + ViewChanged = 'view-changed', + VisibleEditorsChanged = 'visible-editors-changed' +} + export enum GitExplorerView { Auto = 'auto', History = 'history', @@ -139,7 +150,7 @@ export class GitExplorer implements TreeDataProvider { if (root === this._root) return; this._root = root; - this.refresh(undefined, root); + this.refresh(RefreshReason.ActiveEditorChanged, undefined, root); } private onConfigurationChanged() { @@ -175,7 +186,9 @@ export class GitExplorer implements TreeDataProvider { this._root = undefined; } - this.refresh(); + Logger.log(`GitExplorer[view=${this._view}].onRepoChanged(${reasons.join()})`); + + this.refresh(RefreshReason.RepoChanged); } private onVisibleEditorsChanged(editors: TextEditor[]) { @@ -186,11 +199,16 @@ export class GitExplorer implements TreeDataProvider { if (this._root === undefined) return; this._root = undefined; - this.refresh(); + this.refresh(RefreshReason.VisibleEditorsChanged); } } - async refresh(node?: ExplorerNode, root?: ExplorerNode) { + async refresh(reason: RefreshReason | undefined, node?: ExplorerNode, root?: ExplorerNode) { + if (reason === undefined) { + reason = RefreshReason.Command; + } + Logger.log(`GitExplorer[view=${this._view}].refresh`, `reason='${reason}'`); + if (this._root === undefined || (root === undefined && this._view === GitExplorerView.History)) { this._root = await this.getRootNode(window.activeTextEditor); } @@ -203,7 +221,7 @@ export class GitExplorer implements TreeDataProvider { node.maxCount = args.maxCount; } - this.refresh(node); + this.refresh(RefreshReason.NodeCommand, node); } async reset(view: GitExplorerView, force: boolean = false) { @@ -214,7 +232,7 @@ export class GitExplorer implements TreeDataProvider { } this._root = await this.getRootNode(window.activeTextEditor); if (force) { - this.refresh(); + this.refresh(RefreshReason.ViewChanged); } } @@ -352,7 +370,7 @@ export class GitExplorer implements TreeDataProvider { setCommandContext(CommandContext.GitExplorerAutoRefresh, enabled); if (userToggle) { - this.refresh(); + this.refresh(RefreshReason.AutoRefreshChanged); } } diff --git a/src/views/statusNode.ts b/src/views/statusNode.ts index 9115418..a5c18dd 100644 --- a/src/views/statusNode.ts +++ b/src/views/statusNode.ts @@ -2,6 +2,7 @@ import { commands, ExtensionContext, TreeItem, TreeItemCollapsibleState, Uri } f import { WorkspaceState } from '../constants'; import { ExplorerNode, ResourceType } from './explorerNode'; import { GitService, GitStatus, GitUri, Repository, RepositoryStorage } from '../gitService'; +import { Logger } from '../logger'; import { StatusFilesNode } from './statusFilesNode'; import { StatusUpstreamNode } from './statusUpstreamNode'; @@ -115,11 +116,14 @@ export class StatusNode extends ExplorerNode { // This is because of https://github.com/Microsoft/vscode/issues/34789 if (this._status !== undefined && status !== undefined && ((this._status.files.length === status.files.length) || (this._status.files.length > 0 && status.files.length > 0))) { + + Logger.log(`GitExplorer.StatusNode.onFileSystemChanged(${uri && uri.fsPath}); triggering node refresh`); commands.executeCommand('gitlens.gitExplorer.refreshNode', this); return; } + Logger.log(`GitExplorer.StatusNode.onFileSystemChanged(${uri && uri.fsPath}); triggering refresh`); commands.executeCommand('gitlens.gitExplorer.refresh'); } } \ No newline at end of file