Sfoglia il codice sorgente

Fixes first return type

main
Eric Amodio 2 anni fa
parent
commit
645f8a3699
7 ha cambiato i file con 18 aggiunte e 15 eliminazioni
  1. +1
    -1
      src/annotations/gutterBlameAnnotationProvider.ts
  2. +6
    -4
      src/codelens/codeLensProvider.ts
  3. +2
    -1
      src/commands/copyShaToClipboard.ts
  4. +2
    -2
      src/commands/remoteProviders.ts
  5. +4
    -4
      src/env/node/git/localGitProvider.ts
  6. +2
    -2
      src/system/iterable.ts
  7. +1
    -1
      src/views/nodes/branchTrackingStatusNode.ts

+ 1
- 1
src/annotations/gutterBlameAnnotationProvider.ts Vedi File

@ -191,7 +191,7 @@ export class GutterBlameAnnotationProvider extends BlameAnnotationProviderBase {
sha = commitLine?.sha;
}
} else {
sha = first(blame.commits.values()).sha;
sha = first(blame.commits.values())?.sha;
}
if (!sha) {

+ 6
- 4
src/codelens/codeLensProvider.ts Vedi File

@ -480,9 +480,11 @@ export class GitCodeLensProvider implements CodeLensProvider {
private resolveGitRecentChangeCodeLens(lens: GitRecentChangeCodeLens, _token: CancellationToken): CodeLens {
const blame = lens.getBlame();
if (blame === undefined) return lens;
if (blame == null) return lens;
const recentCommit = first(blame.commits.values());
if (recentCommit == null) return lens;
// TODO@eamodio This is FAR too expensive, but this accounts for commits that delete lines -- is there another way?
// if (lens.uri != null) {
// const commit = await this.container.git.getCommitForFile(lens.uri.repoPath, lens.uri.fsPath, {
@ -564,11 +566,10 @@ export class GitCodeLensProvider implements CodeLensProvider {
private resolveGitAuthorsCodeLens(lens: GitAuthorsCodeLens, _token: CancellationToken): CodeLens {
const blame = lens.getBlame();
if (blame === undefined) return lens;
if (blame == null) return lens;
const count = blame.authors.size;
const author = first(blame.authors.values()).name;
const author = first(blame.authors.values())?.name ?? 'Unknown';
let title = `${count} ${count > 1 ? 'authors' : 'author'} (${author}${count > 1 ? ' and others' : ''})`;
if (configuration.get('debug')) {
@ -589,6 +590,7 @@ export class GitCodeLensProvider implements CodeLensProvider {
}
const commit = find(blame.commits.values(), c => c.author.name === author) ?? first(blame.commits.values());
if (commit == null) return lens;
switch (lens.desiredCommand) {
case CodeLensCommand.CopyRemoteCommitUrl:

+ 2
- 1
src/commands/copyShaToClipboard.ts Vedi File

@ -65,7 +65,8 @@ export class CopyShaToClipboardCommand extends ActiveEditorCommand {
const log = await this.container.git.getLog(repoPath, { limit: 1 });
if (log == null) return;
args.sha = first(log.commits.values()).sha;
args.sha = first(log.commits.values())?.sha;
if (args.sha == null) return;
} else if (args.sha == null) {
const blameline = editor?.selection.active.line ?? 0;
if (blameline < 0) return;

+ 2
- 2
src/commands/remoteProviders.ts Vedi File

@ -62,7 +62,7 @@ export class ConnectRemoteProviderCommand extends Command {
if (repos.size === 0) return false;
if (repos.size === 1) {
let repo;
[repo, remote] = first(repos);
[repo, remote] = first(repos)!;
repoPath = repo.path;
} else {
const pick = await RepositoryPicker.show(
@ -153,7 +153,7 @@ export class DisconnectRemoteProviderCommand extends Command {
if (repos.size === 0) return undefined;
if (repos.size === 1) {
let repo;
[repo, remote] = first(repos);
[repo, remote] = first(repos)!;
repoPath = repo.path;
} else {
const pick = await RepositoryPicker.show(

+ 4
- 4
src/env/node/git/localGitProvider.ts Vedi File

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

+ 2
- 2
src/system/iterable.ts Vedi File

@ -107,8 +107,8 @@ export function find(source: Iterable | IterableIterator, predicate: (i
return null;
}
export function first<T>(source: Iterable<T> | IterableIterator<T>): T {
return source[Symbol.iterator]().next().value as T;
export function first<T>(source: Iterable<T> | IterableIterator<T>): T | undefined {
return source[Symbol.iterator]().next().value as T | undefined;
}
export function* flatMap<T, TMapped>(

+ 1
- 1
src/views/nodes/branchTrackingStatusNode.ts Vedi File

@ -92,7 +92,7 @@ export class BranchTrackingStatusNode extends ViewNode impleme
ref: commit.sha,
});
if (previousLog != null) {
commits[commits.length - 1] = first(previousLog.commits.values());
commits[commits.length - 1] = first(previousLog.commits.values())!;
}
}
} else {

Caricamento…
Annulla
Salva