Skip to content

Commit 9053797

Browse files
committed
Removes asCommand helper in favor of createCommand
1 parent e8f3458 commit 9053797

File tree

3 files changed

+105
-152
lines changed

3 files changed

+105
-152
lines changed

src/codelens/codeLensProvider.ts

Lines changed: 80 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { filterMap, find, first, join, map } from '../system/iterable';
3030
import { getLoggableName, Logger } from '../system/logger';
3131
import { startLogScope } from '../system/logger.scope';
3232
import { pluralize } from '../system/string';
33-
import { asCommand, executeCoreCommand } from '../system/vscode/command';
33+
import { createCommand, executeCoreCommand } from '../system/vscode/command';
3434
import { configuration } from '../system/vscode/configuration';
3535
import { isVirtualUri } from '../system/vscode/utils';
3636

@@ -610,17 +610,15 @@ function applyDiffWithPreviousCommand<T extends GitRecentChangeCodeLens | GitAut
610610
lens: T,
611611
commit: GitCommit | undefined,
612612
): T {
613-
lens.command = asCommand<[undefined, DiffWithPreviousCommandArgs]>({
614-
title: title,
615-
command: Commands.DiffWithPrevious,
616-
arguments: [
617-
undefined,
618-
{
619-
commit: commit,
620-
uri: lens.uri!.toFileUri(),
621-
},
622-
],
623-
});
613+
lens.command = createCommand<[undefined, DiffWithPreviousCommandArgs]>(
614+
Commands.DiffWithPrevious,
615+
title,
616+
undefined,
617+
{
618+
commit: commit,
619+
uri: lens.uri!.toFileUri(),
620+
},
621+
);
624622
return lens;
625623
}
626624

@@ -630,19 +628,13 @@ function applyCopyOrOpenCommitOnRemoteCommand<T extends GitRecentChangeCodeLens
630628
commit: GitCommit,
631629
clipboard: boolean = false,
632630
): T {
633-
lens.command = asCommand<[OpenOnRemoteCommandArgs]>({
634-
title: title,
635-
command: Commands.OpenOnRemote,
636-
arguments: [
637-
{
638-
resource: {
639-
type: RemoteResourceType.Commit,
640-
sha: commit.sha,
641-
},
642-
repoPath: commit.repoPath,
643-
clipboard: clipboard,
644-
},
645-
],
631+
lens.command = createCommand<[OpenOnRemoteCommandArgs]>(Commands.OpenOnRemote, title, {
632+
resource: {
633+
type: RemoteResourceType.Commit,
634+
sha: commit.sha,
635+
},
636+
repoPath: commit.repoPath,
637+
clipboard: clipboard,
646638
});
647639
return lens;
648640
}
@@ -653,20 +645,14 @@ function applyCopyOrOpenFileOnRemoteCommand<T extends GitRecentChangeCodeLens |
653645
commit: GitCommit,
654646
clipboard: boolean = false,
655647
): T {
656-
lens.command = asCommand<[OpenOnRemoteCommandArgs]>({
657-
title: title,
658-
command: Commands.OpenOnRemote,
659-
arguments: [
660-
{
661-
resource: {
662-
type: RemoteResourceType.Revision,
663-
fileName: commit.file?.path ?? '',
664-
sha: commit.sha,
665-
},
666-
repoPath: commit.repoPath,
667-
clipboard: clipboard,
668-
},
669-
],
648+
lens.command = createCommand<[OpenOnRemoteCommandArgs]>(Commands.OpenOnRemote, title, {
649+
resource: {
650+
type: RemoteResourceType.Revision,
651+
fileName: commit.file?.path ?? '',
652+
sha: commit.sha,
653+
},
654+
repoPath: commit.repoPath,
655+
clipboard: clipboard,
670656
});
671657
return lens;
672658
}
@@ -676,17 +662,15 @@ function applyRevealCommitInViewCommand<T extends GitRecentChangeCodeLens | GitA
676662
lens: T,
677663
commit: GitCommit | undefined,
678664
): T {
679-
lens.command = asCommand<[Uri, ShowQuickCommitCommandArgs]>({
680-
title: title,
681-
command: commit?.isUncommitted ? '' : CodeLensCommand.RevealCommitInView,
682-
arguments: [
683-
lens.uri!.toFileUri(),
684-
{
685-
commit: commit,
686-
sha: commit === undefined ? undefined : commit.sha,
687-
},
688-
],
689-
});
665+
lens.command = createCommand<[Uri, ShowQuickCommitCommandArgs]>(
666+
commit?.isUncommitted ? ('' as CodeLensCommand) : CodeLensCommand.RevealCommitInView,
667+
title,
668+
lens.uri!.toFileUri(),
669+
{
670+
commit: commit,
671+
sha: commit === undefined ? undefined : commit.sha,
672+
},
673+
);
690674
return lens;
691675
}
692676

@@ -703,16 +687,14 @@ function applyShowCommitsInViewCommand<T extends GitRecentChangeCodeLens | GitAu
703687
refs = [commit.ref];
704688
}
705689

706-
lens.command = asCommand<[ShowCommitsInViewCommandArgs]>({
707-
title: title,
708-
command: refs.length === 0 ? '' : Commands.ShowCommitsInView,
709-
arguments: [
710-
{
711-
repoPath: blame.repoPath,
712-
refs: refs,
713-
},
714-
],
715-
});
690+
lens.command = createCommand<[ShowCommitsInViewCommandArgs]>(
691+
refs.length === 0 ? ('' as Commands) : Commands.ShowCommitsInView,
692+
title,
693+
{
694+
repoPath: blame.repoPath,
695+
refs: refs,
696+
},
697+
);
716698
return lens;
717699
}
718700

