Skip to content

Commit

Permalink
Fixes issues w/ dynamic PR lookup
Browse files Browse the repository at this point in the history
Fixes #2177, fixes #2185, fixes #2180, fixes #2179
  • Loading branch information
eamodio committed Sep 5, 2022
1 parent 32d5062 commit a3d6b71
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 49 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

### Fixed

- Fixes [#2177](https://github.com/gitkraken/vscode-gitlens/issues/2177) - Open Changes action unresponsive in Source Control view
- Fixes [#2185](https://github.com/gitkraken/vscode-gitlens/issues/2185) - Commits view files are sometimes not shown when expanding folders
- Fixes [#2180](https://github.com/gitkraken/vscode-gitlens/issues/2180) - Tree files view of commits is broken
- Fixes [#2179](https://github.com/gitkraken/vscode-gitlens/issues/2179) - Commit Graph content not displayed
- 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))

## [12.2.1] - 2022-09-01
Expand Down
35 changes: 20 additions & 15 deletions src/views/nodes/branchNode.ts
@@ -1,7 +1,8 @@
import { MarkdownString, ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState, Uri, window } from 'vscode';
import type { ViewShowBranchComparison } from '../../configuration';
import { ViewBranchesLayout } from '../../configuration';
import { Colors, GlyphChars } from '../../constants';
import { Colors, ContextKeys, GlyphChars } from '../../constants';
import { getContext } from '../../context';
import type { GitUri } from '../../git/gitUri';
import type { GitBranch } from '../../git/models/branch';
import type { GitLog } from '../../git/models/log';
Expand Down Expand Up @@ -146,7 +147,8 @@ export class BranchNode
if (
this.view.config.pullRequests.enabled &&
this.view.config.pullRequests.showForBranches &&
(branch.upstream != null || branch.remote)
(branch.upstream != null || branch.remote) &&
getContext(ContextKeys.HasConnectedRemotes)
) {
pullRequest = this.getState('pullRequest');
if (pullRequest === undefined && this.getState('pendingPullRequest') === undefined) {
Expand All @@ -157,9 +159,18 @@ export class BranchNode
);

queueMicrotask(async () => {
const [prResult] = await Promise.allSettled([prPromise, onCompleted?.promise]);
await onCompleted?.promise;

// If we are waiting too long, refresh this node to show a spinner while the pull request is loading
let spinner = false;
const timeout = setTimeout(() => {
spinner = true;
this.view.triggerNodeChange(this);
}, 250);

const pr = await prPromise;
clearTimeout(timeout);

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

// Refresh this node to add or remove the pull request node
this.view.triggerNodeChange(this);
// Refresh this node to add the pull request node or remove the spinner
if (spinner || pr != null) {
this.view.triggerNodeChange(this);
}
});

// // If we are showing the node, then refresh this node to show a spinner while the pull request is loading
// if (!this.splatted) {
// void onCompleted?.promise.then(
// () => this.view.triggerNodeChange(this),
// () => {},
// );
// }
}
}

Expand Down Expand Up @@ -326,7 +331,7 @@ export class BranchNode
}

this._children = children;
onCompleted?.fulfill();
setTimeout(() => onCompleted?.fulfill(), 1);
}

return this._children;
Expand Down
10 changes: 10 additions & 0 deletions src/views/nodes/commitFileNode.ts
Expand Up @@ -15,6 +15,11 @@ import type { ViewNode } from './viewNode';
import { ContextValues, ViewRefFileNode } from './viewNode';

export class CommitFileNode<TView extends View = ViewsWithCommits | FileHistoryView> extends ViewRefFileNode<TView> {
static key = ':file';
static getId(parent: ViewNode, path: string): string {
return `${parent.id}${this.key}(${path})`;
}

constructor(
view: TView,
parent: ViewNode,
Expand All @@ -33,6 +38,10 @@ export class CommitFileNode<TView extends View = ViewsWithCommits | FileHistoryV
return this.file.path;
}

override get id(): string {
return CommitFileNode.getId(this.parent, this.file.path);
}

get priority(): number {
return 0;
}
Expand Down Expand Up @@ -63,6 +72,7 @@ export class CommitFileNode<TView extends View = ViewsWithCommits | FileHistoryV
}

