Skip to content

Commit 645f8a3

Browse files
committed
Fixes first return type
1 parent 04600e8 commit 645f8a3

File tree

7 files changed

+18
-15
lines changed

7 files changed

+18
-15
lines changed

src/annotations/gutterBlameAnnotationProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export class GutterBlameAnnotationProvider extends BlameAnnotationProviderBase {
191191
sha = commitLine?.sha;
192192
}
193193
} else {
194-
sha = first(blame.commits.values()).sha;
194+
sha = first(blame.commits.values())?.sha;
195195
}
196196

197197
if (!sha) {

src/codelens/codeLensProvider.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,11 @@ export class GitCodeLensProvider implements CodeLensProvider {
480480

481481
private resolveGitRecentChangeCodeLens(lens: GitRecentChangeCodeLens, _token: CancellationToken): CodeLens {
482482
const blame = lens.getBlame();
483-
if (blame === undefined) return lens;
483+
if (blame == null) return lens;
484484

485485
const recentCommit = first(blame.commits.values());
486+
if (recentCommit == null) return lens;
487+
486488
// TODO@eamodio This is FAR too expensive, but this accounts for commits that delete lines -- is there another way?
487489
// if (lens.uri != null) {
488490
// const commit = await this.container.git.getCommitForFile(lens.uri.repoPath, lens.uri.fsPath, {
@@ -564,11 +566,10 @@ export class GitCodeLensProvider implements CodeLensProvider {
564566

565567
private resolveGitAuthorsCodeLens(lens: GitAuthorsCodeLens, _token: CancellationToken): CodeLens {
566568
const blame = lens.getBlame();
567-
if (blame === undefined) return lens;
569+
if (blame == null) return lens;
568570

569571
const count = blame.authors.size;
570-
571-
const author = first(blame.authors.values()).name;
572+
const author = first(blame.authors.values())?.name ?? 'Unknown';
572573

573574
let title = `${count} ${count > 1 ? 'authors' : 'author'} (${author}${count > 1 ? ' and others' : ''})`;
574575
if (configuration.get('debug')) {
@@ -589,6 +590,7 @@ export class GitCodeLensProvider implements CodeLensProvider {
589590
}
590591

591592
const commit = find(blame.commits.values(), c => c.author.name === author) ?? first(blame.commits.values());
593+
if (commit == null) return lens;
592594

593595
switch (lens.desiredCommand) {
594596
case CodeLensCommand.CopyRemoteCommitUrl:

src/commands/copyShaToClipboard.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ export class CopyShaToClipboardCommand extends ActiveEditorCommand {
6565
const log = await this.container.git.getLog(repoPath, { limit: 1 });
6666
if (log == null) return;
6767

68-
args.sha = first(log.commits.values()).sha;
68+
args.sha = first(log.commits.values())?.sha;
69+
if (args.sha == null) return;
6970
} else if (args.sha == null) {
7071
const blameline = editor?.selection.active.line ?? 0;
7172
if (blameline < 0) return;

src/commands/remoteProviders.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class ConnectRemoteProviderCommand extends Command {
6262
if (repos.size === 0) return false;
6363
if (repos.size === 1) {
6464
let repo;
65-
[repo, remote] = first(repos);
65+
[repo, remote] = first(repos)!;
6666
repoPath = repo.path;
6767
} else {
6868
const pick = await RepositoryPicker.show(
@@ -153,7 +153,7 @@ export class DisconnectRemoteProviderCommand extends Command {
153153
if (repos.size === 0) return undefined;
154154
if (repos.size === 1) {
155155
let repo;
156-
[repo, remote] = first(repos);
156+
[repo, remote] = first(repos)!;
157157
repoPath = repo.path;
158158
} else {
159159
const pick = await RepositoryPicker.show(

src/env/node/git/localGitProvider.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,8 +1279,8 @@ export class LocalGitProvider implements GitProvider, Disposable {
12791279
if (blame == null) return undefined;
12801280

12811281
return {
1282-
author: first(blame.authors.values()),
1283-
commit: first(blame.commits.values()),
1282+
author: first(blame.authors.values())!,
1283+
commit: first(blame.commits.values())!,
12841284
line: blame.lines[editorLine],
12851285
};
12861286
} catch {
@@ -1330,8 +1330,8 @@ export class LocalGitProvider implements GitProvider, Disposable {
13301330
if (blame == null) return undefined;
13311331

13321332
return {
1333-
author: first(blame.authors.values()),
1334-
commit: first(blame.commits.values()),
1333+
author: first(blame.authors.values())!,
1334+
commit: first(blame.commits.values())!,
13351335
line: blame.lines[editorLine],
13361336
};
13371337
} catch {

src/system/iterable.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ export function find<T>(source: Iterable<T> | IterableIterator<T>, predicate: (i
107107
return null;
108108
}
109109

110-
export function first<T>(source: Iterable<T> | IterableIterator<T>): T {
111-
return source[Symbol.iterator]().next().value as T;
110+
export function first<T>(source: Iterable<T> | IterableIterator<T>): T | undefined {
111+
return source[Symbol.iterator]().next().value as T | undefined;
112112
}
113113

114114
export function* flatMap<T, TMapped>(

src/views/nodes/branchTrackingStatusNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export class BranchTrackingStatusNode extends ViewNode<ViewsWithCommits> impleme
9292
ref: commit.sha,
9393
});
9494
if (previousLog != null) {
95-
commits[commits.length - 1] = first(previousLog.commits.values());
95+
commits[commits.length - 1] = first(previousLog.commits.values())!;
9696
}
9797
}
9898
} else {

0 commit comments

Comments
 (0)