Skip to content

Commit

Permalink
Refactors command constants & adds type-safety
Browse files Browse the repository at this point in the history
  - Allows string literals to be used instead of enums
  - Renames `Command` to `GlCommandBase`
  - Renames `Commands` to `GlCommand`
  - Adds new string literal types for commands:
    - `GlCommands`, `TreeViewCommands`, `WebviewCommands`, `WebviewViewCommands`
  - Adds new `Commands` type as a rollup of the rest
  • Loading branch information
eamodio committed Dec 12, 2024
1 parent b8590a5 commit f457470
Show file tree
Hide file tree
Showing 156 changed files with 1,586 additions and 1,133 deletions.
2 changes: 1 addition & 1 deletion docs/telemetry-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -1783,7 +1783,7 @@ or
```typescript
{
'usage.count': number,
'usage.key': 'graphWebview:shown' | 'patchDetailsWebview:shown' | 'settingsWebview:shown' | 'timelineWebview:shown' | 'graphView:shown' | 'patchDetailsView:shown' | 'timelineView:shown' | 'commitDetailsView:shown' | 'graphDetailsView:shown' | 'homeView:shown' | 'commitsView:shown' | 'stashesView:shown' | 'tagsView:shown' | 'launchpadView:shown' | 'worktreesView:shown' | 'branchesView:shown' | 'contributorsView:shown' | 'draftsView:shown' | 'fileHistoryView:shown' | 'scm.groupedView:shown' | 'lineHistoryView:shown' | 'pullRequestView:shown' | 'remotesView:shown' | 'repositoriesView:shown' | 'searchAndCompareView:shown' | 'workspacesView:shown' | 'rebaseEditor:shown' | 'command:gitlens.action.:executed' | 'command:gitlens.addAuthors:executed' | 'command:gitlens.browseRepoAtRevision:executed' | 'command:gitlens.browseRepoAtRevisionInNewWindow:executed' | 'command:gitlens.browseRepoBeforeRevision:executed' | 'command:gitlens.browseRepoBeforeRevisionInNewWindow:executed' | 'command:gitlens.clearFileAnnotations:executed' | 'command:gitlens.closeUnchangedFiles:executed' | 'command:gitlens.compareWith:executed' | 'command:gitlens.compareHeadWith:executed' | 'command:gitlens.compareWorkingWith:executed' | 'command:gitlens.computingFileAnnotations:executed' | 'command:gitlens.connectRemoteProvider:executed' | 'command:gitlens.copyCurrentBranch:executed' | 'command:gitlens.copyDeepLinkToBranch:executed' | 'command:gitlens.copyDeepLinkToCommit:executed' | 'command:gitlens.copyDeepLinkToComparison:executed' | 'command:gitlens.copyDeepLinkToFile:executed' | 'command:gitlens.copyDeepLinkToFileAtRevision:executed' | 'command:gitlens.copyDeepLinkToLines:executed' | 'command:gitlens.copyDeepLinkToRepo:executed' | 'command:gitlens.copyDeepLinkToTag:executed' | 'command:gitlens.copyDeepLinkToWorkspace:executed' | 'command:gitlens.copyMessageToClipboard:executed' | 'command:gitlens.copyRemoteBranchesUrl:executed' | 'command:gitlens.copyRemoteBranchUrl:executed' | 'command:gitlens.copyRemoteCommitUrl:executed' | 'command:gitlens.copyRemoteComparisonUrl:executed' | 'command:gitlens.copyRemoteFileUrlToClipboard:executed' | 'command:gitlens.copyRemoteFileUrlWithoutRange:executed' | 'command:gitlens.copyRemoteFileUrlFrom:executed' | 'command:gitlens.copyRemotePullRequestUrl:executed' | 'command:gitlens.copyRemoteRepositoryUrl:executed' | 'command:gitlens.copyShaToClipboard:executed' | 'command:gitlens.copyRelativePathToClipboard:executed' | 'command:gitlens.applyPatchFromClipboard:executed' | 'command:gitlens.pastePatchFromClipboard:executed' | 'command:gitlens.copyPatchToClipboard:executed' | 'command:gitlens.copyWorkingChangesToWorktree:executed' | 'command:gitlens.createPatch:executed' | 'command:gitlens.createCloudPatch:executed' | 'command:gitlens.createPullRequestOnRemote:executed' | 'command:gitlens.diffDirectory:executed' | 'command:gitlens.diffDirectoryWithHead:executed' | 'command:gitlens.diffFolderWithRevision:executed' | 'command:gitlens.diffFolderWithRevisionFrom:executed' | 'command:gitlens.diffWith:executed' | 'command:gitlens.diffWithNext:executed' | 'command:gitlens.diffWithNextInDiffLeft:executed' | 'command:gitlens.diffWithNextInDiffRight:executed' | 'command:gitlens.diffWithPrevious:executed' | 'command:gitlens.diffWithPreviousInDiffLeft:executed' | 'command:gitlens.diffWithPreviousInDiffRight:executed' | 'command:gitlens.diffLineWithPrevious:executed' | 'command:gitlens.diffWithRevision:executed' | 'command:gitlens.diffWithRevisionFrom:executed' | 'command:gitlens.diffWithWorking:executed' | 'command:gitlens.diffWithWorkingInDiffLeft:executed' | 'command:gitlens.diffWithWorkingInDiffRight:executed' | 'command:gitlens.diffLineWithWorking:executed' | 'command:gitlens.disconnectRemoteProvider:executed' | 'command:gitlens.disableDebugLogging:executed' | 'command:gitlens.enableDebugLogging:executed' | 'command:gitlens.disableRebaseEditor:executed' | 'command:gitlens.enableRebaseEditor:executed' | 'command:gitlens.externalDiff:executed' | 'command:gitlens.externalDiffAll:executed' | 'command:gitlens.fetchRepositories:executed' | 'command:gitlens.generateCommitMessage:executed' | 'command:gitlens.scm.generateCommitMessage:executed' | 'command:gitlens.getStarted:executed' | 'command:gitlens.gk.switchOrganization:executed' | 'command:gitlens.inviteToLiveShare:executed' | 'command:gitlens.openBlamePriorToChange:executed' | 'command:gitlens.openBranchesOnRemote:executed' | 'command:gitlens.openBranchOnRemote:executed' | 'command:gitlens.openCurrentBranchOnRemote:executed' | 'command:gitlens.openChangedFiles:executed' | 'command:gitlens.openCommitOnRemote:executed' | 'command:gitlens.openComparisonOnRemote:executed' | 'command:gitlens.openFileHistory:executed' | 'command:gitlens.openFileFromRemote:executed' | 'command:gitlens.openFileOnRemote:executed' | 'command:gitlens.openFileOnRemoteFrom:executed' | 'command:gitlens.openFileRevision:executed' | 'command:gitlens.openFileRevisionFrom:executed' | 'command:gitlens.openFolderHistory:executed' | 'command:gitlens.openOnRemote:executed' | 'command:gitlens.openCloudPatch:executed' | 'command:gitlens.openPatch:executed' | 'command:gitlens.openPullRequestOnRemote:executed' | 'command:gitlens.openAssociatedPullRequestOnRemote:executed' | 'command:gitlens.openRepoOnRemote:executed' | 'command:gitlens.openRevisionFile:executed' | 'command:gitlens.openRevisionFileInDiffLeft:executed' | 'command:gitlens.openRevisionFileInDiffRight:executed' | 'command:gitlens.openWalkthrough:executed' | 'command:gitlens.openWorkingFile:executed' | 'command:gitlens.openWorkingFileInDiffLeft:executed' | 'command:gitlens.openWorkingFileInDiffRight:executed' | 'command:gitlens.pullRepositories:executed' | 'command:gitlens.pushRepositories:executed' | 'command:gitlens.gitCommands:executed' | 'command:gitlens.gitCommands.branch:executed' | 'command:gitlens.gitCommands.branch.create:executed' | 'command:gitlens.gitCommands.branch.delete:executed' | 'command:gitlens.gitCommands.branch.prune:executed' | 'command:gitlens.gitCommands.branch.rename:executed' | 'command:gitlens.gitCommands.checkout:executed' | 'command:gitlens.gitCommands.cherryPick:executed' | 'command:gitlens.gitCommands.history:executed' | 'command:gitlens.gitCommands.merge:executed' | 'command:gitlens.gitCommands.rebase:executed' | 'command:gitlens.gitCommands.remote:executed' | 'command:gitlens.gitCommands.remote.add:executed' | 'command:gitlens.gitCommands.remote.prune:executed' | 'command:gitlens.gitCommands.remote.remove:executed' | 'command:gitlens.gitCommands.reset:executed' | 'command:gitlens.gitCommands.revert:executed' | 'command:gitlens.gitCommands.show:executed' | 'command:gitlens.gitCommands.stash:executed' | 'command:gitlens.gitCommands.stash.drop:executed' | 'command:gitlens.gitCommands.stash.list:executed' | 'command:gitlens.gitCommands.stash.pop:executed' | 'command:gitlens.gitCommands.stash.push:executed' | 'command:gitlens.gitCommands.stash.rename:executed' | 'command:gitlens.gitCommands.status:executed' | 'command:gitlens.gitCommands.switch:executed' | 'command:gitlens.gitCommands.tag:executed' | 'command:gitlens.gitCommands.tag.create:executed' | 'command:gitlens.gitCommands.tag.delete:executed' | 'command:gitlens.gitCommands.worktree:executed' | 'command:gitlens.gitCommands.worktree.create:executed' | 'command:gitlens.gitCommands.worktree.delete:executed' | 'command:gitlens.gitCommands.worktree.open:executed' | 'command:gitlens.ghpr.views.openOrCreateWorktree:executed' | 'command:gitlens.plus.cloudIntegrations.connect:executed' | 'command:gitlens.plus.hide:executed' | 'command:gitlens.plus.login:executed' | 'command:gitlens.plus.logout:executed' | 'command:gitlens.plus.manage:executed' | 'command:gitlens.plus.cloudIntegrations.manage:executed' | 'command:gitlens.plus.reactivateProTrial:executed' | 'command:gitlens.plus.resendVerification:executed' | 'command:gitlens.plus.restore:executed' | 'command:gitlens.plus.showPlans:executed' | 'command:gitlens.plus.signUp:executed' | 'command:gitlens.plus.startPreviewTrial:executed' | 'command:gitlens.plus.continueFeaturePreview:executed' | 'command:gitlens.plus.upgrade:executed' | 'command:gitlens.plus.validate:executed' | 'command:gitlens.plus.simulateSubscription:executed' | 'command:gitlens.quickOpenFileHistory:executed' | 'command:gitlens.launchpad.refresh:executed' | 'command:gitlens.graph.refresh:executed' | 'command:gitlens.refreshHover:executed' | 'command:gitlens.reset:executed' | 'command:gitlens.resetAIKey:executed' | 'command:gitlens.resetViewsLayout:executed' | 'command:gitlens.revealCommitInView:executed' | 'command:gitlens.shareAsCloudPatch:executed' | 'command:gitlens.showCommitSearch:executed' | 'command:gitlens.views.searchAndCompare.searchCommits:executed' | 'command:gitlens.showBranchesView:executed' | 'command:gitlens.showCommitDetailsView:executed' | 'command:gitlens.showCommitInView:executed' | 'command:gitlens.showCommitsInView:executed' | 'command:gitlens.showCommitsView:executed' | 'command:gitlens.showContributorsView:executed' | 'command:gitlens.showDraftsView:executed' | 'command:gitlens.showFileHistoryView:executed' | 'command:gitlens.showGraph:executed' | 'command:gitlens.showGraphPage:executed' | 'command:gitlens.showGraphView:executed' | 'command:gitlens.showHomeView:executed' | 'command:gitlens.showAccountView:executed' | 'command:gitlens.showInCommitGraph:executed' | 'command:gitlens.showInCommitGraphView:executed' | 'command:gitlens.showInDetailsView:executed' | 'command:gitlens.showInTimeline:executed' | 'command:gitlens.showLastQuickPick:executed' | 'command:gitlens.showLaunchpad:executed' | 'command:gitlens.showLaunchpadView:executed' | 'command:gitlens.showLineCommitInView:executed' | 'command:gitlens.showLineHistoryView:executed' | 'command:gitlens.openOnlyChangedFiles:executed' | 'command:gitlens.showPatchDetailsPage:executed' | 'command:gitlens.showQuickBranchHistory:executed' | 'command:gitlens.showQuickCommitDetails:executed' | 'command:gitlens.showQuickCommitFileDetails:executed' | 'command:gitlens.showQuickRepoHistory:executed' | 'command:gitlens.showQuickFileHistory:executed' | 'command:gitlens.showQuickRepoStatus:executed' | 'command:gitlens.showQuickRevisionDetails:executed' | 'command:gitlens.showQuickRevisionDetailsInDiffLeft:executed' | 'command:gitlens.showQuickRevisionDetailsInDiffRight:executed' | 'command:gitlens.showQuickStashList:executed' | 'command:gitlens.showRemotesView:executed' | 'command:gitlens.showRepositoriesView:executed' | 'command:gitlens.showSearchAndCompareView:executed' | 'command:gitlens.showSettingsPage:executed' | 'command:gitlens.showSettingsPage!file-annotations:executed' | 'command:gitlens.showSettingsPage!branches-view:executed' | 'command:gitlens.showSettingsPage!commits-view:executed' | 'command:gitlens.showSettingsPage!contributors-view:executed' | 'command:gitlens.showSettingsPage!file-history-view:executed' | 'command:gitlens.showSettingsPage!line-history-view:executed' | 'command:gitlens.showSettingsPage!remotes-view:executed' | 'command:gitlens.showSettingsPage!repositories-view:executed' | 'command:gitlens.showSettingsPage!search-compare-view:executed' | 'command:gitlens.showSettingsPage!stashes-view:executed' | 'command:gitlens.showSettingsPage!tags-view:executed' | 'command:gitlens.showSettingsPage!worktrees-view:executed' | 'command:gitlens.showSettingsPage!views:executed' | 'command:gitlens.showSettingsPage!commit-graph:executed' | 'command:gitlens.showSettingsPage!autolinks:executed' | 'command:gitlens.showStashesView:executed' | 'command:gitlens.showTagsView:executed' | 'command:gitlens.showTimelinePage:executed' | 'command:gitlens.showTimelineView:executed' | 'command:gitlens.showWorktreesView:executed' | 'command:gitlens.showWorkspacesView:executed' | 'command:gitlens.startWork:executed' | 'command:gitlens.stashApply:executed' | 'command:gitlens.stashSave:executed' | 'command:gitlens.stashSaveFiles:executed' | 'command:gitlens.switchAIModel:executed' | 'command:gitlens.switchMode:executed' | 'command:gitlens.toggleCodeLens:executed' | 'command:gitlens.toggleFileBlame:executed' | 'command:gitlens.toggleFileBlameInDiffLeft:executed' | 'command:gitlens.toggleFileBlameInDiffRight:executed' | 'command:gitlens.toggleFileChanges:executed' | 'command:gitlens.toggleFileChangesOnly:executed' | 'command:gitlens.toggleFileHeatmap:executed' | 'command:gitlens.toggleFileHeatmapInDiffLeft:executed' | 'command:gitlens.toggleFileHeatmapInDiffRight:executed' | 'command:gitlens.launchpad.indicator.toggle:executed' | 'command:gitlens.toggleGraph:executed' | 'command:gitlens.toggleMaximizedGraph:executed' | 'command:gitlens.toggleLineBlame:executed' | 'command:gitlens.toggleReviewMode:executed' | 'command:gitlens.toggleZenMode:executed' | 'command:gitlens.views.copy:executed' | 'command:gitlens.views.copyAsMarkdown:executed' | 'command:gitlens.views.copyUrl:executed' | 'command:gitlens.views.openChangedFileDiffs:executed' | 'command:gitlens.views.openDirectoryDiff:executed' | 'command:gitlens.views.openDirectoryDiffWithWorking:executed' | 'command:gitlens.views.openUrl:executed' | 'command:gitlens.walkthrough.connectIntegrations:executed' | 'command:gitlens.walkthrough.gitlensInspect:executed' | 'command:gitlens.walkthrough.openAcceleratePrReviews:executed' | 'command:gitlens.walkthrough.openCommunityVsPro:executed' | 'command:gitlens.walkthrough.openHelpCenter:executed' | 'command:gitlens.walkthrough.openInteractiveCodeHistory:executed' | 'command:gitlens.walkthrough.openStartIntegrations:executed' | 'command:gitlens.walkthrough.openStreamlineCollaboration:executed' | 'command:gitlens.walkthrough.openWalkthrough:executed' | 'command:gitlens.walkthrough.plus.signUp:executed' | 'command:gitlens.walkthrough.plus.upgrade:executed' | 'command:gitlens.walkthrough.plus.reactivate:executed' | 'command:gitlens.walkthrough.showAutolinks:executed' | 'command:gitlens.walkthrough.showDraftsView:executed' | 'command:gitlens.walkthrough.showGraph:executed' | 'command:gitlens.walkthrough.showLaunchpad:executed' | 'command:gitlens.walkthrough.worktree.create:executed' | 'command:gitlens.walkthrough.openDevExPlatform:executed' | 'command:gitlens.diffHeadWith:executed' | 'command:gitlens.diffWorkingWith:executed' | 'command:gitlens.openBranchesInRemote:executed' | 'command:gitlens.openBranchInRemote:executed' | 'command:gitlens.openCommitInRemote:executed' | 'command:gitlens.openFileInRemote:executed' | 'command:gitlens.openInRemote:executed' | 'command:gitlens.openRepoInRemote:executed' | 'command:gitlens.showFileHistoryInView:executed' | 'home:walkthrough:dismissed'
'usage.key': 'graphWebview:shown' | 'patchDetailsWebview:shown' | 'settingsWebview:shown' | 'timelineWebview:shown' | 'graphView:shown' | 'patchDetailsView:shown' | 'timelineView:shown' | 'commitDetailsView:shown' | 'graphDetailsView:shown' | 'homeView:shown' | 'commitsView:shown' | 'stashesView:shown' | 'tagsView:shown' | 'launchpadView:shown' | 'worktreesView:shown' | 'branchesView:shown' | 'contributorsView:shown' | 'draftsView:shown' | 'fileHistoryView:shown' | 'scm.groupedView:shown' | 'lineHistoryView:shown' | 'pullRequestView:shown' | 'remotesView:shown' | 'repositoriesView:shown' | 'searchAndCompareView:shown' | 'workspacesView:shown' | 'rebaseEditor:shown' | `command:${string}:executed` | 'home:walkthrough:dismissed'
}
```

