瀏覽代碼

Renames promise members and removes "namespace"

main
Eric Amodio 2 年之前
父節點
當前提交
b85b135fdc
共有 19 個檔案被更改,包括 115 行新增105 行删除
  1. +7
    -10
      src/annotations/autolinks.ts
  2. +6
    -5
      src/annotations/lineAnnotationController.ts
  3. +4
    -3
      src/commands/gitCommands.ts
  4. +6
    -5
      src/git/formatters/commitFormatter.ts
  5. +25
    -22
      src/git/gitProviderService.ts
  6. +6
    -3
      src/git/remotes/provider.ts
  7. +6
    -5
      src/hovers/hovers.ts
  8. +7
    -8
      src/quickpicks/commitPicker.ts
  9. +7
    -6
      src/statusbar/statusBarController.ts
  10. +0
    -1
      src/system.ts
  11. +1
    -1
      src/system/decorators/gate.ts
  12. +1
    -1
      src/system/decorators/log.ts
  13. +1
    -1
      src/system/decorators/timeout.ts
  14. +13
    -13
      src/system/promise.ts
  15. +3
    -2
      src/views/nodes/autolinkedItemsNode.ts
  16. +4
    -3
      src/views/nodes/resultsCommitsNode.ts
  17. +4
    -3
      src/views/nodes/resultsFilesNode.ts
  18. +6
    -3
      src/views/searchAndCompareView.ts
  19. +8
    -10
      src/views/viewBase.ts

+ 7
- 10
src/annotations/autolinks.ts 查看文件