const item = new TreeItem(this.label, TreeItemCollapsibleState.None);
item.id = this.id;
item.contextValue = this.contextValue;
item.description = this.description;
item.resourceUri = Uri.parse(`gitlens-view://commit-file/status/${this.file.status}`);
Expand Down
39 changes: 23 additions & 16 deletions src/views/nodes/commitNode.ts
Expand Up @@ -2,7 +2,8 @@ import type { Command } from 'vscode';
import { MarkdownString, ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode';
import type { DiffWithPreviousCommandArgs } from '../../commands';
import { configuration, ViewFilesLayout } from '../../configuration';
import { Colors, Commands } from '../../constants';
import { Colors, Commands, ContextKeys } from '../../constants';
import { getContext } from '../../context';
import { CommitFormatter } from '../../git/formatters/commitFormatter';
import type { GitBranch } from '../../git/models/branch';
import type { GitCommit } from '../../git/models/commit';
Expand All @@ -23,7 +24,6 @@ import { CommitFileNode } from './commitFileNode';
import type { FileNode } from './folderNode';
import { FolderNode } from './folderNode';
import { PullRequestNode } from './pullRequestNode';
import { RepositoryNode } from './repositoryNode';
import type { ViewNode } from './viewNode';
import { ContextValues, ViewRefNode } from './viewNode';

Expand All @@ -34,8 +34,8 @@ type State = {

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

constructor(
Expand All @@ -55,7 +55,7 @@ export class CommitNode extends ViewRefNode<ViewsWithCommits | FileHistoryView,
}

override get id(): string {
return CommitNode.getId(this.parent, this.commit.repoPath, this.commit.sha);
return CommitNode.getId(this.parent, this.commit.sha);
}

get isTip(): boolean {
Expand All @@ -79,6 +79,8 @@ export class CommitNode extends ViewRefNode<ViewsWithCommits | FileHistoryView,
if (
!(this.view instanceof TagsView) &&
!(this.view instanceof FileHistoryView) &&
!this.unpublished &&
getContext(ContextKeys.HasConnectedRemotes) &&
this.view.config.pullRequests.enabled &&
this.view.config.pullRequests.showForCommits
) {
Expand All @@ -88,9 +90,18 @@ export class CommitNode extends ViewRefNode<ViewsWithCommits | FileHistoryView,
const prPromise = this.getAssociatedPullRequest(commit);

queueMicrotask(async () => {
const [prResult] = await Promise.allSettled([prPromise, onCompleted?.promise]);
await onCompleted?.promise;

// If we are waiting too long, refresh this node to show a spinner while the pull request is loading
let spinner = false;
const timeout = setTimeout(() => {
spinner = true;
this.view.triggerNodeChange(this);
}, 250);

const pr = await prPromise;
clearTimeout(timeout);

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

// Refresh this node to add or remove the pull request node
this.view.triggerNodeChange(this);
// Refresh this node to add the pull request node or remove the spinner
if (spinner || pr != null) {
this.view.triggerNodeChange(this);
}
});

// // Refresh this node to show a spinner while the pull request is loading
// void onCompleted?.promise.then(
// () => this.view.triggerNodeChange(this),
// () => {},
// );
}
}

Expand Down Expand Up @@ -136,7 +143,7 @@ export class CommitNode extends ViewRefNode<ViewsWithCommits | FileHistoryView,
}

this._children = children;
onCompleted?.fulfill();
setTimeout(() => onCompleted?.fulfill(), 1);
}

return this._children;
Expand Down
10 changes: 10 additions & 0 deletions src/views/nodes/folderNode.ts
Expand Up @@ -21,6 +21,11 @@ export interface FileNode extends ViewFileNode {
}