Expand Down
4 changes: 2 additions & 2 deletions src/api/actionRunners.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Event, QuickPickItem } from 'vscode';
import { Disposable, EventEmitter, window } from 'vscode';
import type { Config } from '../config';
import { Commands } from '../constants.commands';
import { actionCommandPrefix } from '../constants.commands';
import type { Container } from '../container';
import { getScopedCounter } from '../system/counter';
import { sortCompare } from '../system/string';
Expand Down Expand Up @@ -137,7 +137,7 @@ export class ActionRunners implements Disposable {

for (const action of actions) {
subscriptions.push(
registerCommand(`${Commands.ActionPrefix}${action}`, (context: ActionContext, runnerId?: number) =>
registerCommand(`${actionCommandPrefix}${action}`, (context: ActionContext, runnerId?: number) =>
this.run(context, runnerId),
),
);
Expand Down
17 changes: 9 additions & 8 deletions src/codelens/codeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import type { ToggleFileChangesAnnotationCommandArgs } from '../commands/toggleF
import type { CodeLensConfig, CodeLensLanguageScope } from '../config';
import { CodeLensCommand } from '../config';
import { trackableSchemes } from '../constants';
import { Commands } from '../constants.commands';
import type { GlCommands } from '../constants.commands';
import { GlCommand } from '../constants.commands';
import type { Container } from '../container';
import type { GitUri } from '../git/gitUri';
import type { GitBlame } from '../git/models/blame';
Expand Down Expand Up @@ -611,7 +612,7 @@ function applyDiffWithPreviousCommand<T extends GitRecentChangeCodeLens | GitAut
commit: GitCommit | undefined,
): T {
lens.command = createCommand<[undefined, DiffWithPreviousCommandArgs]>(
Commands.DiffWithPrevious,
GlCommand.DiffWithPrevious,
title,
undefined,
{
Expand All @@ -628,7 +629,7 @@ function applyCopyOrOpenCommitOnRemoteCommand<T extends GitRecentChangeCodeLens
commit: GitCommit,
clipboard: boolean = false,
): T {
lens.command = createCommand<[OpenOnRemoteCommandArgs]>(Commands.OpenOnRemote, title, {
lens.command = createCommand<[OpenOnRemoteCommandArgs]>(GlCommand.OpenOnRemote, title, {
resource: {
type: RemoteResourceType.Commit,
sha: commit.sha,
Expand All @@ -645,7 +646,7 @@ function applyCopyOrOpenFileOnRemoteCommand<T extends GitRecentChangeCodeLens |
commit: GitCommit,
clipboard: boolean = false,
): T {
lens.command = createCommand<[OpenOnRemoteCommandArgs]>(Commands.OpenOnRemote, title, {
lens.command = createCommand<[OpenOnRemoteCommandArgs]>(GlCommand.OpenOnRemote, title, {
resource: {
type: RemoteResourceType.Revision,
fileName: commit.file?.path ?? '',
Expand Down Expand Up @@ -688,7 +689,7 @@ function applyShowCommitsInViewCommand<T extends GitRecentChangeCodeLens | GitAu
}

lens.command = createCommand<[ShowCommitsInViewCommandArgs]>(
refs.length === 0 ? ('' as Commands) : Commands.ShowCommitsInView,
refs.length === 0 ? ('' as GlCommands) : GlCommand.ShowCommitsInView,
title,
{
repoPath: blame.repoPath,
Expand Down Expand Up @@ -759,7 +760,7 @@ function applyToggleFileBlameCommand<T extends GitRecentChangeCodeLens | GitAuth
title: string,
lens: T,
): T {
lens.command = createCommand<[Uri]>(Commands.ToggleFileBlame, title, lens.uri!.toFileUri());
lens.command = createCommand<[Uri]>(GlCommand.ToggleFileBlame, title, lens.uri!.toFileUri());
return lens;
}

Expand All @@ -770,7 +771,7 @@ function applyToggleFileChangesCommand<T extends GitRecentChangeCodeLens | GitAu
only?: boolean,
): T {
lens.command = createCommand<[Uri, ToggleFileChangesAnnotationCommandArgs]>(
Commands.ToggleFileChanges,
GlCommand.ToggleFileChanges,
title,
lens.uri!.toFileUri(),
{
Expand All @@ -785,7 +786,7 @@ function applyToggleFileHeatmapCommand<T extends GitRecentChangeCodeLens | GitAu
title: string,
lens: T,
): T {
lens.command = createCommand<[Uri]>(Commands.ToggleFileHeatmap, title, lens.uri!.toFileUri());
lens.command = createCommand<[Uri]>(GlCommand.ToggleFileHeatmap, title, lens.uri!.toFileUri());
return lens;
}

Expand Down
8 changes: 4 additions & 4 deletions src/commands/addAuthors.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { SourceControl } from 'vscode';
import { Commands } from '../constants.commands';
import { GlCommand } from '../constants.commands';
import type { Container } from '../container';
import { executeGitCommand } from '../git/actions';
import { command } from '../system/vscode/command';
import { Command } from './base';
import { GlCommandBase } from './base';

@command()
export class AddAuthorsCommand extends Command {
export class AddAuthorsCommand extends GlCommandBase {
constructor(private readonly container: Container) {
super(Commands.AddAuthors);
super(GlCommand.AddAuthors);
}

execute(sourceControl: SourceControl) {
Expand Down
Loading

0 comments on commit f457470

Please sign in to comment.