@ -5,7 +5,8 @@ import { GlyphChars } from '../constants';
import { Container } from '../container'; import { Container } from '../container';
import { GitRemote, IssueOrPullRequest } from '../git/models'; import { GitRemote, IssueOrPullRequest } from '../git/models';
import { Logger } from '../logger'; import { Logger } from '../logger';
import { Dates, debug, Encoding, Iterables, Promises, Strings } from '../system';
import { Dates, debug, Encoding, Iterables, Strings } from '../system';
import { PromiseCancelledError, raceAll } from '../system/promise';
const numRegex = /<num>/g; const numRegex = /<num>/g;
@ -89,11 +90,7 @@ export class Autolinks implements Disposable {
if (ids.size === 0) return undefined; if (ids.size === 0) return undefined;
const issuesOrPullRequests = await Promises.raceAll(
ids.values(),
id => provider.getIssueOrPullRequest(id),
timeout,
);
const issuesOrPullRequests = await raceAll(ids.values(), id => provider.getIssueOrPullRequest(id), timeout);
if (issuesOrPullRequests.size === 0 || Iterables.every(issuesOrPullRequests.values(), pr => pr === undefined)) { if (issuesOrPullRequests.size === 0 || Iterables.every(issuesOrPullRequests.values(), pr => pr === undefined)) {
return undefined; return undefined;
} }
@ -113,7 +110,7 @@ export class Autolinks implements Disposable {
text: string, text: string,
markdown: boolean, markdown: boolean,
remotes?: GitRemote[], remotes?: GitRemote[],
issuesOrPullRequests?: Map<string, IssueOrPullRequest | Promises.CancellationError | undefined>,
issuesOrPullRequests?: Map<string, IssueOrPullRequest | PromiseCancelledError | undefined>,
footnotes?: Map<number, string>, footnotes?: Map<number, string>,
) { ) {
for (const ref of this._references) { for (const ref of this._references) {
@ -143,7 +140,7 @@ export class Autolinks implements Disposable {
private ensureAutolinkCached( private ensureAutolinkCached(
ref: CacheableAutolinkReference | DynamicAutolinkReference, ref: CacheableAutolinkReference | DynamicAutolinkReference,
issuesOrPullRequests?: Map<string, IssueOrPullRequest | Promises.CancellationError | undefined>,
issuesOrPullRequests?: Map<string, IssueOrPullRequest | PromiseCancelledError | undefined>,
): ref is CacheableAutolinkReference | DynamicAutolinkReference { ): ref is CacheableAutolinkReference | DynamicAutolinkReference {
if (isDynamic(ref)) return true; if (isDynamic(ref)) return true;
@ -182,7 +179,7 @@ export class Autolinks implements Disposable {
title = ` "${ref.title.replace(numRegex, num)}`; title = ` "${ref.title.replace(numRegex, num)}`;
if (issue != null) { if (issue != null) {
if (issue instanceof Promises.CancellationError) {
if (issue instanceof PromiseCancelledError) {
title += `\n${GlyphChars.Dash.repeat(2)}\nDetails timed out`; title += `\n${GlyphChars.Dash.repeat(2)}\nDetails timed out`;
} else { } else {
const issueTitle = issue.title.replace(/([")\\])/g, '\\$1').trim(); const issueTitle = issue.title.replace(/([")\\])/g, '\\$1').trim();
@ -225,7 +222,7 @@ export class Autolinks implements Disposable {
footnotes.set( footnotes.set(
index, index,
`${linkText}: ${ `${linkText}: ${
issue instanceof Promises.CancellationError
issue instanceof PromiseCancelledError
? 'Details timed out' ? 'Details timed out'
: `${issue.title} ${GlyphChars.Dot} ${ : `${issue.title} ${GlyphChars.Dot} ${
issue.closed ? 'Closed' : 'Opened' issue.closed ? 'Closed' : 'Opened'

+ 6
- 5
src/annotations/lineAnnotationController.ts 查看文件

@ -18,7 +18,8 @@ import { CommitFormatter } from '../git/formatters';
import { GitBlameCommit, PullRequest } from '../git/models'; import { GitBlameCommit, PullRequest } from '../git/models';
import { Authentication } from '../git/remotes/provider'; import { Authentication } from '../git/remotes/provider';
import { LogCorrelationContext, Logger } from '../logger'; import { LogCorrelationContext, Logger } from '../logger';
import { debug, Iterables, log, Promises } from '../system';
import { debug, Iterables, log } from '../system';
import { PromiseCancelledError, PromiseCancelledErrorWithId, raceAll } from '../system/promise';
import { LinesChangeEvent, LineSelection } from '../trackers/gitLineTracker'; import { LinesChangeEvent, LineSelection } from '../trackers/gitLineTracker';
import { Annotations } from './annotations'; import { Annotations } from './annotations';
@ -170,7 +171,7 @@ export class LineAnnotationController implements Disposable {
if (refs.size === 0) return undefined; if (refs.size === 0) return undefined;
const { provider } = remote; const { provider } = remote;
const prs = await Promises.raceAll(
const prs = await raceAll(
refs.values(), refs.values(),
ref => this.container.git.getPullRequestForCommit(ref, provider), ref => this.container.git.getPullRequestForCommit(ref, provider),
timeout, timeout,
@ -335,21 +336,21 @@ export class LineAnnotationController implements Disposable {
editor: TextEditor, editor: TextEditor,
prs: Map< prs: Map<
string, string,
PullRequest | Promises.CancellationErrorWithId<string, Promise<PullRequest | undefined>> | undefined
PullRequest | PromiseCancelledErrorWithId<string, Promise<PullRequest | undefined>> | undefined
>, >,
cancellationToken: CancellationToken, cancellationToken: CancellationToken,
timeout: number, timeout: number,
cc: LogCorrelationContext | undefined, cc: LogCorrelationContext | undefined,
) { ) {
// If there are any PRs that timed out, refresh the annotation(s) once they complete // If there are any PRs that timed out, refresh the annotation(s) once they complete
const count = Iterables.count(prs.values(), pr => pr instanceof Promises.CancellationError);
const count = Iterables.count(prs.values(), pr => pr instanceof PromiseCancelledError);
if (cancellationToken.isCancellationRequested || count === 0) return; if (cancellationToken.isCancellationRequested || count === 0) return;
Logger.debug(cc, `${GlyphChars.Dot} ${count} pull request queries took too long (over ${timeout} ms)`); Logger.debug(cc, `${GlyphChars.Dot} ${count} pull request queries took too long (over ${timeout} ms)`);
const resolved = new Map<string, PullRequest | undefined>(); const resolved = new Map<string, PullRequest | undefined>();
for (const [key, value] of prs) { for (const [key, value] of prs) {
resolved.set(key, value instanceof Promises.CancellationError ? await value.promise : value);
resolved.set(key, value instanceof PromiseCancelledError ? await value.promise : value);
} }
if (cancellationToken.isCancellationRequested || editor !== this._editor) return; if (cancellationToken.isCancellationRequested || editor !== this._editor) return;

+ 4
- 3
src/commands/gitCommands.ts 查看文件

@ -5,7 +5,8 @@ import { Usage, WorkspaceState } from '../constants';
import type { Container } from '../container'; import type { Container } from '../container';
import { KeyMapping } from '../keyboard'; import { KeyMapping } from '../keyboard';
import { Directive, DirectiveQuickPickItem } from '../quickpicks'; import { Directive, DirectiveQuickPickItem } from '../quickpicks';
import { log, Promises } from '../system';
import { log } from '../system/decorators/log';
import { isPromise } from '../system/promise';
import { command, Command, CommandContext, Commands } from './common'; import { command, Command, CommandContext, Commands } from './common';
import { BranchGitCommand, BranchGitCommandArgs } from './git/branch'; import { BranchGitCommand, BranchGitCommandArgs } from './git/branch';
import { CherryPickGitCommand, CherryPickGitCommandArgs } from './git/cherry-pick'; import { CherryPickGitCommand, CherryPickGitCommandArgs } from './git/cherry-pick';
@ -334,7 +335,7 @@ export class GitCommandsCommand extends Command {
return; return;
} }
if (Promises.is(result)) {
if (isPromise(result)) {
input.buttons = this.getButtons(step, commandsStep.command); input.buttons = this.getButtons(step, commandsStep.command);
} }
@ -506,7 +507,7 @@ export class GitCommandsCommand extends Command {
return; return;
} }
if (Promises.is(result)) {
if (isPromise(result)) {
quickpick.buttons = this.getButtons( quickpick.buttons = this.getButtons(
activeCommand != null ? activeCommand.value : step, activeCommand != null ? activeCommand.value : step,
activeCommand ?? commandsStep.command, activeCommand ?? commandsStep.command,

+ 6
- 5
src/git/formatters/commitFormatter.ts 查看文件

@ -16,7 +16,8 @@ import { DateStyle, FileAnnotationType } from '../../configuration';
import { GlyphChars } from '../../constants'; import { GlyphChars } from '../../constants';
import { Container } from '../../container'; import { Container } from '../../container';
import { emojify } from '../../emojis'; import { emojify } from '../../emojis';
import { Iterables, Promises, Strings } from '../../system';
import { Iterables, Strings } from '../../system';
import { PromiseCancelledError } from '../../system/promise';
import { ContactPresence } from '../../vsls/vsls'; import { ContactPresence } from '../../vsls/vsls';
import { GitUri } from '../gitUri'; import { GitUri } from '../gitUri';
import { GitCommit, GitLogCommit, GitRemote, GitRevision, IssueOrPullRequest, PullRequest } from '../models'; import { GitCommit, GitLogCommit, GitRemote, GitRevision, IssueOrPullRequest, PullRequest } from '../models';
@ -26,7 +27,7 @@ import { FormatOptions, Formatter } from './formatter';
const emptyStr = ''; const emptyStr = '';
export interface CommitFormatOptions extends FormatOptions { export interface CommitFormatOptions extends FormatOptions {
autolinkedIssuesOrPullRequests?: Map<string, IssueOrPullRequest | Promises.CancellationError | undefined>;
autolinkedIssuesOrPullRequests?: Map<string, IssueOrPullRequest | PromiseCancelledError | undefined>;
avatarSize?: number; avatarSize?: number;
dateStyle?: DateStyle; dateStyle?: DateStyle;
editor?: { line: number; uri: Uri }; editor?: { line: number; uri: Uri };
@ -36,7 +37,7 @@ export interface CommitFormatOptions extends FormatOptions {
messageAutolinks?: boolean; messageAutolinks?: boolean;
messageIndent?: number; messageIndent?: number;
messageTruncateAtNewLine?: boolean; messageTruncateAtNewLine?: boolean;
pullRequestOrRemote?: PullRequest | Promises.CancellationError | GitRemote;
pullRequestOrRemote?: PullRequest | PromiseCancelledError | GitRemote;
pullRequestPendingMessage?: string; pullRequestPendingMessage?: string;
presence?: ContactPresence; presence?: ContactPresence;
previousLineDiffUris?: { current: GitUri; previous: GitUri | undefined }; previousLineDiffUris?: { current: GitUri; previous: GitUri | undefined };
@ -358,7 +359,7 @@ export class CommitFormatter extends Formatter {
}\n${GlyphChars.Dash.repeat(2)}\n${Strings.escapeMarkdown(pr.title).replace(/"/g, '\\"')}\n${ }\n${GlyphChars.Dash.repeat(2)}\n${Strings.escapeMarkdown(pr.title).replace(/"/g, '\\"')}\n${
pr.state pr.state
}, ${pr.formatDateFromNow()}")`; }, ${pr.formatDateFromNow()}")`;
} else if (pr instanceof Promises.CancellationError) {
} else if (pr instanceof PromiseCancelledError) {
commands += `${separator}[$(git-pull-request) PR $(loading~spin)](command:${Commands.RefreshHover} "Searching for a Pull Request (if any) that introduced this commit...")`; commands += `${separator}[$(git-pull-request) PR $(loading~spin)](command:${Commands.RefreshHover} "Searching for a Pull Request (if any) that introduced this commit...")`;
} else if (pr.provider != null && Container.instance.config.integrations.enabled) { } else if (pr.provider != null && Container.instance.config.integrations.enabled) {
commands += `${separator}[$(plug) Connect to ${pr.provider.name}${ commands += `${separator}[$(plug) Connect to ${pr.provider.name}${
@ -540,7 +541,7 @@ export class CommitFormatter extends Formatter {
} else { } else {
text = `PR #${pr.id}`; text = `PR #${pr.id}`;
} }
} else if (pr instanceof Promises.CancellationError) {
} else if (pr instanceof PromiseCancelledError) {
text = this._options.markdown text = this._options.markdown
? `[PR $(loading~spin)](command:${Commands.RefreshHover} "Searching for a Pull Request (if any) that introduced this commit...")` ? `[PR $(loading~spin)](command:${Commands.RefreshHover} "Searching for a Pull Request (if any) that introduced this commit...")`
: this._options?.pullRequestPendingMessage ?? emptyStr; : this._options?.pullRequestPendingMessage ?? emptyStr;

+ 25
- 22
src/git/gitProviderService.ts 查看文件

@ -29,9 +29,12 @@ import {
import type { Container } from '../container'; import type { Container } from '../container';
import { ProviderNotFoundError } from '../errors'; import { ProviderNotFoundError } from '../errors';
import { Logger } from '../logger'; import { Logger } from '../logger';
import { Arrays, debug, gate, Iterables, log, Promises } from '../system';
import { groupByFilterMap, groupByMap } from '../system/array';
import { gate } from '../system/decorators/gate';
import { debug, log } from '../system/decorators/log';
import { count, filter, flatMap, map } from '../system/iterable';
import { isDescendent, normalizePath } from '../system/path'; import { isDescendent, normalizePath } from '../system/path';
import { PromiseOrValue } from '../system/promise';
import { cancellable, isPromise, PromiseCancelledError, PromiseOrValue } from '../system/promise';
import { CharCode } from '../system/string'; import { CharCode } from '../system/string';
import { vslsUriPrefixRegex } from '../vsls/vsls'; import { vslsUriPrefixRegex } from '../vsls/vsls';
import { GitProvider, GitProviderDescriptor, GitProviderId, PagedResult, ScmRepository } from './gitProvider'; import { GitProvider, GitProviderDescriptor, GitProviderId, PagedResult, ScmRepository } from './gitProvider';
@ -117,7 +120,7 @@ export class GitProviderService implements Disposable {
} else if (added?.length) { } else if (added?.length) {
// If a provider was added, only preserve paths with a resolved repoPath // If a provider was added, only preserve paths with a resolved repoPath
for (const [key, value] of this._pathToRepoPathCache) { for (const [key, value] of this._pathToRepoPathCache) {
if (value === null || Promises.is(value)) {
if (value === null || isPromise(value)) {
this._pathToRepoPathCache.delete(key); this._pathToRepoPathCache.delete(key);
} }
} }
@ -141,7 +144,7 @@ export class GitProviderService implements Disposable {
} else if (added?.length) { } else if (added?.length) {
// If a repository was added, only preserve paths with a resolved repoPath // If a repository was added, only preserve paths with a resolved repoPath
for (const [key, value] of this._pathToRepoPathCache) { for (const [key, value] of this._pathToRepoPathCache) {
if (value === null || Promises.is(value)) {
if (value === null || isPromise(value)) {
this._pathToRepoPathCache.delete(key); this._pathToRepoPathCache.delete(key);
} }
} }
@ -263,18 +266,18 @@ export class GitProviderService implements Disposable {
} }
get registeredProviders(): GitProviderDescriptor[] { get registeredProviders(): GitProviderDescriptor[] {
return [...Iterables.map(this._providers.values(), p => ({ ...p.descriptor }))];
return [...map(this._providers.values(), p => ({ ...p.descriptor }))];
} }
get openRepositories(): Repository[] { get openRepositories(): Repository[] {
const repositories = [...Iterables.filter(this.repositories, r => !r.closed)];
const repositories = [...filter(this.repositories, r => !r.closed)];
if (repositories.length === 0) return repositories; if (repositories.length === 0) return repositories;
return Repository.sort(repositories); return Repository.sort(repositories);
} }
get openRepositoryCount(): number { get openRepositoryCount(): number {
return Iterables.count(this.repositories, r => !r.closed);
return count(this.repositories, r => !r.closed);
} }
get repositories(): Iterable<Repository> { get repositories(): Iterable<Repository> {
@ -423,14 +426,14 @@ export class GitProviderService implements Disposable {
} }
getOpenRepositories(id: GitProviderId): Iterable<Repository> { getOpenRepositories(id: GitProviderId): Iterable<Repository> {
return Iterables.filter(this.repositories, r => !r.closed && (id == null || id === r.provider.id));
return filter(this.repositories, r => !r.closed && (id == null || id === r.provider.id));
} }
getOpenRepositoriesByProvider(): Map<GitProviderId, Repository[]> { getOpenRepositoriesByProvider(): Map<GitProviderId, Repository[]> {
const repositories = [...Iterables.filter(this.repositories, r => !r.closed)];
const repositories = [...filter(this.repositories, r => !r.closed)];
if (repositories.length === 0) return new Map(); if (repositories.length === 0) return new Map();
return Arrays.groupByMap(repositories, r => r.provider.id);
return groupByMap(repositories, r => r.provider.id);
} }
private _discoveredWorkspaceFolders = new Map<WorkspaceFolder, Promise<Repository[]>>(); private _discoveredWorkspaceFolders = new Map<WorkspaceFolder, Promise<Repository[]>>();
@ -451,8 +454,8 @@ export class GitProviderService implements Disposable {
const results = await Promise.allSettled(promises); const results = await Promise.allSettled(promises);
const repositories = Iterables.flatMap<PromiseFulfilledResult<Repository[]>, Repository>(
Iterables.filter<PromiseSettledResult<Repository[]>, PromiseFulfilledResult<Repository[]>>(
const repositories = flatMap<PromiseFulfilledResult<Repository[]>, Repository>(
filter<PromiseSettledResult<Repository[]>, PromiseFulfilledResult<Repository[]>>(
results, results,
(r): r is PromiseFulfilledResult<Repository[]> => r.status === 'fulfilled', (r): r is PromiseFulfilledResult<Repository[]> => r.status === 'fulfilled',
), ),
@ -927,7 +930,7 @@ export class GitProviderService implements Disposable {
this.getTags(repoPath), this.getTags(repoPath),
]); ]);
const branchesAndTagsBySha = Arrays.groupByFilterMap(
const branchesAndTagsBySha = groupByFilterMap(
(branches as (GitBranch | GitTag)[]).concat(tags as (GitBranch | GitTag)[]), (branches as (GitBranch | GitTag)[]).concat(tags as (GitBranch | GitTag)[]),
bt => bt.sha, bt => bt.sha,
bt => { bt => {
@ -1314,18 +1317,18 @@ export class GitProviderService implements Disposable {
} }
let promiseOrPR = provider.getPullRequestForBranch(branch, options); let promiseOrPR = provider.getPullRequestForBranch(branch, options);
if (promiseOrPR == null || !Promises.is(promiseOrPR)) {
if (promiseOrPR == null || !isPromise(promiseOrPR)) {
return promiseOrPR; return promiseOrPR;
} }
if (timeout != null && timeout > 0) { if (timeout != null && timeout > 0) {
promiseOrPR = Promises.cancellable(promiseOrPR, timeout);
promiseOrPR = cancellable(promiseOrPR, timeout);
} }
try { try {
return await promiseOrPR; return await promiseOrPR;
} catch (ex) { } catch (ex) {
if (ex instanceof Promises.CancellationError) {
if (ex instanceof PromiseCancelledError) {
throw ex; throw ex;
} }
@ -1366,18 +1369,18 @@ export class GitProviderService implements Disposable {
} }
let promiseOrPR = provider.getPullRequestForCommit(ref); let promiseOrPR = provider.getPullRequestForCommit(ref);
if (promiseOrPR == null || !Promises.is(promiseOrPR)) {
if (promiseOrPR == null || !isPromise(promiseOrPR)) {
return promiseOrPR; return promiseOrPR;
} }
if (options?.timeout != null && options.timeout > 0) { if (options?.timeout != null && options.timeout > 0) {
promiseOrPR = Promises.cancellable(promiseOrPR, options.timeout);
promiseOrPR = cancellable(promiseOrPR, options.timeout);
} }
try { try {
return await promiseOrPR; return await promiseOrPR;
} catch (ex) { } catch (ex) {
if (ex instanceof Promises.CancellationError) {
if (ex instanceof PromiseCancelledError) {
throw ex; throw ex;
} }
@ -1522,7 +1525,7 @@ export class GitProviderService implements Disposable {
let repoPathOrPromise = this._pathToRepoPathCache.get(filePath); let repoPathOrPromise = this._pathToRepoPathCache.get(filePath);
if (repoPathOrPromise !== undefined) { if (repoPathOrPromise !== undefined) {
rp = Promises.is(repoPathOrPromise) ? await repoPathOrPromise : repoPathOrPromise;
rp = isPromise(repoPathOrPromise) ? await repoPathOrPromise : repoPathOrPromise;
// If the repoPath is explicitly null, then we know no repo exists // If the repoPath is explicitly null, then we know no repo exists
if (rp === null) return undefined; if (rp === null) return undefined;
@ -1878,8 +1881,8 @@ export class GitProviderService implements Disposable {
@log() @log()
async getOpenScmRepositories(): Promise<ScmRepository[]> { async getOpenScmRepositories(): Promise<ScmRepository[]> {
const results = await Promise.allSettled([...this._providers.values()].map(p => p.getOpenScmRepositories())); const results = await Promise.allSettled([...this._providers.values()].map(p => p.getOpenScmRepositories()));
const repositories = Iterables.flatMap<PromiseFulfilledResult<ScmRepository[]>, ScmRepository>(
Iterables.filter<PromiseSettledResult<ScmRepository[]>, PromiseFulfilledResult<ScmRepository[]>>(
const repositories = flatMap<PromiseFulfilledResult<ScmRepository[]>, ScmRepository>(
filter<PromiseSettledResult<ScmRepository[]>, PromiseFulfilledResult<ScmRepository[]>>(
results, results,
(r): r is PromiseFulfilledResult<ScmRepository[]> => r.status === 'fulfilled', (r): r is PromiseFulfilledResult<ScmRepository[]> => r.status === 'fulfilled',
), ),

+ 6
- 3
src/git/remotes/provider.ts 查看文件

@ -15,7 +15,10 @@ import { WorkspaceState } from '../../constants';
import { Container } from '../../container'; import { Container } from '../../container';
import { AuthenticationError, ProviderRequestClientError } from '../../errors'; import { AuthenticationError, ProviderRequestClientError } from '../../errors';
import { Logger } from '../../logger'; import { Logger } from '../../logger';
import { debug, Encoding, gate, log, Promises } from '../../system';
import { gate } from '../../system/decorators/gate';
import { debug, log } from '../../system/decorators/log';
import { encodeUrl } from '../../system/encoding';
import { isPromise } from '../../system/promise';
import { import {
Account, Account,
DefaultBranch, DefaultBranch,
@ -235,7 +238,7 @@ export abstract class RemoteProvider implements RemoteProviderReference {
protected encodeUrl(url: string): string; protected encodeUrl(url: string): string;
protected encodeUrl(url: string | undefined): string | undefined; protected encodeUrl(url: string | undefined): string | undefined;
protected encodeUrl(url: string | undefined): string | undefined { protected encodeUrl(url: string | undefined): string | undefined {
return Encoding.encodeUrl(url)?.replace(/#/g, '%23');
return encodeUrl(url)?.replace(/#/g, '%23');
} }
} }
@ -530,7 +533,7 @@ export abstract class RichRemoteProvider extends RemoteProvider {
pr = this.getPullRequestForCommitCore(ref); pr = this.getPullRequestForCommitCore(ref);
this._prsByCommit.set(ref, pr); this._prsByCommit.set(ref, pr);
} }
if (pr == null || !Promises.is(pr)) return pr ?? undefined;
if (pr == null || !isPromise(pr)) return pr ?? undefined;
return pr.then(pr => pr ?? undefined); return pr.then(pr => pr ?? undefined);
} }

+ 6
- 5
src/hovers/hovers.ts 查看文件

@ -17,7 +17,8 @@ import {
PullRequest, PullRequest,
} from '../git/models'; } from '../git/models';
import { Logger, LogLevel } from '../logger'; import { Logger, LogLevel } from '../logger';
import { Iterables, Promises, Strings } from '../system';
import { Iterables, Strings } from '../system';
import { PromiseCancelledError } from '../system/promise';
export namespace Hovers { export namespace Hovers {
export async function changesMessage( export async function changesMessage(
@ -190,7 +191,7 @@ export namespace Hovers {
cancellationToken?: CancellationToken; cancellationToken?: CancellationToken;
pullRequests?: { pullRequests?: {
enabled: boolean; enabled: boolean;
pr?: PullRequest | Promises.CancellationError<Promise<PullRequest | undefined>>;
pr?: PullRequest | PromiseCancelledError<Promise<PullRequest | undefined>>;
}; };
getBranchAndTagTips?: ( getBranchAndTagTips?: (
sha: string, sha: string,
@ -296,7 +297,7 @@ export namespace Hovers {
if (autolinks != null && Logger.enabled(LogLevel.Debug)) { if (autolinks != null && Logger.enabled(LogLevel.Debug)) {
// If there are any issues/PRs that timed out, log it // If there are any issues/PRs that timed out, log it
const count = Iterables.count(autolinks.values(), pr => pr instanceof Promises.CancellationError);
const count = Iterables.count(autolinks.values(), pr => pr instanceof PromiseCancelledError);
if (count !== 0) { if (count !== 0) {
Logger.debug( Logger.debug(
cc, cc,
@ -309,7 +310,7 @@ export namespace Hovers {
// const pending = [ // const pending = [
// ...Iterables.map(autolinks.values(), issueOrPullRequest => // ...Iterables.map(autolinks.values(), issueOrPullRequest =>
// issueOrPullRequest instanceof Promises.CancellationError
// issueOrPullRequest instanceof CancelledPromiseError
// ? issueOrPullRequest.promise // ? issueOrPullRequest.promise
// : undefined, // : undefined,
// ), // ),
@ -376,7 +377,7 @@ export namespace Hovers {
return pr; return pr;
} catch (ex) { } catch (ex) {
if (ex instanceof Promises.CancellationError) {
if (ex instanceof PromiseCancelledError) {
Logger.debug(cc, `timed out ${GlyphChars.Dot} ${Strings.getDurationMilliseconds(start)} ms`); Logger.debug(cc, `timed out ${GlyphChars.Dot} ${Strings.getDurationMilliseconds(start)} ms`);
return ex; return ex;

+ 7
- 8
src/quickpicks/commitPicker.ts 查看文件

@ -11,7 +11,8 @@ import {
DirectiveQuickPickItem, DirectiveQuickPickItem,
getQuickPickIgnoreFocusOut, getQuickPickIgnoreFocusOut,
} from '../quickpicks'; } from '../quickpicks';
import { Iterables, Promises } from '../system';
import { filter, map } from '../system/iterable';
import { isPromise } from '../system/promise';
export namespace CommitPicker { export namespace CommitPicker {
export async function show( export async function show(
@ -33,7 +34,7 @@ export namespace CommitPicker {
quickpick.matchOnDescription = true; quickpick.matchOnDescription = true;
quickpick.matchOnDetail = true; quickpick.matchOnDetail = true;
if (Promises.is(log)) {
if (isPromise(log)) {
quickpick.busy = true; quickpick.busy = true;
quickpick.enabled = false; quickpick.enabled = false;
quickpick.show(); quickpick.show();
@ -56,7 +57,7 @@ export namespace CommitPicker {
? [DirectiveQuickPickItem.create(Directive.Cancel)] ? [DirectiveQuickPickItem.create(Directive.Cancel)]
: [ : [
...(options?.showOtherReferences ?? []), ...(options?.showOtherReferences ?? []),
...Iterables.map(log.commits.values(), commit =>
...map(log.commits.values(), commit =>
CommitQuickPickItem.create(commit, options?.picked === commit.ref, { CommitQuickPickItem.create(commit, options?.picked === commit.ref, {
compact: true, compact: true,
icon: true, icon: true,
@ -206,7 +207,7 @@ export namespace StashPicker {
quickpick.matchOnDescription = true; quickpick.matchOnDescription = true;
quickpick.matchOnDetail = true; quickpick.matchOnDetail = true;
if (Promises.is(stash)) {
if (isPromise(stash)) {
quickpick.busy = true; quickpick.busy = true;
quickpick.enabled = false; quickpick.enabled = false;
quickpick.show(); quickpick.show();
@ -217,10 +218,8 @@ export namespace StashPicker {
if (stash != null) { if (stash != null) {
quickpick.items = [ quickpick.items = [
...(options?.showOtherReferences ?? []), ...(options?.showOtherReferences ?? []),
...Iterables.map(
options?.filter != null
? Iterables.filter(stash.commits.values(), options.filter)
: stash.commits.values(),
...map(
options?.filter != null ? filter(stash.commits.values(), options.filter) : stash.commits.values(),
commit => commit =>
CommitQuickPickItem.create(commit, options?.picked === commit.ref, { CommitQuickPickItem.create(commit, options?.picked === commit.ref, {
compact: true, compact: true,

+ 7
- 6
src/statusbar/statusBarController.ts 查看文件

@ -19,7 +19,8 @@ import { CommitFormatter } from '../git/formatters';
import { GitBlameCommit, PullRequest } from '../git/models'; import { GitBlameCommit, PullRequest } from '../git/models';
import { Hovers } from '../hovers/hovers'; import { Hovers } from '../hovers/hovers';
import { LogCorrelationContext, Logger } from '../logger'; import { LogCorrelationContext, Logger } from '../logger';
import { debug, Promises } from '../system';
import { debug } from '../system/decorators/log';
import { PromiseCancelledError } from '../system/promise';
import { LinesChangeEvent } from '../trackers/gitLineTracker'; import { LinesChangeEvent } from '../trackers/gitLineTracker';
export class StatusBarController implements Disposable { export class StatusBarController implements Disposable {
@ -333,7 +334,7 @@ export class StatusBarController implements Disposable {
private async getPullRequest( private async getPullRequest(
commit: GitBlameCommit, commit: GitBlameCommit,
{ timeout }: { timeout?: number } = {}, { timeout }: { timeout?: number } = {},
): Promise<PullRequest | Promises.CancellationError<Promise<PullRequest | undefined>> | undefined> {
): Promise<PullRequest | PromiseCancelledError<Promise<PullRequest | undefined>> | undefined> {
const remote = await this.container.git.getRichRemoteProvider(commit.repoPath); const remote = await this.container.git.getRichRemoteProvider(commit.repoPath);
if (remote?.provider == null) return undefined; if (remote?.provider == null) return undefined;
@ -341,7 +342,7 @@ export class StatusBarController implements Disposable {
try { try {
return await this.container.git.getPullRequestForCommit(commit.ref, provider, { timeout: timeout }); return await this.container.git.getPullRequestForCommit(commit.ref, provider, { timeout: timeout });
} catch (ex) { } catch (ex) {
return ex instanceof Promises.CancellationError ? ex : undefined;
return ex instanceof PromiseCancelledError ? ex : undefined;
} }
} }
@ -357,7 +358,7 @@ export class StatusBarController implements Disposable {
| undefined, | undefined,
pullRequests: { pullRequests: {
enabled: boolean; enabled: boolean;
pr: PullRequest | Promises.CancellationError<Promise<PullRequest | undefined>> | undefined | undefined;
pr: PullRequest | PromiseCancelledError<Promise<PullRequest | undefined>> | undefined | undefined;
}, },
cancellationToken: CancellationToken, cancellationToken: CancellationToken,
) { ) {
@ -386,12 +387,12 @@ export class StatusBarController implements Disposable {
private async waitForPendingPullRequest( private async waitForPendingPullRequest(
editor: TextEditor, editor: TextEditor,
commit: GitBlameCommit, commit: GitBlameCommit,
pr: PullRequest | Promises.CancellationError<Promise<PullRequest | undefined>> | undefined,
pr: PullRequest | PromiseCancelledError<Promise<PullRequest | undefined>> | undefined,
cancellationToken: CancellationToken, cancellationToken: CancellationToken,
timeout: number, timeout: number,
cc: LogCorrelationContext | undefined, cc: LogCorrelationContext | undefined,
) { ) {
if (cancellationToken.isCancellationRequested || !(pr instanceof Promises.CancellationError)) return;
if (cancellationToken.isCancellationRequested || !(pr instanceof PromiseCancelledError)) return;
// If the PR timed out, refresh the status bar once it completes // If the PR timed out, refresh the status bar once it completes
Logger.debug(cc, `${GlyphChars.Dot} pull request query took too long (over ${timeout} ms)`); Logger.debug(cc, `${GlyphChars.Dot} pull request query took too long (over ${timeout} ms)`);

+ 0
- 1
src/system.ts 查看文件

@ -29,7 +29,6 @@ export * as Encoding from './system/encoding';
export * as Functions from './system/function'; export * as Functions from './system/function';
export * as Iterables from './system/iterable'; export * as Iterables from './system/iterable';
export * as Objects from './system/object'; export * as Objects from './system/object';
export * as Promises from './system/promise';
export * from './system/searchTree'; export * from './system/searchTree';
export * from './system/stopwatch'; export * from './system/stopwatch';
export * as Strings from './system/string'; export * as Strings from './system/string';

+ 1
- 1
src/system/decorators/gate.ts 查看文件

@ -1,5 +1,5 @@
'use strict'; 'use strict';
import { is as isPromise } from '../promise';
import { isPromise } from '../promise';
import { resolveProp } from './resolver'; import { resolveProp } from './resolver';
export function gate<T extends (...arg: any) => any>(resolver?: (...args: Parameters<T>) => string) { export function gate<T extends (...arg: any) => any>(resolver?: (...args: Parameters<T>) => string) {

+ 1
- 1
src/system/decorators/log.ts 查看文件

@ -3,7 +3,7 @@ import { hrtime } from '@env/hrtime';
import { LogCorrelationContext, Logger, LogLevel } from '../../logger'; import { LogCorrelationContext, Logger, LogLevel } from '../../logger';
import { filterMap } from '../array'; import { filterMap } from '../array';
import { getParameters } from '../function'; import { getParameters } from '../function';
import { is as isPromise } from '../promise';
import { isPromise } from '../promise';
import { getDurationMilliseconds } from '../string'; import { getDurationMilliseconds } from '../string';
const emptyStr = ''; const emptyStr = '';

+ 1
- 1
src/system/decorators/timeout.ts 查看文件

@ -1,5 +1,5 @@
'use strict'; 'use strict';
import { cancellable, is as isPromise } from '../promise';
import { cancellable, isPromise } from '../promise';
export function timeout(timeout: number): any; export function timeout(timeout: number): any;
export function timeout(timeoutFromLastArg: true, defaultTimeout?: number): any; export function timeout(timeoutFromLastArg: true, defaultTimeout?: number): any;

+ 13
- 13
src/system/promise.ts 查看文件

@ -33,13 +33,13 @@ export function any(...promises: Promise[]): Promise {
}); });
} }
export class CancellationError<T extends Promise<any> = Promise<any>> extends Error {
export class PromiseCancelledError<T extends Promise<any> = Promise<any>> extends Error {
constructor(public readonly promise: T, message: string) { constructor(public readonly promise: T, message: string) {
super(message); super(message);
} }
} }
export class CancellationErrorWithId<TKey, T extends Promise<any> = Promise<any>> extends CancellationError<T> {
export class PromiseCancelledErrorWithId<TKey, T extends Promise<any> = Promise<any>> extends PromiseCancelledError<T> {
constructor(public readonly id: TKey, promise: T, message: string) { constructor(public readonly id: TKey, promise: T, message: string) {
super(promise, message); super(promise, message);
} }
@ -65,7 +65,7 @@ export function cancellable(
if (typeof options.onDidCancel === 'function') { if (typeof options.onDidCancel === 'function') {
options.onDidCancel(resolve, reject); options.onDidCancel(resolve, reject);
} else { } else {
reject(new CancellationError(promise, options.cancelMessage ?? 'TIMED OUT'));
reject(new PromiseCancelledError(promise, options.cancelMessage ?? 'TIMED OUT'));
} }
}, timeoutOrToken); }, timeoutOrToken);
} else { } else {
@ -76,7 +76,7 @@ export function cancellable(
if (typeof options.onDidCancel === 'function') { if (typeof options.onDidCancel === 'function') {
options.onDidCancel(resolve, reject); options.onDidCancel(resolve, reject);
} else { } else {
reject(new CancellationError(promise, options.cancelMessage ?? 'CANCELLED'));
reject(new PromiseCancelledError(promise, options.cancelMessage ?? 'CANCELLED'));
} }
}); });
} }
@ -102,23 +102,23 @@ export function cancellable(
}); });
} }
export function is<T>(obj: PromiseLike<T> | T): obj is Promise<T> {
export function isPromise<T>(obj: PromiseLike<T> | T): obj is Promise<T> {
return obj instanceof Promise || typeof (obj as PromiseLike<T>)?.then === 'function'; return obj instanceof Promise || typeof (obj as PromiseLike<T>)?.then === 'function';
} }
export function raceAll<TPromise>( export function raceAll<TPromise>(
promises: Promise<TPromise>[], promises: Promise<TPromise>[],
timeout?: number, timeout?: number,
): Promise<(TPromise | CancellationError<Promise<TPromise>>)[]>;
): Promise<(TPromise | PromiseCancelledError<Promise<TPromise>>)[]>;
export function raceAll<TPromise, T>( export function raceAll<TPromise, T>(
promises: Map<T, Promise<TPromise>>, promises: Map<T, Promise<TPromise>>,
timeout?: number, timeout?: number,
): Promise<Map<T, TPromise | CancellationErrorWithId<T, Promise<TPromise>>>>;
): Promise<Map<T, TPromise | PromiseCancelledErrorWithId<T, Promise<TPromise>>>>;
export function raceAll<TPromise, T>( export function raceAll<TPromise, T>(
ids: Iterable<T>, ids: Iterable<T>,
fn: (id: T) => Promise<TPromise>, fn: (id: T) => Promise<TPromise>,
timeout?: number, timeout?: number,
): Promise<Map<T, TPromise | CancellationErrorWithId<T, Promise<TPromise>>>>;
): Promise<Map<T, TPromise | PromiseCancelledErrorWithId<T, Promise<TPromise>>>>;
export async function raceAll<TPromise, T>( export async function raceAll<TPromise, T>(
promisesOrIds: Promise<TPromise>[] | Map<T, Promise<TPromise>> | Iterable<T>, promisesOrIds: Promise<TPromise>[] | Map<T, Promise<TPromise>> | Iterable<T>,
timeoutOrFn?: number | ((id: T) => Promise<TPromise>), timeoutOrFn?: number | ((id: T) => Promise<TPromise>),
@ -135,7 +135,7 @@ export async function raceAll(
if (promises instanceof Map) { if (promises instanceof Map) {
return new Map( return new Map(
await Promise.all( await Promise.all(
map<[T, Promise<TPromise>], Promise<[T, TPromise | CancellationErrorWithId<T, Promise<TPromise>>]>>(
map<[T, Promise<TPromise>], Promise<[T, TPromise | PromiseCancelledErrorWithId<T, Promise<TPromise>>]>>(
promises.entries(), promises.entries(),
timeout == null timeout == null
? ([id, promise]) => promise.then(p => [id, p]) ? ([id, promise]) => promise.then(p => [id, p])
@ -143,9 +143,9 @@ export async function raceAll(
Promise.race([ Promise.race([
promise, promise,
new Promise<CancellationErrorWithId<T, Promise<TPromise>>>(resolve =>
new Promise<PromiseCancelledErrorWithId<T, Promise<TPromise>>>(resolve =>
setTimeout( setTimeout(
() => resolve(new CancellationErrorWithId(id, promise, 'TIMED OUT')),
() => resolve(new PromiseCancelledErrorWithId(id, promise, 'TIMED OUT')),
timeout, timeout,
), ),
), ),
@ -161,8 +161,8 @@ export async function raceAll(
: promises.map(p => : promises.map(p =>
Promise.race([ Promise.race([
p, p,
new Promise<CancellationError<Promise<TPromise>>>(resolve =>
setTimeout(() => resolve(new CancellationError(p, 'TIMED OUT')), timeout),
new Promise<PromiseCancelledError<Promise<TPromise>>>(resolve =>
setTimeout(() => resolve(new PromiseCancelledError(p, 'TIMED OUT')), timeout),
), ),
]), ]),
), ),

+ 3
- 2
src/views/nodes/autolinkedItemsNode.ts 查看文件

@ -3,7 +3,8 @@ import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { GitUri } from '../../git/gitUri'; import { GitUri } from '../../git/gitUri';
import { GitFile, GitLog, GitRemote, IssueOrPullRequest, PullRequest } from '../../git/models'; import { GitFile, GitLog, GitRemote, IssueOrPullRequest, PullRequest } from '../../git/models';
import { RichRemoteProvider } from '../../git/remotes/provider'; import { RichRemoteProvider } from '../../git/remotes/provider';
import { debug, gate, Promises } from '../../system';
import { debug, gate } from '../../system';
import { PromiseCancelledErrorWithId } from '../../system/promise';
import { ViewsWithCommits } from '../viewBase'; import { ViewsWithCommits } from '../viewBase';
import { AutolinkedItemNode } from './autolinkedItemNode'; import { AutolinkedItemNode } from './autolinkedItemNode';
import { MessageNode } from './common'; import { MessageNode } from './common';
@ -53,7 +54,7 @@ export class AutolinkedItemsNode extends ViewNode {
if (autolinkedMapResult.status === 'fulfilled' && autolinkedMapResult.value != null) { if (autolinkedMapResult.status === 'fulfilled' && autolinkedMapResult.value != null) {
for (const [id, issue] of autolinkedMapResult.value) { for (const [id, issue] of autolinkedMapResult.value) {
if (issue == null || issue instanceof Promises.CancellationErrorWithId) continue;
if (issue == null || issue instanceof PromiseCancelledErrorWithId) continue;
items.set(id, issue); items.set(id, issue);
} }

+ 4
- 3
src/views/nodes/resultsCommitsNode.ts 查看文件

@ -2,7 +2,8 @@
import { TreeItem, TreeItemCollapsibleState } from 'vscode'; import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { GitUri } from '../../git/gitUri'; import { GitUri } from '../../git/gitUri';
import { GitLog } from '../../git/models'; import { GitLog } from '../../git/models';
import { debug, gate, Iterables, Promises } from '../../system';
import { debug, gate, Iterables } from '../../system';
import { cancellable, PromiseCancelledError } from '../../system/promise';
import { ViewsWithCommits } from '../viewBase'; import { ViewsWithCommits } from '../viewBase';
import { AutolinkedItemsNode } from './autolinkedItemsNode'; import { AutolinkedItemsNode } from './autolinkedItemsNode';
import { CommitNode } from './commitNode'; import { CommitNode } from './commitNode';
@ -126,7 +127,7 @@ export class ResultsCommitsNode
} else { } else {
try { try {
let log; let log;
({ label, log } = await Promises.cancellable(this.getCommitsQueryResults(), 100));
({ label, log } = await cancellable(this.getCommitsQueryResults(), 100));
state = state =
log == null || log.count === 0 log == null || log.count === 0
? TreeItemCollapsibleState.None ? TreeItemCollapsibleState.None
@ -134,7 +135,7 @@ export class ResultsCommitsNode
? TreeItemCollapsibleState.Expanded ? TreeItemCollapsibleState.Expanded
: TreeItemCollapsibleState.Collapsed; : TreeItemCollapsibleState.Collapsed;
} catch (ex) { } catch (ex) {
if (ex instanceof Promises.CancellationError) {
if (ex instanceof PromiseCancelledError) {
ex.promise.then(() => this.triggerChange(false)); ex.promise.then(() => this.triggerChange(false));
} }

+ 4
- 3
src/views/nodes/resultsFilesNode.ts 查看文件

@ -3,8 +3,9 @@ import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { ViewFilesLayout } from '../../configuration'; import { ViewFilesLayout } from '../../configuration';
import { GitUri } from '../../git/gitUri'; import { GitUri } from '../../git/gitUri';
import { GitFile } from '../../git/models'; import { GitFile } from '../../git/models';
import { Arrays, debug, gate, Iterables, Promises, Strings } from '../../system';
import { Arrays, debug, gate, Iterables, Strings } from '../../system';
import { joinPaths, normalizePath } from '../../system/path'; import { joinPaths, normalizePath } from '../../system/path';
import { cancellable, PromiseCancelledError } from '../../system/promise';
import { ViewsWithCommits } from '../viewBase'; import { ViewsWithCommits } from '../viewBase';
import { FileNode, FolderNode } from './folderNode'; import { FileNode, FolderNode } from './folderNode';
import { ResultsFileNode } from './resultsFileNode'; import { ResultsFileNode } from './resultsFileNode';
@ -98,7 +99,7 @@ export class ResultsFilesNode extends ViewNode {
let state; let state;
try { try {
const results = await Promises.cancellable(this.getFilesQueryResults(), 100);
const results = await cancellable(this.getFilesQueryResults(), 100);
label = results.label; label = results.label;
files = (this.filtered ? results.filtered?.files : undefined) ?? results.files; files = (this.filtered ? results.filtered?.files : undefined) ?? results.files;
@ -114,7 +115,7 @@ export class ResultsFilesNode extends ViewNode {
? TreeItemCollapsibleState.Expanded ? TreeItemCollapsibleState.Expanded
: TreeItemCollapsibleState.Collapsed; : TreeItemCollapsibleState.Collapsed;
} catch (ex) { } catch (ex) {
if (ex instanceof Promises.CancellationError) {
if (ex instanceof PromiseCancelledError) {
ex.promise.then(() => queueMicrotask(() => this.triggerChange(false))); ex.promise.then(() => queueMicrotask(() => this.triggerChange(false)));
} }

+ 6
- 3
src/views/searchAndCompareView.ts 查看文件

@ -8,7 +8,10 @@ import { GitUri } from '../git/gitUri';
import { GitLog, GitRevision } from '../git/models'; import { GitLog, GitRevision } from '../git/models';
import { SearchPattern } from '../git/search'; import { SearchPattern } from '../git/search';
import { ReferencePicker, ReferencesQuickPickIncludes } from '../quickpicks'; import { ReferencePicker, ReferencesQuickPickIncludes } from '../quickpicks';
import { debug, gate, Iterables, log, Promises } from '../system';
import { filterMap } from '../system/array';
import { gate } from '../system/decorators/gate';
import { debug, log } from '../system/decorators/log';
import { isPromise } from '../system/promise';
import { import {
CompareResultsNode, CompareResultsNode,
ContextValues, ContextValues,
@ -121,9 +124,9 @@ export class SearchAndCompareViewNode extends ViewNode {
if (this.children.length === 0) return; if (this.children.length === 0) return;
const promises: Promise<any>[] = [ const promises: Promise<any>[] = [
...Iterables.filterMap(this.children, c => {
...filterMap(this.children, c => {
const result = c.refresh === undefined ? false : c.refresh(); const result = c.refresh === undefined ? false : c.refresh();
return Promises.is<boolean | void>(result) ? result : undefined;
return isPromise<boolean | void>(result) ? result : undefined;
}), }),
]; ];
await Promise.all(promises); await Promise.all(promises);

+ 8
- 10
src/views/viewBase.ts 查看文件

@ -34,7 +34,9 @@ import {
} from '../configuration'; } from '../configuration';
import { Container } from '../container'; import { Container } from '../container';
import { Logger } from '../logger'; import { Logger } from '../logger';
import { debug, Functions, log, Promises } from '../system';
import { debug, log } from '../system/decorators/log';
import { debounce } from '../system/function';
import { cancellable, isPromise } from '../system/promise';
import { BranchesView } from './branchesView'; import { BranchesView } from './branchesView';
import { CommitsView } from './commitsView'; import { CommitsView } from './commitsView';
import { ContributorsView } from './contributorsView'; import { ContributorsView } from './contributorsView';
@ -240,7 +242,7 @@ export abstract class ViewBase<
this.onConfigurationChanged(e); this.onConfigurationChanged(e);
}, this), }, this),
this.tree, this.tree,
this.tree.onDidChangeVisibility(Functions.debounce(this.onVisibilityChanged, 250), this),
this.tree.onDidChangeVisibility(debounce(this.onVisibilityChanged, 250), this),
this.tree.onDidCollapseElement(this.onElementCollapsed, this), this.tree.onDidCollapseElement(this.onElementCollapsed, this),
this.tree.onDidExpandElement(this.onElementExpanded, this), this.tree.onDidExpandElement(this.onElementExpanded, this),
); );
@ -394,7 +396,7 @@ export abstract class ViewBase<
if (predicate(node)) return node; if (predicate(node)) return node;
if (canTraverse != null) { if (canTraverse != null) {
const traversable = canTraverse(node); const traversable = canTraverse(node);
if (Promises.is(traversable)) {
if (isPromise(traversable)) {
if (!(await traversable)) continue; if (!(await traversable)) continue;
} else if (!traversable) { } else if (!traversable) {
continue; continue;
@ -418,13 +420,9 @@ export abstract class ViewBase<
await this.loadMoreNodeChildren(node, defaultPageSize); await this.loadMoreNodeChildren(node, defaultPageSize);
pagedChildren = await Promises.cancellable(
Promise.resolve(node.getChildren()),
token ?? 60000,
{
onDidCancel: resolve => resolve([]),
},
);
pagedChildren = await cancellable(Promise.resolve(node.getChildren()), token ?? 60000, {
onDidCancel: resolve => resolve([]),
});
child = pagedChildren.find(predicate); child = pagedChildren.find(predicate);
if (child != null) return child; if (child != null) return child;

Loading…
取消
儲存