@ -11,7 +11,7 @@ import type { GitWorktree } from '../../git/models/worktree';
import { gate } from '../../system/decorators/gate' ;
import { debug } from '../../system/decorators/log' ;
import { map } from '../../system/iterable' ;
import type { Deferred } from '../../system/promise' ;
import type { Deferred } from '../../system/promise' ;
import { defer , getSettledValue } from '../../system/promise' ;
import { pad } from '../../system/string' ;
import type { RepositoriesView } from '../repositoriesView' ;
@ -65,9 +65,8 @@ export class WorktreeNode extends ViewNode
if ( this . _children == null ) {
const branch = this . _branch ;
let pullRequest ;
let onCompleted : Deferred < void > | undefined ;
let pullRequest ;
if (
branch != null &&
@ -78,34 +77,34 @@ export class WorktreeNode extends ViewNode
pullRequest = this . getState ( 'pullRequest' ) ;
if ( pullRequest === undefined && this . getState ( 'pendingPullRequest' ) === undefined ) {
onCompleted = defer < void > ( ) ;
const prPromise = this . getAssociatedPullRequest ( branch , {
include : [ PullRequestState . Open , PullRequestState . Merged ] ,
} ) ;
queueMicrotask ( ( ) = > {
void this . getAssociatedPullRequest ( branch , {
include : [ PullRequestState . Open , PullRequestState . Merged ] ,
} ) . then ( pr = > {
onCompleted ? . cancel ( ) ;
// 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 (
this . _children [ 0 ] instanceof CompareBranchNode ? 1 : 0 ,
0 ,
new PullRequestNode ( this . view , this , pr , branch ) ,
) ;
}
// Refresh this node to show a spinner while the pull request is loading
this . view . triggerNodeChange ( this ) ;
} ) ;
queueMicrotask ( async ( ) = > {
const [ prResult ] = await Promise . allSettled ( [ prPromise , onCompleted ? . promise ] ) ;
// 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 ) ,
( ) = > { } ,
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 (
this . _children [ 0 ] instanceof CompareBranchNode ? 1 : 0 ,
0 ,
new PullRequestNode ( this . view , this , pr , branch ) ,
) ;
}
// Refresh this node to add or remove the pull request node
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),
// () => {},
// );
// }
}
}
@ -179,7 +178,7 @@ export class WorktreeNode extends ViewNode
}
this . _children = children ;
setTimeout ( ( ) = > onCompleted? . fulfill ( ) , 0 ) ;
onCompleted ? . fulfill ( ) ;
}
return this . _children ;