Bladeren bron

Switches to use Promises.timeout for cleaner impl

main
Eric Amodio 5 jaren geleden
bovenliggende
commit
3c4461abc0
6 gewijzigde bestanden met toevoegingen van 47 en 52 verwijderingen
  1. +1
    -2
      src/views/nodes/compareBranchNode.ts
  2. +1
    -2
      src/views/nodes/compareResultsNode.ts
  3. +27
    -23
      src/views/nodes/resultsCommitsNode.ts
  4. +14
    -18
      src/views/nodes/resultsFilesNode.ts
  5. +2
    -4
      src/views/nodes/searchResultsCommitsNode.ts
  6. +2
    -3
      src/views/searchView.ts

+ 1
- 2
src/views/nodes/compareBranchNode.ts Bestand weergeven

@ -49,8 +49,7 @@ export class CompareBranchNode extends ViewNode {
this.getCommitsQuery.bind(this),
{
expand: false,
includeDescription: false,
querying: true
includeDescription: false
}
),
new ResultsFilesNode(

+ 1
- 2
src/views/nodes/compareResultsNode.ts Bestand weergeven

@ -60,8 +60,7 @@ export class CompareResultsNode extends SubscribeableViewNode {
this.getCommitsQuery.bind(this),
{
expand: false,
includeDescription: true,
querying: true
includeDescription: true
}
),
new ResultsFilesNode(this.view, this, this.uri.repoPath!, this._ref1.ref, this._ref2.ref)

+ 27
- 23
src/views/nodes/resultsCommitsNode.ts Bestand weergeven

@ -2,7 +2,7 @@
import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { Container } from '../../container';
import { GitLog, GitUri } from '../../git/gitService';
import { debug, gate, Iterables } from '../../system';
import { debug, gate, Iterables, Promises } from '../../system';
import { ViewWithFiles } from '../viewBase';
import { CommitNode } from './commitNode';
import { ShowMoreNode } from './common';
@ -25,11 +25,11 @@ export class ResultsCommitsNode extends ViewNode implements Pagea
public readonly repoPath: string,
private _label: string,
private readonly _commitsQuery: (maxCount: number | undefined) => Promise<CommitsQueryResults>,
private readonly _options: { expand?: boolean; includeDescription?: boolean; querying?: boolean } = {}
private readonly _options: { expand?: boolean; includeDescription?: boolean } = {}
) {
super(GitUri.fromRepoPath(repoPath), view, parent);
this._options = { expand: true, includeDescription: true, querying: true, ..._options };
this._options = { expand: true, includeDescription: true, ..._options };
}
get id(): string {
@ -65,33 +65,37 @@ export class ResultsCommitsNode extends ViewNode implements Pagea
}
async getTreeItem(): Promise<TreeItem> {
let state;
let label;
let log;
if (this._options.querying) {
// Need to use Collapsed before we have results or the item won't show up in the view until the children are awaited
state = TreeItemCollapsibleState.Collapsed;
label = this._label;
this.getCommitsQueryResults().then(({ log }) => {
this._options.querying = false;
if (log != null) {
this.maxCount = log.maxCount;
}
let state;
this.triggerChange(false);
});
}
else {
({ label, log } = await this.getCommitsQueryResults());
try {
({ label, log } = await Promises.timeout(this.getCommitsQueryResults(), 100));
if (log != null) {
this.maxCount = log.maxCount;
}
state = this._options.expand ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.Collapsed;
if (log == null || log.count === 0) {
state = TreeItemCollapsibleState.None;
state =
log == null || log.count === 0
? TreeItemCollapsibleState.None
: this._options.expand
? TreeItemCollapsibleState.Expanded
: TreeItemCollapsibleState.Collapsed;
}
catch (ex) {
if (ex instanceof Promises.TimeoutError) {
ex.promise.then(({ log }: CommitsQueryResults) => {
if (log != null) {
this.maxCount = log.maxCount;
}
this.triggerChange(false);
});
}
// Need to use Collapsed before we have results or the item won't show up in the view until the children are awaited
// https://github.com/microsoft/vscode/issues/54806 & https://github.com/microsoft/vscode/issues/62214
state = TreeItemCollapsibleState.Collapsed;
}
let description;
@ -100,7 +104,7 @@ export class ResultsCommitsNode extends ViewNode implements Pagea
description = (repo && repo.formattedName) || this.repoPath;
}
const item = new TreeItem(label, state);
const item = new TreeItem(label || this._label, state);
item.contextValue = this.type;
item.description = description;
item.id = this.id;

+ 14
- 18
src/views/nodes/resultsFilesNode.ts Bestand weergeven

@ -4,7 +4,7 @@ import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { ViewFilesLayout } from '../../configuration';
import { Container } from '../../container';
import { GitFile, GitUri } from '../../git/gitService';
import { Arrays, debug, gate, Iterables, Strings } from '../../system';
import { Arrays, debug, gate, Iterables, Promises, Strings } from '../../system';
import { ViewWithFiles } from '../viewBase';
import { FileNode, FolderNode } from './folderNode';
import { ResultsFileNode } from './resultsFileNode';
@ -61,29 +61,26 @@ export class ResultsFilesNode extends ViewNode {
}
async getTreeItem(): Promise<TreeItem> {
let state;
let label;
let diff;
if (this._querying) {
// Need to use Collapsed before we have results or the item won't show up in the view until the children are awaited
state = TreeItemCollapsibleState.Collapsed;
label = 'files changed';
let state;
this.getFilesQueryResults().then(_ => {
this._querying = false;
this.triggerChange(false);
});
try {
({ label, diff } = await Promises.timeout(this.getFilesQueryResults(), 100));
state =
diff == null || diff.length === 0 ? TreeItemCollapsibleState.None : TreeItemCollapsibleState.Expanded;
}
else {
({ label, diff } = await this.getFilesQueryResults());
state = TreeItemCollapsibleState.Expanded;
if (diff == null || diff.length === 0) {
state = TreeItemCollapsibleState.None;
catch (ex) {
if (ex instanceof Promises.TimeoutError) {
ex.promise.then(() => this.triggerChange(false));
}
// Need to use Collapsed before we have results or the item won't show up in the view until the children are awaited
// https://github.com/microsoft/vscode/issues/54806 & https://github.com/microsoft/vscode/issues/62214
state = TreeItemCollapsibleState.Collapsed;
}
const item = new TreeItem(label, state);
const item = new TreeItem(label || 'files changed', state);
item.contextValue = ResourceType.ResultsFiles;
item.id = this.id;
@ -99,7 +96,6 @@ export class ResultsFilesNode extends ViewNode {
}
private _filesQueryResults: Promise<FilesQueryResults> | undefined;
private _querying = true;
private getFilesQueryResults() {
if (this._filesQueryResults === undefined) {

+ 2
- 4
src/views/nodes/searchResultsCommitsNode.ts Bestand weergeven

@ -19,13 +19,11 @@ export class SearchResultsCommitsNode extends ResultsCommitsNode {
public readonly search: string,
public readonly searchBy: GitRepoSearchBy,
label: string,
commitsQuery: (maxCount: number | undefined) => Promise<CommitsQueryResults>,
_querying = true
commitsQuery: (maxCount: number | undefined) => Promise<CommitsQueryResults>
) {
super(view, parent, repoPath, label, commitsQuery, {
expand: true,
includeDescription: true,
querying: _querying
includeDescription: true
});
this._instanceId = instanceId++;

+ 2
- 3
src/views/searchView.ts Bestand weergeven

@ -125,8 +125,7 @@ export class SearchView extends ViewBase {
search,
searchBy,
`results for ${typeof options.label === 'string' ? options.label : options.label.label}`,
searchQueryFn,
true
searchQueryFn
)
);
}
@ -152,7 +151,7 @@ export class SearchView extends ViewBase {
});
return this.addResults(
new SearchResultsCommitsNode(this, this._root!, repoPath, search, searchBy, label, searchQueryFn, false)
new SearchResultsCommitsNode(this, this._root!, repoPath, search, searchBy, label, searchQueryFn)
);
}

Laden…
Annuleren
Opslaan