export class FolderNode extends ViewNode<ViewsWithCommits | FileHistoryView | StashesView> {
static key = ':folder';
static getId(parent: ViewNode, path: string): string {
return `${parent.id}${this.key}(${path})`;
}

readonly priority: number = 1;

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

override get id(): string {
return FolderNode.getId(this.parent, this.folderName);
}

getChildren(): (FolderNode | FileNode)[] {
if (this.root.descendants === undefined || this.root.children === undefined) return [];

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

getTreeItem(): TreeItem {
const item = new TreeItem(this.label, TreeItemCollapsibleState.Expanded);
item.id = this.id;
item.contextValue = ContextValues.Folder;
if (this.containsWorkingFiles) {
item.contextValue += '+working';
Expand Down
7 changes: 3 additions & 4 deletions src/views/nodes/pullRequestNode.ts
Expand Up @@ -5,13 +5,12 @@ import type { GitCommit } from '../../git/models/commit';
import { isCommit } from '../../git/models/commit';
import { PullRequest, PullRequestState } from '../../git/models/pullRequest';
import type { ViewsWithCommits } from '../viewBase';
import { RepositoryNode } from './repositoryNode';
import { ContextValues, ViewNode } from './viewNode';

export class PullRequestNode extends ViewNode<ViewsWithCommits> {
static key = ':pullrequest';
static getId(parent: ViewNode, repoPath: string, id: string, ref?: string): string {
return `${parent.id}|${RepositoryNode.getId(repoPath)}${this.key}(${id}):${ref}`;
static getId(parent: ViewNode, id: string, ref?: string): string {
return `${parent.id}${this.key}(${id}):${ref}`;
}

public readonly pullRequest: PullRequest;
Expand Down Expand Up @@ -45,7 +44,7 @@ export class PullRequestNode extends ViewNode<ViewsWithCommits> {
}

override get id(): string {
return PullRequestNode.getId(this.parent, this.repoPath, this.pullRequest.id, this.branchOrCommit?.ref);
return PullRequestNode.getId(this.parent, this.pullRequest.id, this.branchOrCommit?.ref);
}

getChildren(): ViewNode[] {
Expand Down
33 changes: 19 additions & 14 deletions src/views/nodes/worktreeNode.ts
@@ -1,5 +1,6 @@
import { MarkdownString, ThemeIcon, TreeItem, TreeItemCollapsibleState, Uri, window } from 'vscode';
import { GlyphChars } from '../../constants';
import { ContextKeys, GlyphChars } from '../../constants';
import { getContext } from '../../context';
import type { GitUri } from '../../git/gitUri';
import type { GitBranch } from '../../git/models/branch';
import type { GitLog } from '../../git/models/log';
Expand Down Expand Up @@ -72,7 +73,8 @@ export class WorktreeNode extends ViewNode<WorktreesView | RepositoriesView, Sta
branch != null &&
this.view.config.pullRequests.enabled &&
this.view.config.pullRequests.showForBranches &&
(branch.upstream != null || branch.remote)
(branch.upstream != null || branch.remote) &&
getContext(ContextKeys.HasConnectedRemotes)
) {
pullRequest = this.getState('pullRequest');
if (pullRequest === undefined && this.getState('pendingPullRequest') === undefined) {
Expand All @@ -82,9 +84,18 @@ export class WorktreeNode extends ViewNode<WorktreesView | RepositoriesView, Sta
});

queueMicrotask(async () => {
const [prResult] = await Promise.allSettled([prPromise, onCompleted?.promise]);
await onCompleted?.promise;

// If we are waiting too long, refresh this node to show a spinner while the pull request is loading
let spinner = false;
const timeout = setTimeout(() => {
spinner = true;
this.view.triggerNodeChange(this);
}, 250);

const pr = await prPromise;
clearTimeout(timeout);

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

// Refresh this node to add or remove the pull request node
this.view.triggerNodeChange(this);
// Refresh this node to add the pull request node or remove the spinner
if (spinner || pr != null) {
this.view.triggerNodeChange(this);
}
});

// // If we are showing the node, then refresh this node to show a spinner while the pull request is loading
// if (!this.splatted) {
// void onCompleted?.promise.then(
// () => this.view.triggerNodeChange(this),
// () => {},
// );
// }
}
}

Expand Down

0 comments on commit a3d6b71

Please sign in to comment.