diff --git a/src/codelens/codeLensProvider.ts b/src/codelens/codeLensProvider.ts index a509d5be4814e..5b5079e2bd6fc 100644 --- a/src/codelens/codeLensProvider.ts +++ b/src/codelens/codeLensProvider.ts @@ -3,7 +3,6 @@ import { CodeLens, CodeLensProvider, Command, - commands, DocumentSelector, DocumentSymbol, Event, @@ -20,6 +19,7 @@ import { command, Commands, DiffWithPreviousCommandArgs, + executeCoreCommand, OpenOnRemoteCommandArgs, ShowCommitsInViewCommandArgs, ShowQuickCommitCommandArgs, @@ -35,7 +35,7 @@ import { configuration, FileAnnotationType, } from '../configuration'; -import { BuiltInCommands, Schemes } from '../constants'; +import { CoreCommands, Schemes } from '../constants'; import { Container } from '../container'; import type { GitUri } from '../git/gitUri'; import { GitBlame, GitBlameLines, GitCommit } from '../git/models'; @@ -158,8 +158,8 @@ export class GitCodeLensProvider implements CodeLensProvider { } else { [blame, symbols] = await Promise.all([ this.container.git.getBlame(gitUri, document), - commands.executeCommand( - BuiltInCommands.ExecuteDocumentSymbolProvider, + executeCoreCommand<[Uri], SymbolInformation[]>( + CoreCommands.ExecuteDocumentSymbolProvider, document.uri, ), ]); @@ -167,8 +167,8 @@ export class GitCodeLensProvider implements CodeLensProvider { if (blame == null || blame?.lines.length === 0) return lenses; } else if (languageScope.scopes.length !== 1 || !languageScope.scopes.includes(CodeLensScopes.Document)) { - symbols = await commands.executeCommand( - BuiltInCommands.ExecuteDocumentSymbolProvider, + symbols = await executeCoreCommand<[Uri], SymbolInformation[]>( + CoreCommands.ExecuteDocumentSymbolProvider, document.uri, ); } diff --git a/src/commands/browseRepoAtRevision.ts b/src/commands/browseRepoAtRevision.ts index 175d483416657..4aa7c24a2f38a 100644 --- a/src/commands/browseRepoAtRevision.ts +++ b/src/commands/browseRepoAtRevision.ts @@ -1,5 +1,5 @@ -import { commands, TextEditor, Uri } from 'vscode'; -import { BuiltInCommands } from '../constants'; +import { TextEditor, Uri } from 'vscode'; +import { CoreCommands } from '../constants'; import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { Logger } from '../logger'; @@ -10,6 +10,7 @@ import { command, CommandContext, Commands, + executeCoreCommand, getCommandUri, openWorkspace, OpenWorkspaceLocation, @@ -75,7 +76,7 @@ export class BrowseRepoAtRevisionCommand extends ActiveEditorCommand { }); if (!args.openInNewWindow) { - void commands.executeCommand(BuiltInCommands.FocusFilesExplorer); + void executeCoreCommand(CoreCommands.FocusFilesExplorer); } } catch (ex) { Logger.error(ex, 'BrowseRepoAtRevisionCommand'); diff --git a/src/commands/closeUnchangedFiles.ts b/src/commands/closeUnchangedFiles.ts index e91a23bf03869..97633469c8f38 100644 --- a/src/commands/closeUnchangedFiles.ts +++ b/src/commands/closeUnchangedFiles.ts @@ -1,11 +1,11 @@ -import { commands, TextEditor, Uri, window } from 'vscode'; +import { TextEditor, Uri, window } from 'vscode'; import { TextEditorComparer, UriComparer } from '../comparers'; -import { BuiltInCommands } from '../constants'; +import { CoreCommands } from '../constants'; import type { Container } from '../container'; import { Logger } from '../logger'; import { Messages } from '../messages'; import { debounce } from '../system/function'; -import { Command, command, Commands, getRepoPathOrPrompt } from './common'; +import { Command, command, Commands, executeCoreCommand, getRepoPathOrPrompt } from './common'; export interface CloseUnchangedFilesCommandArgs { uris?: Uri[]; @@ -38,7 +38,7 @@ export class CloseUnchangedFilesCommand extends Command { } if (args.uris.length === 0) { - void commands.executeCommand(BuiltInCommands.CloseAllEditors); + void executeCoreCommand(CoreCommands.CloseAllEditors); return; } @@ -106,7 +106,7 @@ export class CloseUnchangedFilesCommand extends Command { private async closeEditor(timeout: number = 500): Promise { const editor = window.activeTextEditor; - void (await commands.executeCommand(BuiltInCommands.CloseActiveEditor)); + void (await executeCoreCommand(CoreCommands.CloseActiveEditor)); if (editor !== window.activeTextEditor) { return window.activeTextEditor; @@ -118,7 +118,7 @@ export class CloseUnchangedFilesCommand extends Command { private async nextEditor(timeout: number = 500): Promise { const editor = window.activeTextEditor; - void (await commands.executeCommand(BuiltInCommands.NextEditor)); + void (await executeCoreCommand(CoreCommands.NextEditor)); if (editor !== window.activeTextEditor) { return window.activeTextEditor; diff --git a/src/commands/common.ts b/src/commands/common.ts index 74b8bed1a1508..61cbbd748f34b 100644 --- a/src/commands/common.ts +++ b/src/commands/common.ts @@ -14,7 +14,7 @@ import { workspace, } from 'vscode'; import type { Action, ActionContext } from '../api/gitlens'; -import { BuiltInCommands, ImageMimetypes, Schemes } from '../constants'; +import { CoreCommands, CoreGitCommands, ImageMimetypes, Schemes } from '../constants'; import { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { @@ -183,6 +183,7 @@ export const enum Commands { ToggleLineBlame = 'gitlens.toggleLineBlame', ToggleReviewMode = 'gitlens.toggleReviewMode', ToggleZenMode = 'gitlens.toggleZenMode', + ViewsCopy = 'gitlens.views.copy', ViewsOpenDirectoryDiff = 'gitlens.views.openDirectoryDiff', ViewsOpenDirectoryDiffWithWorking = 'gitlens.views.openDirectoryDiffWithWorking', @@ -208,8 +209,45 @@ export function getMarkdownActionCommand(action: Action }); } -export function executeCommand(command: Commands, args: T) { - return commands.executeCommand(command, args); +type SupportedCommands = Commands | `gitlens.views.${string}.focus` | `gitlens.views.${string}.resetViewLocation`; + +export function executeCommand(command: SupportedCommands): Thenable; +export function executeCommand(command: SupportedCommands, arg: T): Thenable; +export function executeCommand( + command: SupportedCommands, + ...args: T +): Thenable; +export function executeCommand( + command: SupportedCommands, + ...args: T +): Thenable { + return commands.executeCommand(command, args); +} + +export function executeCoreCommand(command: CoreCommands): Thenable; +export function executeCoreCommand(command: CoreCommands, arg: T): Thenable; +export function executeCoreCommand( + command: CoreCommands, + ...args: T +): Thenable; +export function executeCoreCommand( + command: CoreCommands, + ...args: T +): Thenable { + return commands.executeCommand(command, ...args); +} + +export function executeCoreGitCommand(command: CoreGitCommands): Thenable; +export function executeCoreGitCommand(command: CoreGitCommands, arg: T): Thenable; +export function executeCoreGitCommand( + command: CoreGitCommands, + ...args: T +): Thenable; +export function executeCoreGitCommand( + command: CoreGitCommands, + ...args: T +): Thenable { + return commands.executeCommand(command, ...args); } export function executeEditorCommand(command: Commands, uri: Uri | undefined, args: T) { @@ -700,7 +738,7 @@ export function findOrOpenEditors(uris: Uri[]): void { } for (const uri of normalizedUris.values()) { - void commands.executeCommand(BuiltInCommands.Open, uri, { background: true, preview: false }); + void executeCoreCommand(CoreCommands.Open, uri, { background: true, preview: false }); } } @@ -715,7 +753,7 @@ export async function openEditor( } if (uri.scheme === Schemes.GitLens && ImageMimetypes[extname(uri.fsPath)]) { - await commands.executeCommand(BuiltInCommands.Open, uri); + await executeCoreCommand(CoreCommands.Open, uri); return undefined; } @@ -730,7 +768,7 @@ export async function openEditor( } catch (ex) { const msg: string = ex?.toString() ?? ''; if (msg.includes('File seems to be binary and cannot be opened as text')) { - await commands.executeCommand(BuiltInCommands.Open, uri); + await executeCoreCommand(CoreCommands.Open, uri); return undefined; } @@ -757,7 +795,7 @@ export function openWorkspace( return void workspace.updateWorkspaceFolders(count, 0, { uri: uri, name: options?.name }); } - return void commands.executeCommand(BuiltInCommands.OpenFolder, uri, { + return void executeCoreCommand(CoreCommands.OpenFolder, uri, { forceNewWindow: options?.location === OpenWorkspaceLocation.NewWindow, }); } diff --git a/src/commands/diffWith.ts b/src/commands/diffWith.ts index 895902029b6f1..d79486071b358 100644 --- a/src/commands/diffWith.ts +++ b/src/commands/diffWith.ts @@ -1,11 +1,11 @@ -import { commands, Range, TextDocumentShowOptions, Uri, ViewColumn } from 'vscode'; -import { BuiltInCommands, GlyphChars } from '../constants'; +import { Range, TextDocumentShowOptions, Uri, ViewColumn } from 'vscode'; +import { CoreCommands, GlyphChars } from '../constants'; import type { Container } from '../container'; import { GitCommit, GitRevision } from '../git/models'; import { Logger } from '../logger'; import { Messages } from '../messages'; import { basename } from '../system/path'; -import { command, Command, Commands } from './common'; +import { command, Command, Commands, executeCoreCommand } from './common'; export interface DiffWithCommandArgsRevision { sha: string; @@ -174,8 +174,8 @@ export class DiffWithCommand extends Command { args.showOptions.selection = new Range(args.line, 0, args.line, 0); } - void (await commands.executeCommand( - BuiltInCommands.Diff, + void (await executeCoreCommand( + CoreCommands.Diff, lhs ?? this.container.git.getRevisionUri(GitRevision.deletedOrMissing, args.lhs.uri.fsPath, args.repoPath), rhs ?? diff --git a/src/commands/git/coauthors.ts b/src/commands/git/coauthors.ts index 8cbd2466837b0..efc4f1ff51b83 100644 --- a/src/commands/git/coauthors.ts +++ b/src/commands/git/coauthors.ts @@ -1,8 +1,9 @@ -import { commands } from 'vscode'; +import { CoreCommands } from '../../constants'; import { Container } from '../../container'; import { GitContributor, Repository } from '../../git/models'; import { normalizePath } from '../../system/path'; import { ViewsWithRepositoryFolders } from '../../views/viewBase'; +import { executeCoreCommand } from '../common'; import { PartialStepState, pickContributorsStep, @@ -90,7 +91,7 @@ export class CoAuthorsGitCommand extends QuickCommand { } repo.inputBox.value = message; - void (await commands.executeCommand('workbench.view.scm')); + void (await executeCoreCommand(CoreCommands.ShowSCM)); } protected async *steps(state: PartialStepState): StepGenerator { diff --git a/src/commands/git/push.ts b/src/commands/git/push.ts index 4818575f3fe97..d06204612451b 100644 --- a/src/commands/git/push.ts +++ b/src/commands/git/push.ts @@ -1,5 +1,5 @@ import { configuration } from '../../configuration'; -import { BuiltInGitConfiguration, GlyphChars } from '../../constants'; +import { CoreGitConfiguration, GlyphChars } from '../../constants'; import { Container } from '../../container'; import { GitBranch, GitBranchReference, GitReference, Repository } from '../../git/models'; import { Directive, DirectiveQuickPickItem, FlagsQuickPickItem } from '../../quickpicks'; @@ -151,7 +151,7 @@ export class PushGitCommand extends QuickCommand { } private async *confirmStep(state: PushStepState, context: Context): AsyncStepResultGenerator { - const useForceWithLease = configuration.getAny(BuiltInGitConfiguration.UseForcePushWithLease) ?? false; + const useForceWithLease = configuration.getAny(CoreGitConfiguration.UseForcePushWithLease) ?? false; let step: QuickPickStep>; diff --git a/src/commands/refreshHover.ts b/src/commands/refreshHover.ts index cb2988e259103..19f3ef3a512a0 100644 --- a/src/commands/refreshHover.ts +++ b/src/commands/refreshHover.ts @@ -1,6 +1,6 @@ -import { commands } from 'vscode'; +import { CoreCommands } from '../constants'; import type { Container } from '../container'; -import { command, Command, Commands } from './common'; +import { command, Command, Commands, executeCoreCommand } from './common'; @command() export class RefreshHoverCommand extends Command { @@ -10,6 +10,6 @@ export class RefreshHoverCommand extends Command { async execute() { // TODO@eamodio figure out how to really refresh/update a hover - await commands.executeCommand('editor.action.showHover'); + await executeCoreCommand(CoreCommands.EditorShowHover); } } diff --git a/src/commands/setViewsLayout.ts b/src/commands/setViewsLayout.ts index cb5979e88d702..9140d3e8d1a58 100644 --- a/src/commands/setViewsLayout.ts +++ b/src/commands/setViewsLayout.ts @@ -1,7 +1,8 @@ -import { commands, window } from 'vscode'; +import { window } from 'vscode'; import { viewsConfigKeys } from '../configuration'; +import { CoreCommands } from '../constants'; import type { Container } from '../container'; -import { command, Command, Commands } from './common'; +import { command, Command, Commands, executeCommand, executeCoreCommand } from './common'; enum ViewsLayout { GitLens = 'gitlens', @@ -51,7 +52,7 @@ export class SetViewsLayoutCommand extends Command { // Because of https://github.com/microsoft/vscode/issues/105774, run the command twice which seems to fix things let count = 0; while (count++ < 2) { - void (await commands.executeCommand('vscode.moveViews', { + void (await executeCoreCommand(CoreCommands.MoveViews, { viewIds: viewsConfigKeys.map(view => `gitlens.views.${view}`), destinationId: 'workbench.view.extension.gitlens', })); @@ -64,14 +65,14 @@ export class SetViewsLayoutCommand extends Command { // Because of https://github.com/microsoft/vscode/issues/105774, run the command twice which seems to fix things let count = 0; while (count++ < 2) { - void (await commands.executeCommand('vscode.moveViews', { + void (await executeCoreCommand(CoreCommands.MoveViews, { viewIds: viewsConfigKeys.map(view => `gitlens.views.${view}`), destinationId: 'workbench.view.scm', })); } } catch { for (const view of viewsConfigKeys) { - void (await commands.executeCommand(`gitlens.views.${view}.resetViewLocation`)); + void (await executeCommand(`gitlens.views.${view}.resetViewLocation`)); } } diff --git a/src/commands/showView.ts b/src/commands/showView.ts index de51f0aba1509..2b5c2dd3ab6b2 100644 --- a/src/commands/showView.ts +++ b/src/commands/showView.ts @@ -1,8 +1,7 @@ -import { commands } from 'vscode'; import type { Container } from '../container'; import { ContextKeys, setContext } from '../context'; import { SyncedState } from '../storage'; -import { command, Command, CommandContext, Commands } from './common'; +import { command, Command, CommandContext, Commands, executeCommand } from './common'; @command() export class ShowViewCommand extends Command { @@ -51,7 +50,7 @@ export class ShowViewCommand extends Command { case Commands.ShowWelcomeView: await setContext(ContextKeys.ViewsWelcomeVisible, true); void this.container.storage.store(SyncedState.WelcomeViewVisible, true); - void (await commands.executeCommand('gitlens.views.welcome.focus')); + void (await executeCommand('gitlens.views.welcome.focus')); } return Promise.resolve(undefined); diff --git a/src/constants.ts b/src/constants.ts index 5aae20562455d..d85c13f21401d 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -44,6 +44,46 @@ export const enum Colors { UnpulledChangesIconColor = 'gitlens.unpulledChangesIconColor', } +export const enum CoreCommands { + CloseActiveEditor = 'workbench.action.closeActiveEditor', + CloseAllEditors = 'workbench.action.closeAllEditors', + CursorMove = 'cursorMove', + Diff = 'vscode.diff', + EditorScroll = 'editorScroll', + EditorShowHover = 'editor.action.showHover', + ExecuteDocumentSymbolProvider = 'vscode.executeDocumentSymbolProvider', + ExecuteCodeLensProvider = 'vscode.executeCodeLensProvider', + FocusFilesExplorer = 'workbench.files.action.focusFilesExplorer', + InstallExtension = 'workbench.extensions.installExtension', + MoveViews = 'vscode.moveViews', + Open = 'vscode.open', + OpenFolder = 'vscode.openFolder', + OpenInTerminal = 'openInTerminal', + OpenWith = 'vscode.openWith', + NextEditor = 'workbench.action.nextEditor', + PreviewHtml = 'vscode.previewHtml', + RevealLine = 'revealLine', + SetContext = 'setContext', + ShowExplorer = 'workbench.view.explorer', + ShowReferences = 'editor.action.showReferences', + ShowSCM = 'workbench.view.scm', +} + +export const enum CoreGitCommands { + Publish = 'git.publish', + Pull = 'git.pull', + PullRebase = 'git.pullRebase', + Push = 'git.push', + PushForce = 'git.pushForce', + UndoCommit = 'git.undoCommit', +} + +export const enum CoreGitConfiguration { + AutoRepositoryDetection = 'git.autoRepositoryDetection', + FetchOnPull = 'git.fetchOnPull', + UseForcePushWithLease = 'git.useForcePushWithLease', +} + export const enum GlyphChars { AngleBracketLeftHeavy = '\u2770', AngleBracketRightHeavy = '\u2771', @@ -103,40 +143,3 @@ export const enum Schemes { VslsScc = 'vsls-scc', Virtual = 'vscode-vfs', } - -export const enum BuiltInCommands { - CloseActiveEditor = 'workbench.action.closeActiveEditor', - CloseAllEditors = 'workbench.action.closeAllEditors', - CursorMove = 'cursorMove', - Diff = 'vscode.diff', - EditorScroll = 'editorScroll', - ExecuteDocumentSymbolProvider = 'vscode.executeDocumentSymbolProvider', - ExecuteCodeLensProvider = 'vscode.executeCodeLensProvider', - FocusFilesExplorer = 'workbench.files.action.focusFilesExplorer', - InstallExtension = 'workbench.extensions.installExtension', - Open = 'vscode.open', - OpenFolder = 'vscode.openFolder', - OpenInTerminal = 'openInTerminal', - OpenWith = 'vscode.openWith', - NextEditor = 'workbench.action.nextEditor', - PreviewHtml = 'vscode.previewHtml', - RevealLine = 'revealLine', - SetContext = 'setContext', - ShowExplorerActivity = 'workbench.view.explorer', - ShowReferences = 'editor.action.showReferences', -} - -export const enum BuiltInGitCommands { - Publish = 'git.publish', - Pull = 'git.pull', - PullRebase = 'git.pullRebase', - Push = 'git.push', - PushForce = 'git.pushForce', - UndoCommit = 'git.undoCommit', -} - -export const enum BuiltInGitConfiguration { - AutoRepositoryDetection = 'git.autoRepositoryDetection', - FetchOnPull = 'git.fetchOnPull', - UseForcePushWithLease = 'git.useForcePushWithLease', -} diff --git a/src/container.ts b/src/container.ts index 8fa93a7f71df4..2191623d6857f 100644 --- a/src/container.ts +++ b/src/container.ts @@ -1,4 +1,4 @@ -import { commands, ConfigurationChangeEvent, ConfigurationScope, Event, EventEmitter, ExtensionContext } from 'vscode'; +import { ConfigurationChangeEvent, ConfigurationScope, Event, EventEmitter, ExtensionContext } from 'vscode'; import { getSupportedGitProviders } from '@env/providers'; import { Autolinks } from './annotations/autolinks'; import { FileAnnotationController } from './annotations/fileAnnotationController'; @@ -6,7 +6,7 @@ import { LineAnnotationController } from './annotations/lineAnnotationController import { ActionRunners } from './api/actionRunners'; import { resetAvatarCache } from './avatars'; import { GitCodeLensController } from './codelens/codeLensController'; -import { Commands, ToggleFileAnnotationCommandArgs } from './commands'; +import { Commands, executeCommand, ToggleFileAnnotationCommandArgs } from './commands'; import { AnnotationsToggleMode, Config, @@ -465,7 +465,7 @@ export class Container { if (mode == null) return config; if (mode.annotations != null) { - let command: string | undefined; + let command: Commands | undefined; switch (mode.annotations) { case 'blame': config.blame.toggleMode = AnnotationsToggleMode.Window; @@ -487,7 +487,7 @@ export class Container { on: true, }; // Make sure to delay the execution by a bit so that the configuration changes get propegated first - setTimeout(() => commands.executeCommand(command!, commandArgs), 50); + setTimeout(() => executeCommand(command!, commandArgs), 50); } } diff --git a/src/context.ts b/src/context.ts index 55e1c7ba329cf..54e0031ef5fc2 100644 --- a/src/context.ts +++ b/src/context.ts @@ -1,5 +1,5 @@ import { commands } from 'vscode'; -import { BuiltInCommands } from './constants'; +import { CoreCommands } from './constants'; export const enum ContextKeys { ActionPrefix = 'gitlens:action:', @@ -38,5 +38,5 @@ export async function setContext( value: unknown, ): Promise { // contextStorage.set(key, value); - void (await commands.executeCommand(BuiltInCommands.SetContext, key, value)); + void (await commands.executeCommand(CoreCommands.SetContext, key, value)); } diff --git a/src/env/node/git/localGitProvider.ts b/src/env/node/git/localGitProvider.ts index 17a7de2845293..02fc4e8810769 100644 --- a/src/env/node/git/localGitProvider.ts +++ b/src/env/node/git/localGitProvider.ts @@ -23,7 +23,7 @@ import type { GitExtension, } from '../../../@types/vscode.git'; import { configuration } from '../../../configuration'; -import { BuiltInGitConfiguration, GlyphChars, Schemes } from '../../../constants'; +import { CoreGitConfiguration, GlyphChars, Schemes } from '../../../constants'; import type { Container } from '../../../container'; import { StashApplyError, StashApplyErrorReason } from '../../../git/errors'; import { @@ -323,7 +323,7 @@ export class LocalGitProvider implements GitProvider, Disposable { const autoRepositoryDetection = configuration.getAny( - BuiltInGitConfiguration.AutoRepositoryDetection, + CoreGitConfiguration.AutoRepositoryDetection, ) ?? true; if (autoRepositoryDetection === false || autoRepositoryDetection === 'openEditors') return []; diff --git a/src/extension.ts b/src/extension.ts index 1be98b06d7e62..c1c0884cdc98f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,4 +1,4 @@ -import { version as codeVersion, commands, env, ExtensionContext, extensions, window, workspace } from 'vscode'; +import { version as codeVersion, env, ExtensionContext, extensions, window, workspace } from 'vscode'; import { isWeb } from '@env/platform'; import { Api } from './api/api'; import type { CreatePullRequestActionContext, GitLensApi, OpenPullRequestActionContext } from './api/gitlens'; @@ -122,7 +122,7 @@ export function activate(context: ExtensionContext): Promise( - BuiltInGitConfiguration.AutoRepositoryDetection, + CoreGitConfiguration.AutoRepositoryDetection, ) ?? true; if (autoRepositoryDetection !== false && autoRepositoryDetection !== 'openEditors') { void this.discoverRepositories(e.added); @@ -398,7 +398,7 @@ export class GitProviderService implements Disposable { if (workspaceFolders?.length) { const autoRepositoryDetection = configuration.getAny( - BuiltInGitConfiguration.AutoRepositoryDetection, + CoreGitConfiguration.AutoRepositoryDetection, ) ?? true; if (autoRepositoryDetection !== false && autoRepositoryDetection !== 'openEditors') { diff --git a/src/git/models/repository.ts b/src/git/models/repository.ts index 475d11f02af4b..6d5775b921eee 100644 --- a/src/git/models/repository.ts +++ b/src/git/models/repository.ts @@ -1,5 +1,4 @@ import { - commands, ConfigurationChangeEvent, Disposable, Event, @@ -12,9 +11,9 @@ import { WorkspaceFolder, } from 'vscode'; import type { CreatePullRequestActionContext } from '../../api/gitlens'; -import { executeActionCommand } from '../../commands'; +import { executeActionCommand, executeCoreGitCommand } from '../../commands'; import { configuration } from '../../configuration'; -import { BuiltInGitCommands, BuiltInGitConfiguration, Schemes } from '../../constants'; +import { CoreGitCommands, CoreGitConfiguration, Schemes } from '../../constants'; import { Container } from '../../container'; import { Logger } from '../../logger'; import { Messages } from '../../messages'; @@ -643,11 +642,11 @@ export class Repository implements Disposable { try { const upstream = await this.hasUpstreamBranch(); if (upstream) { - void (await commands.executeCommand( - options.rebase ? BuiltInGitCommands.PullRebase : BuiltInGitCommands.Pull, + void (await executeCoreGitCommand( + options.rebase ? CoreGitCommands.PullRebase : CoreGitCommands.Pull, this.path, )); - } else if (configuration.getAny(BuiltInGitConfiguration.FetchOnPull, Uri.file(this.path))) { + } else if (configuration.getAny(CoreGitConfiguration.FetchOnPull, Uri.file(this.path))) { void (await this.container.git.fetch(this.path)); } @@ -738,8 +737,8 @@ export class Repository implements Disposable { const currentBranch = await this.getBranch(); if (branch.id === currentBranch?.id) { - void (await commands.executeCommand( - options.force ? BuiltInGitCommands.PushForce : BuiltInGitCommands.Push, + void (await executeCoreGitCommand( + options.force ? CoreGitCommands.PushForce : CoreGitCommands.Push, this.path, )); } else { @@ -755,8 +754,8 @@ export class Repository implements Disposable { await repo?.push(branch.getRemoteName(), `${options.reference.ref}:${branch.getNameWithoutRemote()}`); } else { - void (await commands.executeCommand( - options.force ? BuiltInGitCommands.PushForce : BuiltInGitCommands.Push, + void (await executeCoreGitCommand( + options.force ? CoreGitCommands.PushForce : CoreGitCommands.Push, this.path, )); } diff --git a/src/hovers/hovers.ts b/src/hovers/hovers.ts index 1838df2d3fd5e..bdc63c35acc40 100644 --- a/src/hovers/hovers.ts +++ b/src/hovers/hovers.ts @@ -337,7 +337,7 @@ export namespace Hovers { // cc, // `${GlyphChars.Dot} ${count} issue/pull request queries completed; refreshing...`, // ); - // void commands.executeCommand('editor.action.showHover'); + // void executeCoreCommand(CoreCommands.EditorShowHover); // }); return autolinks; diff --git a/src/partners.ts b/src/partners.ts index 9f6aca2884008..56affea77ea90 100644 --- a/src/partners.ts +++ b/src/partners.ts @@ -1,7 +1,7 @@ -import { CancellationTokenSource, commands, Extension, ExtensionContext, extensions, Uri } from 'vscode'; +import { CancellationTokenSource, Extension, ExtensionContext, extensions, Uri } from 'vscode'; import type { ActionContext, HoverCommandsActionContext } from './api/gitlens'; -import { Commands, executeCommand, InviteToLiveShareCommandArgs } from './commands'; -import { BuiltInCommands } from './constants'; +import { Commands, executeCommand, executeCoreCommand, InviteToLiveShareCommandArgs } from './commands'; +import { CoreCommands } from './constants'; import { Container } from './container'; export async function installExtension( @@ -33,7 +33,7 @@ export async function installExtension( }); }); - await commands.executeCommand(BuiltInCommands.InstallExtension, vsix ?? extensionId); + await executeCoreCommand(CoreCommands.InstallExtension, vsix ?? extensionId); // Wait for extension activation until timeout expires timer = setTimeout(() => { timer = undefined; diff --git a/src/quickpicks/commitQuickPickItems.ts b/src/quickpicks/commitQuickPickItems.ts index f83ce8f138044..4b7ee9ec73ea4 100644 --- a/src/quickpicks/commitQuickPickItems.ts +++ b/src/quickpicks/commitQuickPickItems.ts @@ -89,7 +89,7 @@ export class CommitFileQuickPickItem extends CommandQuickPickItem { // commit: fileCommit, // showOptions: options, // }; - // void (await commands.executeCommand(Commands.DiffWithPrevious, fileCommit.toGitUri(), commandArgs)); + // void (await executeCommand(Commands.DiffWithPrevious, fileCommit.toGitUri(), commandArgs)); } } diff --git a/src/views/branchesView.ts b/src/views/branchesView.ts index 7a7d8557a60cd..e82013c0e229c 100644 --- a/src/views/branchesView.ts +++ b/src/views/branchesView.ts @@ -8,6 +8,7 @@ import { TreeItemCollapsibleState, window, } from 'vscode'; +import { Commands, executeCommand } from '../commands'; import { BranchesViewConfig, configuration, @@ -128,7 +129,7 @@ export class BranchesView extends ViewBase return [ commands.registerCommand( this.getQualifiedCommand('copy'), - () => commands.executeCommand('gitlens.views.copy', this.selection), + () => executeCommand(Commands.ViewsCopy, this.selection), this, ), commands.registerCommand( diff --git a/src/views/commitsView.ts b/src/views/commitsView.ts index acd9dcdb73ef6..508d1fbc1f34d 100644 --- a/src/views/commitsView.ts +++ b/src/views/commitsView.ts @@ -8,6 +8,7 @@ import { TreeItemCollapsibleState, window, } from 'vscode'; +import { Commands, executeCommand } from '../commands'; import { CommitsViewConfig, configuration, ViewFilesLayout, ViewShowBranchComparison } from '../configuration'; import { GlyphChars } from '../constants'; import { Container } from '../container'; @@ -196,7 +197,7 @@ export class CommitsView extends ViewBase { return [ commands.registerCommand( this.getQualifiedCommand('copy'), - () => commands.executeCommand('gitlens.views.copy', this.selection), + () => executeCommand(Commands.ViewsCopy, this.selection), this, ), commands.registerCommand( diff --git a/src/views/contributorsView.ts b/src/views/contributorsView.ts index ffc705ddcbf5f..7b0806349601a 100644 --- a/src/views/contributorsView.ts +++ b/src/views/contributorsView.ts @@ -9,6 +9,7 @@ import { window, } from 'vscode'; import { Avatars } from '../avatars'; +import { Commands, executeCommand } from '../commands'; import { configuration, ContributorsViewConfig, ViewFilesLayout } from '../configuration'; import { Container } from '../container'; import { GitUri } from '../git/gitUri'; @@ -135,7 +136,7 @@ export class ContributorsView extends ViewBase commands.executeCommand('gitlens.views.copy', this.selection), + () => executeCommand(Commands.ViewsCopy, this.selection), this, ), commands.registerCommand( diff --git a/src/views/fileHistoryView.ts b/src/views/fileHistoryView.ts index 4fb35d81a76b6..c3092ff4fda3a 100644 --- a/src/views/fileHistoryView.ts +++ b/src/views/fileHistoryView.ts @@ -1,4 +1,5 @@ import { commands, ConfigurationChangeEvent, Disposable } from 'vscode'; +import { Commands, executeCommand } from '../commands'; import { configuration, FileHistoryViewConfig } from '../configuration'; import { Container } from '../container'; import { ContextKeys, setContext } from '../context'; @@ -35,7 +36,7 @@ export class FileHistoryView extends ViewBase commands.executeCommand('gitlens.views.copy', this.selection), + () => executeCommand(Commands.ViewsCopy, this.selection), this, ), commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this), diff --git a/src/views/lineHistoryView.ts b/src/views/lineHistoryView.ts index a4179c0c20f21..f7fcef53ad9d2 100644 --- a/src/views/lineHistoryView.ts +++ b/src/views/lineHistoryView.ts @@ -1,4 +1,5 @@ import { commands, ConfigurationChangeEvent, Disposable } from 'vscode'; +import { Commands, executeCommand } from '../commands'; import { configuration, LineHistoryViewConfig } from '../configuration'; import { Container } from '../container'; import { ContextKeys, setContext } from '../context'; @@ -30,7 +31,7 @@ export class LineHistoryView extends ViewBase commands.executeCommand('gitlens.views.copy', this.selection), + () => executeCommand(Commands.ViewsCopy, this.selection), this, ), commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this), diff --git a/src/views/nodes/mergeConflictCurrentChangesNode.ts b/src/views/nodes/mergeConflictCurrentChangesNode.ts index 670c8d42ed7db..3836c8d7acfc4 100644 --- a/src/views/nodes/mergeConflictCurrentChangesNode.ts +++ b/src/views/nodes/mergeConflictCurrentChangesNode.ts @@ -1,6 +1,6 @@ import { Command, MarkdownString, ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode'; import { Commands, DiffWithCommandArgs } from '../../commands'; -import { BuiltInCommands, GlyphChars } from '../../constants'; +import { CoreCommands, GlyphChars } from '../../constants'; import { CommitFormatter } from '../../git/formatters'; import { GitUri } from '../../git/gitUri'; import { GitFile, GitMergeStatus, GitRebaseStatus, GitReference } from '../../git/models'; @@ -69,7 +69,7 @@ export class MergeConflictCurrentChangesNode extends ViewNode implements override getCommand(): Command | undefined { return { title: 'Open File', - command: BuiltInCommands.Open, + command: CoreCommands.Open, arguments: [ this.view.container.git.getAbsoluteUri(this.file.path, this.repoPath), { diff --git a/src/views/nodes/mergeConflictIncomingChangesNode.ts b/src/views/nodes/mergeConflictIncomingChangesNode.ts index 15148802d514e..75ffc27445e62 100644 --- a/src/views/nodes/mergeConflictIncomingChangesNode.ts +++ b/src/views/nodes/mergeConflictIncomingChangesNode.ts @@ -1,6 +1,6 @@ import { Command, MarkdownString, ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode'; import { Commands, DiffWithCommandArgs } from '../../commands'; -import { BuiltInCommands, GlyphChars } from '../../constants'; +import { CoreCommands, GlyphChars } from '../../constants'; import { CommitFormatter } from '../../git/formatters'; import { GitUri } from '../../git/gitUri'; import { GitFile, GitMergeStatus, GitRebaseStatus, GitReference } from '../../git/models'; @@ -81,7 +81,7 @@ export class MergeConflictIncomingChangesNode extends ViewNode { async openEditor() { const rebaseTodoUri = Uri.joinPath(this.uri, '.git', 'rebase-merge', 'git-rebase-todo'); - await commands.executeCommand(BuiltInCommands.OpenWith, rebaseTodoUri, 'gitlens.rebase', { + await executeCoreCommand(CoreCommands.OpenWith, rebaseTodoUri, 'gitlens.rebase', { preview: false, }); } diff --git a/src/views/remotesView.ts b/src/views/remotesView.ts index c0901211fe37e..76e8b8c6bbdf6 100644 --- a/src/views/remotesView.ts +++ b/src/views/remotesView.ts @@ -8,6 +8,7 @@ import { TreeItemCollapsibleState, window, } from 'vscode'; +import { Commands, executeCommand } from '../commands'; import { configuration, RemotesViewConfig, ViewBranchesLayout, ViewFilesLayout } from '../configuration'; import { Container } from '../container'; import { GitUri } from '../git/gitUri'; @@ -122,7 +123,7 @@ export class RemotesView extends ViewBase { return [ commands.registerCommand( this.getQualifiedCommand('copy'), - () => commands.executeCommand('gitlens.views.copy', this.selection), + () => executeCommand(Commands.ViewsCopy, this.selection), this, ), commands.registerCommand( diff --git a/src/views/repositoriesView.ts b/src/views/repositoriesView.ts index 643b063750baf..93d6906e661ce 100644 --- a/src/views/repositoriesView.ts +++ b/src/views/repositoriesView.ts @@ -8,6 +8,7 @@ import { ProgressLocation, window, } from 'vscode'; +import { Commands, executeCommand } from '../commands'; import { configuration, RepositoriesViewConfig, @@ -71,7 +72,7 @@ export class RepositoriesView extends ViewBase commands.executeCommand('gitlens.views.copy', this.selection), + () => executeCommand(Commands.ViewsCopy, this.selection), this, ), commands.registerCommand( diff --git a/src/views/searchAndCompareView.ts b/src/views/searchAndCompareView.ts index de8dd7e640278..147bdeec1e990 100644 --- a/src/views/searchAndCompareView.ts +++ b/src/views/searchAndCompareView.ts @@ -1,5 +1,5 @@ import { commands, ConfigurationChangeEvent, Disposable, TreeItem, TreeItemCollapsibleState } from 'vscode'; -import { getRepoPathOrPrompt } from '../commands'; +import { Commands, executeCommand, getRepoPathOrPrompt } from '../commands'; import { configuration, SearchAndCompareViewConfig, ViewFilesLayout } from '../configuration'; import { Container } from '../container'; import { ContextKeys, setContext } from '../context'; @@ -274,7 +274,7 @@ export class SearchAndCompareView extends ViewBase this.clear(), this), commands.registerCommand( this.getQualifiedCommand('copy'), - () => commands.executeCommand('gitlens.views.copy', this.selection), + () => executeCommand(Commands.ViewsCopy, this.selection), this, ), commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this), diff --git a/src/views/stashesView.ts b/src/views/stashesView.ts index ea8d3f3da6ae2..6fbaec63bca1a 100644 --- a/src/views/stashesView.ts +++ b/src/views/stashesView.ts @@ -8,6 +8,7 @@ import { TreeItemCollapsibleState, window, } from 'vscode'; +import { Commands, executeCommand } from '../commands'; import { configuration, StashesViewConfig, ViewFilesLayout } from '../configuration'; import { Container } from '../container'; import { GitUri } from '../git/gitUri'; @@ -110,7 +111,7 @@ export class StashesView extends ViewBase { return [ commands.registerCommand( this.getQualifiedCommand('copy'), - () => commands.executeCommand('gitlens.views.copy', this.selection), + () => executeCommand(Commands.ViewsCopy, this.selection), this, ), commands.registerCommand( diff --git a/src/views/tagsView.ts b/src/views/tagsView.ts index fd0e850b22be1..d9ed9a8a73fb1 100644 --- a/src/views/tagsView.ts +++ b/src/views/tagsView.ts @@ -8,6 +8,7 @@ import { TreeItemCollapsibleState, window, } from 'vscode'; +import { Commands, executeCommand } from '../commands'; import { configuration, TagsViewConfig, ViewBranchesLayout, ViewFilesLayout } from '../configuration'; import { Container } from '../container'; import { GitUri } from '../git/gitUri'; @@ -110,7 +111,7 @@ export class TagsView extends ViewBase { return [ commands.registerCommand( this.getQualifiedCommand('copy'), - () => commands.executeCommand('gitlens.views.copy', this.selection), + () => executeCommand(Commands.ViewsCopy, this.selection), this, ), commands.registerCommand( diff --git a/src/views/viewBase.ts b/src/views/viewBase.ts index f2662808fb40d..96d6afe0072d7 100644 --- a/src/views/viewBase.ts +++ b/src/views/viewBase.ts @@ -1,6 +1,5 @@ import { CancellationToken, - commands, ConfigurationChangeEvent, Disposable, Event, @@ -14,6 +13,7 @@ import { TreeViewVisibilityChangeEvent, window, } from 'vscode'; +import { executeCommand } from '../commands'; import { BranchesViewConfig, CommitsViewConfig, @@ -103,7 +103,11 @@ export abstract class ViewBase< private readonly _lastKnownLimits = new Map(); - constructor(public readonly id: string, public readonly name: string, public readonly container: Container) { + constructor( + public readonly id: `gitlens.views.${string}`, + public readonly name: string, + public readonly container: Container, + ) { this.disposables.push(once(container.onReady)(this.onReady, this)); if (Logger.isDebugging || this.container.config.debug) { @@ -505,7 +509,7 @@ export abstract class ViewBase< @log() async show(options?: { preserveFocus?: boolean }) { try { - void (await commands.executeCommand(`${this.id}.focus`, options)); + void (await executeCommand(`${this.id}.focus`, options)); } catch (ex) { Logger.error(ex); } diff --git a/src/views/viewCommands.ts b/src/views/viewCommands.ts index 59a68a65dc6a5..35e0165c9dbb4 100644 --- a/src/views/viewCommands.ts +++ b/src/views/viewCommands.ts @@ -7,12 +7,14 @@ import { DiffWithWorkingCommandArgs, executeActionCommand, executeCommand, + executeCoreCommand, + executeCoreGitCommand, executeEditorCommand, GitActions, OpenFileAtRevisionCommandArgs, } from '../commands'; import { configuration, FileAnnotationType, ViewShowBranchComparison } from '../configuration'; -import { BuiltInCommands, BuiltInGitCommands } from '../constants'; +import { CoreCommands, CoreGitCommands } from '../constants'; import { Container } from '../container'; import { ContextKeys, setContext } from '../context'; import { GitUri } from '../git/gitUri'; @@ -460,7 +462,7 @@ export class ViewCommands { private openInTerminal(node: RepositoryNode | RepositoryFolderNode) { if (!(node instanceof RepositoryNode) && !(node instanceof RepositoryFolderNode)) return Promise.resolve(); - return commands.executeCommand(BuiltInCommands.OpenInTerminal, Uri.file(node.repo.path)); + return executeCoreCommand(CoreCommands.OpenInTerminal, Uri.file(node.repo.path)); } @debug() @@ -481,7 +483,7 @@ export class ViewCommands { @debug() private publishRepository(node: BranchNode | BranchTrackingStatusNode) { if (node instanceof BranchNode || node instanceof BranchTrackingStatusNode) { - return commands.executeCommand(BuiltInGitCommands.Publish, Uri.file(node.repoPath)); + return executeCoreGitCommand(CoreGitCommands.Publish, Uri.file(node.repoPath)); } return Promise.resolve(); } @@ -685,7 +687,7 @@ export class ViewCommands { return; } - await commands.executeCommand(BuiltInGitCommands.UndoCommit, node.repoPath); + await executeCoreGitCommand(CoreGitCommands.UndoCommit, node.repoPath); } @debug() @@ -969,7 +971,7 @@ export class ViewCommands { // }; // const uri = GitUri.fromFile(file, repoPath, ref); - // await commands.executeCommand(Commands.DiffWithWorking, uri, args); + // await executeCommand(Commands.DiffWithWorking, uri, args); // } } diff --git a/src/webviews/rebaseEditor.ts b/src/webviews/rebaseEditor.ts index 8adbe7e53c29c..e1eb23b421781 100644 --- a/src/webviews/rebaseEditor.ts +++ b/src/webviews/rebaseEditor.ts @@ -1,6 +1,5 @@ import { CancellationToken, - commands, ConfigurationTarget, CustomTextEditorProvider, Disposable, @@ -14,9 +13,9 @@ import { WorkspaceEdit, } from 'vscode'; import { getNonce } from '@env/crypto'; -import { ShowQuickCommitCommand } from '../commands'; +import { executeCoreCommand, ShowQuickCommitCommand } from '../commands'; import { configuration } from '../configuration'; -import { BuiltInCommands } from '../constants'; +import { CoreCommands } from '../constants'; import { Container } from '../container'; import { RepositoryChange, RepositoryChangeComparisonMode } from '../git/models'; import { Logger } from '../logger'; @@ -466,7 +465,7 @@ export class RebaseEditorProvider implements CustomTextEditorProvider, Disposabl void Messages.showRebaseSwitchToTextWarningMessage(); // Open the text version of the document - void commands.executeCommand(BuiltInCommands.Open, context.document.uri, { + void executeCoreCommand(CoreCommands.Open, context.document.uri, { override: false, preview: false, });