@@ -721,17 +703,15 @@ function applyShowQuickCommitDetailsCommand<T extends GitRecentChangeCodeLens |
721703
lens: T,
722704
commit: GitCommit | undefined,
723705
): T {
724-
lens.command = asCommand<[Uri, ShowQuickCommitCommandArgs]>({
725-
title: title,
726-
command: commit?.isUncommitted ? '' : CodeLensCommand.ShowQuickCommitDetails,
727-
arguments: [
728-
lens.uri!.toFileUri(),
729-
{
730-
commit: commit,
731-
sha: commit === undefined ? undefined : commit.sha,
732-
},
733-
],
734-
});
706+
lens.command = createCommand<[Uri, ShowQuickCommitCommandArgs]>(
707+
commit?.isUncommitted ? ('' as CodeLensCommand) : CodeLensCommand.ShowQuickCommitDetails,
708+
title,
709+
lens.uri!.toFileUri(),
710+
{
711+
commit: commit,
712+
sha: commit === undefined ? undefined : commit.sha,
713+
},
714+
);
735715
return lens;
736716
}
737717

@@ -740,58 +720,46 @@ function applyShowQuickCommitFileDetailsCommand<T extends GitRecentChangeCodeLen
740720
lens: T,
741721
commit: GitCommit | undefined,
742722
): T {
743-
lens.command = asCommand<[Uri, ShowQuickCommitFileCommandArgs]>({
744-
title: title,
745-
command: commit?.isUncommitted ? '' : CodeLensCommand.ShowQuickCommitFileDetails,
746-
arguments: [
747-
lens.uri!.toFileUri(),
748-
{
749-
commit: commit,
750-
sha: commit === undefined ? undefined : commit.sha,
751-
},
752-
],
753-
});
723+
lens.command = createCommand<[Uri, ShowQuickCommitFileCommandArgs]>(
724+
commit?.isUncommitted ? ('' as CodeLensCommand) : CodeLensCommand.ShowQuickCommitFileDetails,
725+
title,
726+
lens.uri!.toFileUri(),
727+
{
728+
commit: commit,
729+
sha: commit === undefined ? undefined : commit.sha,
730+
},
731+
);
754732
return lens;
755733
}
756734

757735
function applyShowQuickCurrentBranchHistoryCommand<T extends GitRecentChangeCodeLens | GitAuthorsCodeLens>(
758736
title: string,
759737
lens: T,
760738
): T {
761-
lens.command = asCommand<[Uri]>({
762-
title: title,
763-
command: CodeLensCommand.ShowQuickCurrentBranchHistory,
764-
arguments: [lens.uri!.toFileUri()],
765-
});
739+
lens.command = createCommand<[Uri]>(CodeLensCommand.ShowQuickCurrentBranchHistory, title, lens.uri!.toFileUri());
766740
return lens;
767741
}
768742

769743
function applyShowQuickFileHistoryCommand<T extends GitRecentChangeCodeLens | GitAuthorsCodeLens>(
770744
title: string,
771745
lens: T,
772746
): T {
773-
lens.command = asCommand<[Uri, ShowQuickFileHistoryCommandArgs]>({
774-
title: title,
775-
command: CodeLensCommand.ShowQuickFileHistory,
776-
arguments: [
777-
lens.uri!.toFileUri(),
778-
{
779-
range: lens.isFullRange ? undefined : lens.blameRange,
780-
},
781-
],
782-
});
747+
lens.command = createCommand<[Uri, ShowQuickFileHistoryCommandArgs]>(
748+
CodeLensCommand.ShowQuickFileHistory,
749+
title,
750+
lens.uri!.toFileUri(),
751+
{
752+
range: lens.isFullRange ? undefined : lens.blameRange,
753+
},
754+
);
783755
return lens;
784756
}
785757

