From a3d6b712b2a74eaf33af51d2d30a77e9012f080e Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Mon, 5 Sep 2022 17:54:53 -0400 Subject: [PATCH] Fixes issues w/ dynamic PR lookup Fixes #2177, fixes #2185, fixes #2180, fixes #2179 --- CHANGELOG.md | 4 ++++ src/views/nodes/branchNode.ts | 35 +++++++++++++++++++--------------- src/views/nodes/commitFileNode.ts | 10 ++++++++++ src/views/nodes/commitNode.ts | 39 ++++++++++++++++++++++---------------- src/views/nodes/folderNode.ts | 10 ++++++++++ src/views/nodes/pullRequestNode.ts | 7 +++---- src/views/nodes/worktreeNode.ts | 33 ++++++++++++++++++-------------- 7 files changed, 89 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65488db..c4d43c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/views/nodes/branchNode.ts b/src/views/nodes/branchNode.ts index 39ba75b..0c55b43 100644 --- a/src/views/nodes/branchNode.ts +++ b/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'; @@ -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) { @@ -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( @@ -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), - // () => {}, - // ); - // } } } @@ -326,7 +331,7 @@ export class BranchNode } this._children = children; - onCompleted?.fulfill(); + setTimeout(() => onCompleted?.fulfill(), 1); } return this._children; diff --git a/src/views/nodes/commitFileNode.ts b/src/views/nodes/commitFileNode.ts index 9c1ff83..211397d 100644 --- a/src/views/nodes/commitFileNode.ts +++ b/src/views/nodes/commitFileNode.ts @@ -15,6 +15,11 @@ import type { ViewNode } from './viewNode'; import { ContextValues, ViewRefFileNode } from './viewNode'; export class CommitFileNode extends ViewRefFileNode { + static key = ':file'; + static getId(parent: ViewNode, path: string): string { + return `${parent.id}${this.key}(${path})`; + } + constructor( view: TView, parent: ViewNode, @@ -33,6 +38,10 @@ export class CommitFileNode { 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( @@ -55,7 +55,7 @@ export class CommitNode extends ViewRefNode { - 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( @@ -100,15 +111,11 @@ export class CommitNode extends ViewRefNode this.view.triggerNodeChange(this), - // () => {}, - // ); } } @@ -136,7 +143,7 @@ export class CommitNode extends ViewRefNode onCompleted?.fulfill(), 1); } return this._children; diff --git a/src/views/nodes/folderNode.ts b/src/views/nodes/folderNode.ts index 9a4b10b..fc7899e 100644 --- a/src/views/nodes/folderNode.ts +++ b/src/views/nodes/folderNode.ts @@ -21,6 +21,11 @@ export interface FileNode extends ViewFileNode { } export class FolderNode extends ViewNode { + static key = ':folder'; + static getId(parent: ViewNode, path: string): string { + return `${parent.id}${this.key}(${path})`; + } + readonly priority: number = 1; constructor( @@ -39,6 +44,10 @@ export class FolderNode extends ViewNode { 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; @@ -45,7 +44,7 @@ export class PullRequestNode extends ViewNode { } 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[] { diff --git a/src/views/nodes/worktreeNode.ts b/src/views/nodes/worktreeNode.ts index d20bcc1..efc5c56 100644 --- a/src/views/nodes/worktreeNode.ts +++ b/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'; @@ -72,7 +73,8 @@ export class WorktreeNode extends ViewNode { - 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( @@ -94,17 +105,11 @@ export class WorktreeNode extends ViewNode this.view.triggerNodeChange(this), - // () => {}, - // ); - // } } }