Skip to content

Commit 00369f4

Browse files
authored
Add logs for building the tree (#3444)
1 parent 413742b commit 00369f4

File tree

5 files changed

+35
-7
lines changed

5 files changed

+35
-7
lines changed

src/common/logger.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const enum LogLevel {
88

99
const SETTINGS_NAMESPACE = 'githubPullRequests';
1010
const LOG_LEVEL_SETTING = 'logLevel';
11+
export const PR_TREE = 'PullRequestTree';
1112

1213
class Log {
1314
private _outputChannel: vscode.OutputChannel;

src/view/prChangesTreeDataProvider.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7-
import Logger from '../common/logger';
7+
import Logger, { PR_TREE } from '../common/logger';
88
import { FILE_LIST_LAYOUT } from '../common/settingKeys';
99
import { FolderRepositoryManager, SETTINGS_NAMESPACE } from '../github/folderRepositoryManager';
1010
import { PullRequestModel } from '../github/pullRequestModel';
@@ -73,9 +73,11 @@ export class PullRequestChangesTreeDataProvider extends vscode.Disposable implem
7373
reviewModel: ReviewModel,
7474
shouldReveal: boolean,
7575
) {
76+
Logger.appendLine(`Adding PR #${pullRequestModel.number} to tree`, PR_TREE);
7677
if (this._pullRequestManagerMap.has(pullRequestManager)) {
7778
const existingNode = this._pullRequestManagerMap.get(pullRequestManager);
7879
if (existingNode && (existingNode.pullRequestModel === pullRequestModel)) {
80+
Logger.appendLine(`PR #${pullRequestModel.number} already exists in tree`, PR_TREE);
7981
return;
8082
} else {
8183
existingNode?.dispose();
@@ -100,6 +102,8 @@ export class PullRequestChangesTreeDataProvider extends vscode.Disposable implem
100102

101103
async removePrFromView(pullRequestManager: FolderRepositoryManager) {
102104
const oldPR = this._pullRequestManagerMap.has(pullRequestManager) ? this._pullRequestManagerMap.get(pullRequestManager) : undefined;
105+
Logger.appendLine(`Removing PR #${oldPR?.pullRequestModel.number} from tree`, PR_TREE);
106+
103107
oldPR?.dispose();
104108
this._pullRequestManagerMap.delete(pullRequestManager);
105109
this.updateViewTitle();
@@ -132,7 +136,7 @@ export class PullRequestChangesTreeDataProvider extends vscode.Disposable implem
132136
}
133137
}
134138

135-
async getChildren(element?: GitFileChangeNode): Promise<TreeNode[]> {
139+
async getChildren(element?: TreeNode): Promise<TreeNode[]> {
136140
if (!element) {
137141
const result: TreeNode[] = [];
138142
if (this._pullRequestManagerMap.size >= 1) {

src/view/treeNodes/commitsCategoryNode.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7+
import Logger, { PR_TREE } from '../../common/logger';
78
import { FolderRepositoryManager } from '../../github/folderRepositoryManager';
89
import { PullRequestModel } from '../../github/pullRequestModel';
910
import { CommitNode } from './commitNode';
@@ -27,8 +28,14 @@ export class CommitsNode extends TreeNode implements vscode.TreeItem {
2728
this.collapsibleState = vscode.TreeItemCollapsibleState.Collapsed;
2829

2930
this.childrenDisposables = [];
30-
this.childrenDisposables.push(this._pr.onDidChangeReviewThreads(() => this.refresh(this)));
31-
this.childrenDisposables.push(this._pr.onDidChangeComments(() => this.refresh(this)));
31+
this.childrenDisposables.push(this._pr.onDidChangeReviewThreads(() => {
32+
Logger.appendLine(`Review threads have changed, refreshing Commits node`, PR_TREE);
33+
this.refresh(this);
34+
}));
35+
this.childrenDisposables.push(this._pr.onDidChangeComments(() => {
36+
Logger.appendLine(`Comments have changed, refreshing Commits node`, PR_TREE);
37+
this.refresh(this);
38+
}));
3239
}
3340

3441
getTreeItem(): vscode.TreeItem {
@@ -37,10 +44,12 @@ export class CommitsNode extends TreeNode implements vscode.TreeItem {
3744

3845
async getChildren(): Promise<TreeNode[]> {
3946
try {
47+
Logger.appendLine(`Getting children for Commits node`, PR_TREE);
4048
const commits = await this._pr.getCommits();
4149
const commitNodes = commits.map(
4250
(commit, index) => new CommitNode(this, this._folderRepoManager, this._pr, commit, index === commits.length - 1),
4351
);
52+
Logger.appendLine(`Got all children for Commits node`, PR_TREE);
4453
return Promise.resolve(commitNodes);
4554
} catch (e) {
4655
return Promise.resolve([]);

src/view/treeNodes/filesCategoryNode.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7+
import Logger, { PR_TREE } from '../../common/logger';
78
import { PullRequestModel } from '../../github/pullRequestModel';
89
import { ReviewModel } from '../reviewModel';
910
import { DirectoryTreeNode } from './directoryTreeNode';
@@ -22,16 +23,26 @@ export class FilesCategoryNode extends TreeNode implements vscode.TreeItem {
2223
super();
2324
this.collapsibleState = vscode.TreeItemCollapsibleState.Expanded;
2425
this.childrenDisposables = [];
25-
this.childrenDisposables.push(this._reviewModel.onDidChangeLocalFileChanges(() => this.refresh(this)));
26-
this.childrenDisposables.push(_pullRequestModel.onDidChangeReviewThreads(() => this.refresh(this)));
27-
this.childrenDisposables.push(_pullRequestModel.onDidChangeComments(() => this.refresh(this)));
26+
this.childrenDisposables.push(this._reviewModel.onDidChangeLocalFileChanges(() => {
27+
Logger.appendLine(`Local files have changed, refreshing Files node`, PR_TREE);
28+
this.refresh(this);
29+
}));
30+
this.childrenDisposables.push(_pullRequestModel.onDidChangeReviewThreads(() => {
31+
Logger.appendLine(`Review threads have changed, refreshing Files node`, PR_TREE);
32+
this.refresh(this);
33+
}));
34+
this.childrenDisposables.push(_pullRequestModel.onDidChangeComments(() => {
35+
Logger.appendLine(`Comments have changed, refreshing Files node`, PR_TREE);
36+
this.refresh(this);
37+
}));
2838
}
2939

3040
getTreeItem(): vscode.TreeItem {
3141
return this;
3242
}
3343

3444
async getChildren(): Promise<TreeNode[]> {
45+
Logger.appendLine(`Getting children for Files node`, PR_TREE);
3546
if (this._reviewModel.localFileChanges.length === 0) {
3647
// Provide loading feedback until we get the files.
3748
return new Promise<TreeNode[]>(resolve => {
@@ -60,6 +71,7 @@ export class FilesCategoryNode extends TreeNode implements vscode.TreeItem {
6071
} else {
6172
nodes = this._reviewModel.localFileChanges;
6273
}
74+
Logger.appendLine(`Got all children for Files node`, PR_TREE);
6375
return Promise.resolve(nodes);
6476
}
6577
}

src/view/treeNodes/repositoryChangesNode.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7+
import Logger, { PR_TREE } from '../../common/logger';
78
import { FolderRepositoryManager } from '../../github/folderRepositoryManager';
89
import { PullRequestModel } from '../../github/pullRequestModel';
910
import { ReviewModel } from '../reviewModel';
@@ -61,6 +62,7 @@ export class RepositoryChangesNode extends DescriptionNode implements vscode.Tre
6162

6263
async getChildren(): Promise<TreeNode[]> {
6364
if (!this._filesCategoryNode || !this._commitsCategoryNode) {
65+
Logger.appendLine(`Creating file and commit nodes for PR #${this.pullRequestModel.number}`, PR_TREE);
6466
this._filesCategoryNode = new FilesCategoryNode(this.parent, this._reviewModel, this._pullRequest);
6567
this._commitsCategoryNode = new CommitsNode(
6668
this.parent,

0 commit comments

Comments
 (0)