Skip to content

Commit a3d6b71

Browse files
committed
Fixes issues w/ dynamic PR lookup
Fixes #2177, fixes #2185, fixes #2180, fixes #2179
1 parent 32d5062 commit a3d6b71

File tree

7 files changed

+89
-49
lines changed

7 files changed

+89
-49
lines changed

CHANGELOG.md

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

99
### Fixed
1010

11+
- Fixes [#2177](https://github.com/gitkraken/vscode-gitlens/issues/2177) - Open Changes action unresponsive in Source Control view
12+
- Fixes [#2185](https://github.com/gitkraken/vscode-gitlens/issues/2185) - Commits view files are sometimes not shown when expanding folders
13+
- Fixes [#2180](https://github.com/gitkraken/vscode-gitlens/issues/2180) - Tree files view of commits is broken
14+
- Fixes [#2179](https://github.com/gitkraken/vscode-gitlens/issues/2179) - Commit Graph content not displayed
1115
- Fixes [#2187](https://github.com/gitkraken/vscode-gitlens/issues/2187) - scm/title commands shown against non-Git SCM providers — thanks to [PR #2186](https://github.com/gitkraken/vscode-gitlens/pull/2186) by Matt Seddon ([@mattseddon](https://github.com/mattseddon))
1216

1317
## [12.2.1] - 2022-09-01

src/views/nodes/branchNode.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { MarkdownString, ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState, Uri, window } from 'vscode';
22
import type { ViewShowBranchComparison } from '../../configuration';
33
import { ViewBranchesLayout } from '../../configuration';
4-
import { Colors, GlyphChars } from '../../constants';
4+
import { Colors, ContextKeys, GlyphChars } from '../../constants';
5+
import { getContext } from '../../context';
56
import type { GitUri } from '../../git/gitUri';
67
import type { GitBranch } from '../../git/models/branch';
78
import type { GitLog } from '../../git/models/log';
@@ -146,7 +147,8 @@ export class BranchNode
146147
if (
147148
this.view.config.pullRequests.enabled &&
148149
this.view.config.pullRequests.showForBranches &&
149-
(branch.upstream != null || branch.remote)
150+
(branch.upstream != null || branch.remote) &&
151+
getContext(ContextKeys.HasConnectedRemotes)
150152
) {
151153
pullRequest = this.getState('pullRequest');
152154
if (pullRequest === undefined && this.getState('pendingPullRequest') === undefined) {
@@ -157,9 +159,18 @@ export class BranchNode
157159
);
158160

159161
queueMicrotask(async () => {
160-
const [prResult] = await Promise.allSettled([prPromise, onCompleted?.promise]);
162+
await onCompleted?.promise;
163+
164+
// If we are waiting too long, refresh this node to show a spinner while the pull request is loading
165+
let spinner = false;
166+
const timeout = setTimeout(() => {
167+
spinner = true;
168+
this.view.triggerNodeChange(this);
169+
}, 250);
170+
171+
const pr = await prPromise;
172+
clearTimeout(timeout);
161173

162-
const pr = getSettledValue(prResult);
163174
// If we found a pull request, insert it into the children cache (if loaded) and refresh the node
164175
if (pr != null && this._children != null) {
165176
this._children.splice(
@@ -169,17 +180,11 @@ export class BranchNode
169180
);
170181
}
171182

172-
// Refresh this node to add or remove the pull request node
173-
this.view.triggerNodeChange(this);
183+
// Refresh this node to add the pull request node or remove the spinner
184+
if (spinner || pr != null) {
185+
this.view.triggerNodeChange(this);
186+
}
174187
});
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-
// }
183188
}
184189
}
185190

@@ -326,7 +331,7 @@ export class BranchNode
326331
}
327332

328333
this._children = children;
329-
onCompleted?.fulfill();
334+
setTimeout(() => onCompleted?.fulfill(), 1);
330335
}
331336

332337
return this._children;

src/views/nodes/commitFileNode.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import type { ViewNode } from './viewNode';
1515
import { ContextValues, ViewRefFileNode } from './viewNode';
1616

1717
export class CommitFileNode<TView extends View = ViewsWithCommits | FileHistoryView> extends ViewRefFileNode<TView> {
18+
static key = ':file';
19+
static getId(parent: ViewNode, path: string): string {
20+
return `${parent.id}${this.key}(${path})`;
21+
}
22+
1823
constructor(
1924
view: TView,
2025
parent: ViewNode,
@@ -33,6 +38,10 @@ export class CommitFileNode<TView extends View = ViewsWithCommits | FileHistoryV
3338
return this.file.path;
3439
}
3540

41+
override get id(): string {
42+
return CommitFileNode.getId(this.parent, this.file.path);
43+
}
44+
3645
get priority(): number {
3746
return 0;
3847
}
@@ -63,6 +72,7 @@ export class CommitFileNode<TView extends View = ViewsWithCommits | FileHistoryV
6372
}
6473

6574
const item = new TreeItem(this.label, TreeItemCollapsibleState.None);
75+
item.id = this.id;
6676
item.contextValue = this.contextValue;
6777
item.description = this.description;
6878
item.resourceUri = Uri.parse(`gitlens-view://commit-file/status/${this.file.status}`);

src/views/nodes/commitNode.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import type { Command } from 'vscode';
22
import { MarkdownString, ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode';
33
import type { DiffWithPreviousCommandArgs } from '../../commands';
44
import { configuration, ViewFilesLayout } from '../../configuration';
5-
import { Colors, Commands } from '../../constants';
5+
import { Colors, Commands, ContextKeys } from '../../constants';
6+
import { getContext } from '../../context';
67
import { CommitFormatter } from '../../git/formatters/commitFormatter';
78
import type { GitBranch } from '../../git/models/branch';
89
import type { GitCommit } from '../../git/models/commit';
@@ -23,7 +24,6 @@ import { CommitFileNode } from './commitFileNode';
2324
import type { FileNode } from './folderNode';
2425
import { FolderNode } from './folderNode';
2526
import { PullRequestNode } from './pullRequestNode';
26-
import { RepositoryNode } from './repositoryNode';
2727
import type { ViewNode } from './viewNode';
2828
import { ContextValues, ViewRefNode } from './viewNode';
2929

@@ -34,8 +34,8 @@ type State = {
3434

3535
export class CommitNode extends ViewRefNode<ViewsWithCommits | FileHistoryView, GitRevisionReference, State> {
3636
static key = ':commit';
37-
static getId(parent: ViewNode, repoPath: string, sha: string): string {
38-
return `${parent.id}|${RepositoryNode.getId(repoPath)}${this.key}(${sha})`;
37+
static getId(parent: ViewNode, sha: string): string {
38+
return `${parent.id}${this.key}(${sha})`;
3939
}
4040

4141
constructor(
@@ -55,7 +55,7 @@ export class CommitNode extends ViewRefNode<ViewsWithCommits | FileHistoryView,
5555
}
5656

5757
override get id(): string {
58-
return CommitNode.getId(this.parent, this.commit.repoPath, this.commit.sha);
58+
return CommitNode.getId(this.parent, this.commit.sha);
5959
}
6060

6161
get isTip(): boolean {
@@ -79,6 +79,8 @@ export class CommitNode extends ViewRefNode<ViewsWithCommits | FileHistoryView,
7979
if (
8080
!(this.view instanceof TagsView) &&
8181
!(this.view instanceof FileHistoryView) &&
82+
!this.unpublished &&
83+
getContext(ContextKeys.HasConnectedRemotes) &&
8284
this.view.config.pullRequests.enabled &&
8385
this.view.config.pullRequests.showForCommits
8486
) {
@@ -88,9 +90,18 @@ export class CommitNode extends ViewRefNode<ViewsWithCommits | FileHistoryView,
8890
const prPromise = this.getAssociatedPullRequest(commit);
8991

9092
queueMicrotask(async () => {
91-
const [prResult] = await Promise.allSettled([prPromise, onCompleted?.promise]);
93+
await onCompleted?.promise;
94+
95+
// If we are waiting too long, refresh this node to show a spinner while the pull request is loading
96+
let spinner = false;
97+
const timeout = setTimeout(() => {
98+
spinner = true;
99+
this.view.triggerNodeChange(this);
100+
}, 250);
101+
102+
const pr = await prPromise;
103+
clearTimeout(timeout);
92104

93-
const pr = getSettledValue(prResult);
94105
// If we found a pull request, insert it into the children cache (if loaded) and refresh the node
95106
if (pr != null && this._children != null) {
96107
this._children.splice(
@@ -100,15 +111,11 @@ export class CommitNode extends ViewRefNode<ViewsWithCommits | FileHistoryView,
100111
);
101112
}
102113

103-
// Refresh this node to add or remove the pull request node
104-
this.view.triggerNodeChange(this);
114+
// Refresh this node to add the pull request node or remove the spinner
115+
if (spinner || pr != null) {
116+
this.view.triggerNodeChange(this);
117+
}
105118
});
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-
// );
112119
}
113120
}
114121

@@ -136,7 +143,7 @@ export class CommitNode extends ViewRefNode<ViewsWithCommits | FileHistoryView,
136143
}
137144

138145
this._children = children;
139-
onCompleted?.fulfill();
146+
setTimeout(() => onCompleted?.fulfill(), 1);
140147
}
141148

142149
return this._children;

src/views/nodes/folderNode.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ export interface FileNode extends ViewFileNode {
2121
}
2222

2323
export class FolderNode extends ViewNode<ViewsWithCommits | FileHistoryView | StashesView> {
24+
static key = ':folder';
25+
static getId(parent: ViewNode, path: string): string {
26+
return `${parent.id}${this.key}(${path})`;
27+
}
28+
2429
readonly priority: number = 1;
2530

2631
constructor(
@@ -39,6 +44,10 @@ export class FolderNode extends ViewNode<ViewsWithCommits | FileHistoryView | St
3944
return this.folderName;
4045
}
4146

47+
override get id(): string {
48+
return FolderNode.getId(this.parent, this.folderName);
49+
}
50+
4251
getChildren(): (FolderNode | FileNode)[] {
4352
if (this.root.descendants === undefined || this.root.children === undefined) return [];
4453

@@ -90,6 +99,7 @@ export class FolderNode extends ViewNode<ViewsWithCommits | FileHistoryView | St
9099

91100
getTreeItem(): TreeItem {
92101
const item = new TreeItem(this.label, TreeItemCollapsibleState.Expanded);
102+
item.id = this.id;
93103
item.contextValue = ContextValues.Folder;
94104
if (this.containsWorkingFiles) {
95105
item.contextValue += '+working';

src/views/nodes/pullRequestNode.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ import type { GitCommit } from '../../git/models/commit';
55
import { isCommit } from '../../git/models/commit';
66
import { PullRequest, PullRequestState } from '../../git/models/pullRequest';
77
import type { ViewsWithCommits } from '../viewBase';
8-
import { RepositoryNode } from './repositoryNode';
98
import { ContextValues, ViewNode } from './viewNode';
109

1110
export class PullRequestNode extends ViewNode<ViewsWithCommits> {
1211
static key = ':pullrequest';
13-
static getId(parent: ViewNode, repoPath: string, id: string, ref?: string): string {
14-
return `${parent.id}|${RepositoryNode.getId(repoPath)}${this.key}(${id}):${ref}`;
12+
static getId(parent: ViewNode, id: string, ref?: string): string {
13+
return `${parent.id}${this.key}(${id}):${ref}`;
1514
}
1615

1716
public readonly pullRequest: PullRequest;
@@ -45,7 +44,7 @@ export class PullRequestNode extends ViewNode<ViewsWithCommits> {
4544
}
4645

4746
override get id(): string {
48-
return PullRequestNode.getId(this.parent, this.repoPath, this.pullRequest.id, this.branchOrCommit?.ref);
47+
return PullRequestNode.getId(this.parent, this.pullRequest.id, this.branchOrCommit?.ref);
4948
}
5049

5150
getChildren(): ViewNode[] {

src/views/nodes/worktreeNode.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { MarkdownString, ThemeIcon, TreeItem, TreeItemCollapsibleState, Uri, window } from 'vscode';
2-
import { GlyphChars } from '../../constants';
2+
import { ContextKeys, GlyphChars } from '../../constants';
3+
import { getContext } from '../../context';
34
import type { GitUri } from '../../git/gitUri';
45
import type { GitBranch } from '../../git/models/branch';
56
import type { GitLog } from '../../git/models/log';
@@ -72,7 +73,8 @@ export class WorktreeNode extends ViewNode<WorktreesView | RepositoriesView, Sta
7273
branch != null &&
7374
this.view.config.pullRequests.enabled &&
7475
this.view.config.pullRequests.showForBranches &&
75-
(branch.upstream != null || branch.remote)
76+
(branch.upstream != null || branch.remote) &&
77+
getContext(ContextKeys.HasConnectedRemotes)
7678
) {
7779
pullRequest = this.getState('pullRequest');
7880
if (pullRequest === undefined && this.getState('pendingPullRequest') === undefined) {
@@ -82,9 +84,18 @@ export class WorktreeNode extends ViewNode<WorktreesView | RepositoriesView, Sta
8284
});
8385

8486
queueMicrotask(async () => {
85-
const [prResult] = await Promise.allSettled([prPromise, onCompleted?.promise]);
87+
await onCompleted?.promise;
88+
89+
// If we are waiting too long, refresh this node to show a spinner while the pull request is loading
90+
let spinner = false;
91+
const timeout = setTimeout(() => {
92+
spinner = true;
93+
this.view.triggerNodeChange(this);
94+
}, 250);
95+
96+
const pr = await prPromise;
97+
clearTimeout(timeout);
8698

87-
const pr = getSettledValue(prResult);
8899
// If we found a pull request, insert it into the children cache (if loaded) and refresh the node
89100
if (pr != null && this._children != null) {
90101
this._children.splice(
@@ -94,17 +105,11 @@ export class WorktreeNode extends ViewNode<WorktreesView | RepositoriesView, Sta
94105
);
95106
}
96107

97-
// Refresh this node to add or remove the pull request node
98-
this.view.triggerNodeChange(this);
108+
// Refresh this node to add the pull request node or remove the spinner
109+
if (spinner || pr != null) {
110+
this.view.triggerNodeChange(this);
111+
}
99112
});
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-
// }
108113
}
109114
}
110115

0 commit comments

Comments
 (0)