Skip to content

Commit f7dc254

Browse files
committed
Improves error handling for #2209
1 parent 0e679d8 commit f7dc254

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/codelens/codeLensProvider.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { configuration } from '../system/configuration';
3131
import { is, once } from '../system/function';
3232
import { filterMap, find, first, join, map } from '../system/iterable';
3333
import { Logger } from '../system/logger';
34+
import { pluralize } from '../system/string';
3435
import { isVirtualUri } from '../system/utils';
3536

3637
class GitRecentChangeCodeLens extends CodeLens {
@@ -477,10 +478,10 @@ export class GitCodeLensProvider implements CodeLensProvider {
477478

478479
private resolveGitRecentChangeCodeLens(lens: GitRecentChangeCodeLens, _token: CancellationToken): CodeLens {
479480
const blame = lens.getBlame();
480-
if (blame == null) return lens;
481+
if (blame == null) return applyCommandWithNoClickAction('Unknown, (Blame failed)', lens);
481482

482483
const recentCommit = first(blame.commits.values());
483-
if (recentCommit == null) return lens;
484+
if (recentCommit == null) return applyCommandWithNoClickAction('Unknown, (Blame failed)', lens);
484485

485486
// TODO@eamodio This is FAR too expensive, but this accounts for commits that delete lines -- is there another way?
486487
// if (lens.uri != null) {
@@ -553,12 +554,12 @@ export class GitCodeLensProvider implements CodeLensProvider {
553554

554555
private resolveGitAuthorsCodeLens(lens: GitAuthorsCodeLens, _token: CancellationToken): CodeLens {
555556
const blame = lens.getBlame();
556-
if (blame == null) return lens;
557+
if (blame == null) return applyCommandWithNoClickAction('? authors (Blame failed)', lens);
557558

558559
const count = blame.authors.size;
559560
const author = first(blame.authors.values())?.name ?? 'Unknown';
560561

561-
let title = `${count} ${count > 1 ? 'authors' : 'author'} (${author}${count > 1 ? ' and others' : ''})`;
562+
let title = `${pluralize('author', count, { zero: '?' })} (${author}${count > 1 ? ' and others' : ''})`;
562563
if (configuration.get('debug')) {
563564
title += ` [${lens.languageId}: ${SymbolKind[lens.symbol.kind]}(${lens.range.start.character}-${
564565
lens.range.end.character
@@ -577,7 +578,7 @@ export class GitCodeLensProvider implements CodeLensProvider {
577578
}
578579

579580
const commit = find(blame.commits.values(), c => c.author.name === author) ?? first(blame.commits.values());
580-
if (commit == null) return lens;
581+
if (commit == null) return applyCommandWithNoClickAction(title, lens);
581582

582583
switch (lens.desiredCommand) {
583584
case CodeLensCommand.CopyRemoteCommitUrl:

0 commit comments

Comments
 (0)