786758
function applyToggleFileBlameCommand<T extends GitRecentChangeCodeLens | GitAuthorsCodeLens>(
787759
title: string,
788760
lens: T,
789761
): T {
790-
lens.command = asCommand<[Uri]>({
791-
title: title,
792-
command: Commands.ToggleFileBlame,
793-
arguments: [lens.uri!.toFileUri()],
794-
});
762+
lens.command = createCommand<[Uri]>(Commands.ToggleFileBlame, title, lens.uri!.toFileUri());
795763
return lens;
796764
}
797765

@@ -801,29 +769,23 @@ function applyToggleFileChangesCommand<T extends GitRecentChangeCodeLens | GitAu
801769
commit: GitCommit,
802770
only?: boolean,
803771
): T {
804-
lens.command = asCommand<[Uri, ToggleFileChangesAnnotationCommandArgs]>({
805-
title: title,
806-
command: Commands.ToggleFileChanges,
807-
arguments: [
808-
lens.uri!.toFileUri(),
809-
{
810-
type: 'changes',
811-
context: { sha: commit.sha, only: only, selection: false },
812-
},
813-
],
814-
});
772+
lens.command = createCommand<[Uri, ToggleFileChangesAnnotationCommandArgs]>(
773+
Commands.ToggleFileChanges,
774+
title,
775+
lens.uri!.toFileUri(),
776+
{
777+
type: 'changes',
778+
context: { sha: commit.sha, only: only, selection: false },
779+
},
780+
);
815781
return lens;
816782
}
817783

818784
function applyToggleFileHeatmapCommand<T extends GitRecentChangeCodeLens | GitAuthorsCodeLens>(
819785
title: string,
820786
lens: T,
821787
): T {
822-
lens.command = asCommand<[Uri]>({
823-
title: title,
824-
command: Commands.ToggleFileHeatmap,
825-
arguments: [lens.uri!.toFileUri()],
826-
});
788+
lens.command = createCommand<[Uri]>(Commands.ToggleFileHeatmap, title, lens.uri!.toFileUri());
827789
return lens;
828790
}
829791

src/statusbar/statusBarController.ts

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { Logger } from '../system/logger';
1515
import { getLogScope, setLogScopeExit } from '../system/logger.scope';
1616
import type { MaybePausedResult } from '../system/promise';
1717
import { getSettledValue, pauseOnCancelOrTimeout } from '../system/promise';
18-
import { asCommand } from '../system/vscode/command';
18+
import { createCommand } from '../system/vscode/command';
1919
import { configuration } from '../system/vscode/configuration';
2020
import { isTrackableTextEditor } from '../system/vscode/utils';
2121
import type { LinesChangeEvent, LineState } from '../trackers/lineTracker';
@@ -299,34 +299,30 @@ export class StatusBarController implements Disposable {
299299
break;
300300
case StatusBarCommand.ToggleFileChanges: {
301301
if (commit.file != null) {
302-
this._statusBarBlame.command = asCommand<[Uri, ToggleFileChangesAnnotationCommandArgs]>({
303-
title: 'Toggle File Changes',
304-
command: Commands.ToggleFileChanges,
305-
arguments: [
306-
commit.file.uri,
307-
{
308-
type: 'changes',
309-
context: { sha: commit.sha, only: false, selection: false },
310-
},
311-
],
312-
});
302+
this._statusBarBlame.command = createCommand<[Uri, ToggleFileChangesAnnotationCommandArgs]>(
303+
Commands.ToggleFileChanges,
304+
'Toggle File Changes',
305+
commit.file.uri,
306+
{
307+
type: 'changes',
308+
context: { sha: commit.sha, only: false, selection: false },
309+
},
310+
);
313311
}
314312
actionTooltip = 'Click to Toggle File Changes';
315313
break;
316314
}
317315
case StatusBarCommand.ToggleFileChangesOnly: {
318316
if (commit.file != null) {
319-
this._statusBarBlame.command = asCommand<[Uri, ToggleFileChangesAnnotationCommandArgs]>({
320-
title: 'Toggle File Changes',
321-
command: Commands.ToggleFileChanges,
322-
arguments: [
323-
commit.file.uri,
324-
{
325-
type: 'changes',
326-
context: { sha: commit.sha, only: true, selection: false },
327-
},
328-
],
329-
});
317+
this._statusBarBlame.command = createCommand<[Uri, ToggleFileChangesAnnotationCommandArgs]>(
318+
Commands.ToggleFileChanges,
319+
'Toggle File Changes',
320+
commit.file.uri,
321+
{
322+
type: 'changes',
323+
context: { sha: commit.sha, only: true, selection: false },
324+
},
325+
);
330326
}
331327
actionTooltip = 'Click to Toggle File Changes';
332328
break;

0 commit comments

Comments
 (0)