diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a70cc0..12462e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ### Fixed +- Fixes [2742](https://github.com/gitkraken/vscode-gitlens/issues/2742) - Search & Compare: Element with id ... is already registered - Fixes an issue where the links in the _Search & Compare_ view failed to open the specific search type - Fixes an issue when searching for commits and the results contain stashes diff --git a/src/views/nodes/resultsCommitsNode.ts b/src/views/nodes/resultsCommitsNode.ts index 6619d49..768ca36 100644 --- a/src/views/nodes/resultsCommitsNode.ts +++ b/src/views/nodes/resultsCommitsNode.ts @@ -6,7 +6,8 @@ import { configuration } from '../../system/configuration'; import { gate } from '../../system/decorators/gate'; import { debug } from '../../system/decorators/log'; import { map } from '../../system/iterable'; -import { cancellable, PromiseCancelledError } from '../../system/promise'; +import type { Deferred } from '../../system/promise'; +import { cancellable, defer, PromiseCancelledError } from '../../system/promise'; import type { ViewsWithCommits } from '../viewBase'; import { AutolinkedItemsNode } from './autolinkedItemsNode'; import { CommitNode } from './commitNode'; @@ -76,7 +77,12 @@ export class ResultsCommitsNode | undefined; + async getChildren(): Promise { + this._onChildrenCompleted?.cancel(); + this._onChildrenCompleted = defer(); + const { log } = await this.getCommitsQueryResults(); if (log == null) return []; @@ -126,6 +132,7 @@ export class ResultsCommitsNode this.triggerChange(false)); + setTimeout(async () => { + void (await ex.promise); + try { + await this._onChildrenCompleted?.promise; + } catch {} + + setTimeout(() => void this.triggerChange(false), 1); + }, 1); } // Need to use Collapsed before we have results or the item won't show up in the view until the children are awaited @@ -171,24 +185,34 @@ export class ResultsCommitsNode | undefined; + private _commitsQueryResultsPromise: Promise | undefined; private async getCommitsQueryResults() { - if (this._commitsQueryResults == null) { - this._commitsQueryResults = this._results.query(this.limit ?? configuration.get('advanced.maxSearchItems')); - const results = await this._commitsQueryResults; + if (this._commitsQueryResultsPromise == null) { + this._commitsQueryResultsPromise = this._results.query( + this.limit ?? configuration.get('advanced.maxSearchItems'), + ); + const results = await this._commitsQueryResultsPromise; + this._commitsQueryResults = results; + this._hasMore = results.hasMore; if (this._results.deferred) { this._results.deferred = false; - void this.triggerChange(false); + // void this.triggerChange(false); } } + return this._commitsQueryResultsPromise; + } + + private _commitsQueryResults: CommitsQueryResults | undefined; + private maybeGetCommitsQueryResults(): CommitsQueryResults | undefined { return this._commitsQueryResults; }