Skip to content

Commit 2760a2f

Browse files
committed
Fixes #2185, #2180 pr node refresh causes issues
I've disabled the refresh to show the spinner icon on the root node to avoid this issue until I can dig into this more. It looks like this is a bug in the VS Code tree view.
1 parent 97a3398 commit 2760a2f

File tree

4 files changed

+82
-82
lines changed

4 files changed

+82
-82
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
88

99
### Fixed
1010

11+
- Fixes [#2185](https://github.com/gitkraken/vscode-gitlens/issues/2185) - Commits view files are sometimes not shown when expanding folders
12+
- Fixes [#2180](https://github.com/gitkraken/vscode-gitlens/issues/2180) - Tree files view of commits is broken
1113
- Fixes [#2179](https://github.com/gitkraken/vscode-gitlens/issues/2179) - Commit Graph content not displayed
1214
- Fixes regression with _Contributors_ view not working
1315

src/views/nodes/branchNode.ts

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,8 @@ export class BranchNode
140140
if (this._children == null) {
141141
const branch = this.branch;
142142

143-
let pullRequest;
144-
145143
let onCompleted: Deferred<void> | undefined;
144+
let pullRequest;
146145

147146
if (
148147
this.view.config.pullRequests.enabled &&
@@ -152,35 +151,35 @@ export class BranchNode
152151
pullRequest = this.getState('pullRequest');
153152
if (pullRequest === undefined && this.getState('pendingPullRequest') === undefined) {
154153
onCompleted = defer<void>();
155-
156-
queueMicrotask(() => {
157-
void this.getAssociatedPullRequest(
158-
branch,
159-
this.root ? { include: [PullRequestState.Open, PullRequestState.Merged] } : undefined,
160-
).then(pr => {
161-
onCompleted?.cancel();
162-
163-
// If we found a pull request, insert it into the children cache (if loaded) and refresh the node
164-
if (pr != null && this._children != null) {
165-
this._children.splice(
166-
this._children[0] instanceof CompareBranchNode ? 1 : 0,
167-
0,
168-
new PullRequestNode(this.view, this, pr, branch),
169-
);
170-
}
171-
172-
// Refresh this node to show a spinner while the pull request is loading
173-
this.view.triggerNodeChange(this);
174-
});
175-
176-
// If we are showing the node, then refresh this node to show a spinner while the pull request is loading
177-
if (!this.splatted) {
178-
void onCompleted?.promise.then(
179-
() => this.view.triggerNodeChange(this),
180-
() => {},
154+
const prPromise = this.getAssociatedPullRequest(
155+
branch,
156+
this.root ? { include: [PullRequestState.Open, PullRequestState.Merged] } : undefined,
157+
);
158+
159+
queueMicrotask(async () => {
160+
const [prResult] = await Promise.allSettled([prPromise, onCompleted?.promise]);
161+
162+
const pr = getSettledValue(prResult);
163+
// If we found a pull request, insert it into the children cache (if loaded) and refresh the node
164+
if (pr != null && this._children != null) {
165+
this._children.splice(
166+
this._children[0] instanceof CompareBranchNode ? 1 : 0,
167+
0,
168+
new PullRequestNode(this.view, this, pr, branch),
181169
);
182170
}
171+
172+
// Refresh this node to add or remove the pull request node
173+
this.view.triggerNodeChange(this);
183174
});
175+
176+
// // If we are showing the node, then refresh this node to show a spinner while the pull request is loading
177+
// if (!this.splatted) {
178+
// void onCompleted?.promise.then(
179+
// () => this.view.triggerNodeChange(this),
180+
// () => {},
181+
// );
182+
// }
184183
}
185184
}
186185

@@ -327,7 +326,7 @@ export class BranchNode
327326
}
328327

329328
this._children = children;
330-
setTimeout(() => onCompleted?.fulfill(), 0);
329+
onCompleted?.fulfill();
331330
}
332331

333332
return this._children;

src/views/nodes/commitNode.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -72,43 +72,43 @@ export class CommitNode extends ViewRefNode<ViewsWithCommits | FileHistoryView,
7272
if (this._children == null) {
7373
const commit = this.commit;
7474

75-
const pullRequest = this.getState('pullRequest');
76-
7775
let children: (PullRequestNode | FileNode)[] = [];
7876
let onCompleted: Deferred<void> | undefined;
77+
let pullRequest;
7978

8079
if (
8180
!(this.view instanceof TagsView) &&
8281
!(this.view instanceof FileHistoryView) &&
8382
this.view.config.pullRequests.enabled &&
8483
this.view.config.pullRequests.showForCommits
8584
) {
85+
pullRequest = this.getState('pullRequest');
8686
if (pullRequest === undefined && this.getState('pendingPullRequest') === undefined) {
8787
onCompleted = defer<void>();
88-
89-
queueMicrotask(() => {
90-
void this.getAssociatedPullRequest(commit).then(pr => {
91-
onCompleted?.cancel();
92-
93-
// If we found a pull request, insert it into the children cache (if loaded) and refresh the node
94-
if (pr != null && this._children != null) {
95-
this._children.splice(
96-
0,
97-
0,
98-
new PullRequestNode(this.view as ViewsWithCommits, this, pr, commit),
99-
);
100-
}
101-
102-
// Refresh this node to show a spinner while the pull request is loading
103-
this.view.triggerNodeChange(this);
104-
});
105-
106-
// Refresh this node to show a spinner while the pull request is loading
107-
void onCompleted?.promise.then(
108-
() => this.view.triggerNodeChange(this),
109-
() => {},
110-
);
88+
const prPromise = this.getAssociatedPullRequest(commit);
89+
90+
queueMicrotask(async () => {
91+
const [prResult] = await Promise.allSettled([prPromise, onCompleted?.promise]);
92+
93+
const pr = getSettledValue(prResult);
94+
// If we found a pull request, insert it into the children cache (if loaded) and refresh the node
95+
if (pr != null && this._children != null) {
96+
this._children.splice(
97+
0,
98+
0,
99+
new PullRequestNode(this.view as ViewsWithCommits, this, pr, commit),
100+
);
101+
}
102+
103+
// Refresh this node to add or remove the pull request node
104+
this.view.triggerNodeChange(this);
111105
});
106+
107+
// // Refresh this node to show a spinner while the pull request is loading
108+
// void onCompleted?.promise.then(
109+
// () => this.view.triggerNodeChange(this),
110+
// () => {},
111+
// );
112112
}
113113
}
114114

@@ -136,7 +136,7 @@ export class CommitNode extends ViewRefNode<ViewsWithCommits | FileHistoryView,
136136
}
137137

138138
this._children = children;
139-
setTimeout(() => onCompleted?.fulfill(), 1);
139+
onCompleted?.fulfill();
140140
}
141141

142142
return this._children;

src/views/nodes/worktreeNode.ts

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { GitWorktree } from '../../git/models/worktree';
1111
import { gate } from '../../system/decorators/gate';
1212
import { debug } from '../../system/decorators/log';
1313
import { map } from '../../system/iterable';
14-
import type { Deferred} from '../../system/promise';
14+
import type { Deferred } from '../../system/promise';
1515
import { defer, getSettledValue } from '../../system/promise';
1616
import { pad } from '../../system/string';
1717
import type { RepositoriesView } from '../repositoriesView';
@@ -65,9 +65,8 @@ export class WorktreeNode extends ViewNode<WorktreesView | RepositoriesView, Sta
6565
if (this._children == null) {
6666
const branch = this._branch;
6767

68-
let pullRequest;
69-
7068
let onCompleted: Deferred<void> | undefined;
69+
let pullRequest;
7170

7271
if (
7372
branch != null &&
@@ -78,34 +77,34 @@ export class WorktreeNode extends ViewNode<WorktreesView | RepositoriesView, Sta
7877
pullRequest = this.getState('pullRequest');
7978
if (pullRequest === undefined && this.getState('pendingPullRequest') === undefined) {
8079
onCompleted = defer<void>();
80+
const prPromise = this.getAssociatedPullRequest(branch, {
81+
include: [PullRequestState.Open, PullRequestState.Merged],
82+
});
8183

82-
queueMicrotask(() => {
83-
void this.getAssociatedPullRequest(branch, {
84-
include: [PullRequestState.Open, PullRequestState.Merged],
85-
}).then(pr => {
86-
onCompleted?.cancel();
87-
88-
// If we found a pull request, insert it into the children cache (if loaded) and refresh the node
89-
if (pr != null && this._children != null) {
90-
this._children.splice(
91-
this._children[0] instanceof CompareBranchNode ? 1 : 0,
92-
0,
93-
new PullRequestNode(this.view, this, pr, branch),
94-
);
95-
}
96-
97-
// Refresh this node to show a spinner while the pull request is loading
98-
this.view.triggerNodeChange(this);
99-
});
84+
queueMicrotask(async () => {
85+
const [prResult] = await Promise.allSettled([prPromise, onCompleted?.promise]);
10086

101-
// If we are showing the node, then refresh this node to show a spinner while the pull request is loading
102-
if (!this.splatted) {
103-
void onCompleted?.promise.then(
104-
() => this.view.triggerNodeChange(this),
105-
() => {},
87+
const pr = getSettledValue(prResult);
88+
// If we found a pull request, insert it into the children cache (if loaded) and refresh the node
89+
if (pr != null && this._children != null) {
90+
this._children.splice(
91+
this._children[0] instanceof CompareBranchNode ? 1 : 0,
92+
0,
93+
new PullRequestNode(this.view, this, pr, branch),
10694
);
10795
}
96+
97+
// Refresh this node to add or remove the pull request node
98+
this.view.triggerNodeChange(this);
10899
});
100+
101+
// // If we are showing the node, then refresh this node to show a spinner while the pull request is loading
102+
// if (!this.splatted) {
103+
// void onCompleted?.promise.then(
104+
// () => this.view.triggerNodeChange(this),
105+
// () => {},
106+
// );
107+
// }
109108
}
110109
}
111110

@@ -179,7 +178,7 @@ export class WorktreeNode extends ViewNode<WorktreesView | RepositoriesView, Sta
179178
}
180179

181180
this._children = children;
182-
setTimeout(() => onCompleted?.fulfill(), 0);
181+
onCompleted?.fulfill();
183182
}
184183

185184
return this._children;

0 commit comments

Comments
 (0)