Browse Source

Consolidates executeCommand calls

main
Eric Amodio 2 years ago
parent
commit
94e1ae3622
37 changed files with 199 additions and 152 deletions
  1. +6
    -6
      src/codelens/codeLensProvider.ts
  2. +4
    -3
      src/commands/browseRepoAtRevision.ts
  3. +6
    -6
      src/commands/closeUnchangedFiles.ts
  4. +45
    -7
      src/commands/common.ts
  5. +5
    -5
      src/commands/diffWith.ts
  6. +3
    -2
      src/commands/git/coauthors.ts
  7. +2
    -2
      src/commands/git/push.ts
  8. +3
    -3
      src/commands/refreshHover.ts
  9. +6
    -5
      src/commands/setViewsLayout.ts
  10. +2
    -3
      src/commands/showView.ts
  11. +40
    -37
      src/constants.ts
  12. +4
    -4
      src/container.ts
  13. +2
    -2
      src/context.ts
  14. +2
    -2
      src/env/node/git/localGitProvider.ts
  15. +4
    -4
      src/extension.ts
  16. +3
    -3
      src/git/gitProviderService.ts
  17. +9
    -10
      src/git/models/repository.ts
  18. +1
    -1
      src/hovers/hovers.ts
  19. +4
    -4
      src/partners.ts
  20. +1
    -1
      src/quickpicks/commitQuickPickItems.ts
  21. +2
    -1
      src/views/branchesView.ts
  22. +2
    -1
      src/views/commitsView.ts
  23. +2
    -1
      src/views/contributorsView.ts
  24. +2
    -1
      src/views/fileHistoryView.ts
  25. +2
    -1
      src/views/lineHistoryView.ts
  26. +2
    -2
      src/views/nodes/mergeConflictCurrentChangesNode.ts
  27. +2
    -2
      src/views/nodes/mergeConflictFileNode.ts
  28. +2
    -2
      src/views/nodes/mergeConflictIncomingChangesNode.ts
  29. +4
    -13
      src/views/nodes/rebaseStatusNode.ts
  30. +2
    -1
      src/views/remotesView.ts
  31. +2
    -1
      src/views/repositoriesView.ts
  32. +2
    -2
      src/views/searchAndCompareView.ts
  33. +2
    -1
      src/views/stashesView.ts
  34. +2
    -1
      src/views/tagsView.ts
  35. +7
    -3
      src/views/viewBase.ts
  36. +7
    -5
      src/views/viewCommands.ts
  37. +3
    -4
      src/webviews/rebaseEditor.ts

+ 6
- 6
src/codelens/codeLensProvider.ts View File

@ -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<SymbolInformation[]>(
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<SymbolInformation[]>(
BuiltInCommands.ExecuteDocumentSymbolProvider,
symbols = await executeCoreCommand<[Uri], SymbolInformation[]>(
CoreCommands.ExecuteDocumentSymbolProvider,
document.uri,
);
}

+ 4
- 3
src/commands/browseRepoAtRevision.ts View File

@ -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');

+ 6
- 6
src/commands/closeUnchangedFiles.ts View File

@ -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<TextEditor | undefined> {
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<TextEditor | undefined> {
const editor = window.activeTextEditor;
void (await commands.executeCommand(BuiltInCommands.NextEditor));
void (await executeCoreCommand(CoreCommands.NextEditor));
if (editor !== window.activeTextEditor) {
return window.activeTextEditor;

+ 45
- 7
src/commands/common.ts View File

@ -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<T>(command: Commands, args: T) {
return commands.executeCommand(command, args);
type SupportedCommands = Commands | `gitlens.views.${string}.focus` | `gitlens.views.${string}.resetViewLocation`;
export function executeCommand<U = any>(command: SupportedCommands): Thenable<U>;
export function executeCommand<T = unknown, U = any>(command: SupportedCommands, arg: T): Thenable<U>;
export function executeCommand<T extends [...unknown[]] = [], U = any>(
command: SupportedCommands,
...args: T
): Thenable<U>;
export function executeCommand<T extends [...unknown[]] = [], U = any>(
command: SupportedCommands,
...args: T
): Thenable<U> {
return commands.executeCommand<U>(command, args);
}
export function executeCoreCommand<U = any>(command: CoreCommands): Thenable<U>;
export function executeCoreCommand<T = unknown, U = any>(command: CoreCommands, arg: T): Thenable<U>;
export function executeCoreCommand<T extends [...unknown[]] = [], U = any>(
command: CoreCommands,
...args: T
): Thenable<U>;
export function executeCoreCommand<T extends [...unknown[]] = [], U = any>(
command: CoreCommands,
...args: T
): Thenable<U> {
return commands.executeCommand<U>(command, ...args);
}
export function executeCoreGitCommand<U = any>(command: CoreGitCommands): Thenable<U>;
export function executeCoreGitCommand<T = unknown, U = any>(command: CoreGitCommands, arg: T): Thenable<U>;
export function executeCoreGitCommand<T extends [...unknown[]] = [], U = any>(
command: CoreGitCommands,
...args: T
): Thenable<U>;
export function executeCoreGitCommand<T extends [...unknown[]] = [], U = any>(
command: CoreGitCommands,
...args: T
): Thenable<U> {
return commands.executeCommand<U>(command, ...args);
}
export function executeEditorCommand<T>(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,
});
}

+ 5
- 5
src/commands/diffWith.ts View File

@ -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 ??

+ 3
- 2
src/commands/git/coauthors.ts View File

@ -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<State>): StepGenerator {

+ 2
- 2
src/commands/git/push.ts View File

@ -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<Flags[]> {
const useForceWithLease = configuration.getAny<boolean>(BuiltInGitConfiguration.UseForcePushWithLease) ?? false;
const useForceWithLease = configuration.getAny<boolean>(CoreGitConfiguration.UseForcePushWithLease) ?? false;
let step: QuickPickStep<FlagsQuickPickItem<Flags>>;

+ 3
- 3
src/commands/refreshHover.ts View File

@ -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);
}
}

+ 6
- 5
src/commands/setViewsLayout.ts View File

@ -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`));
}
}

+ 2
- 3
src/commands/showView.ts View File

@ -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);

+ 40
- 37
src/constants.ts View File

@ -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',
}

+ 4
- 4
src/container.ts View File

@ -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);
}
}

+ 2
- 2
src/context.ts View File

@ -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<void> {
// contextStorage.set(key, value);
void (await commands.executeCommand(BuiltInCommands.SetContext, key, value));
void (await commands.executeCommand(CoreCommands.SetContext, key, value));
}

+ 2
- 2
src/env/node/git/localGitProvider.ts View File

@ -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<boolean | 'subFolders' | 'openEditors'>(
BuiltInGitConfiguration.AutoRepositoryDetection,
CoreGitConfiguration.AutoRepositoryDetection,
) ?? true;
if (autoRepositoryDetection === false || autoRepositoryDetection === 'openEditors') return [];

+ 4
- 4
src/extension.ts View File

@ -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
if (cfg.outputLevel !== OutputLevel.Debug) return;
if (await Messages.showDebugLoggingWarningMessage()) {
void commands.executeCommand(Commands.DisableDebugLogging);
void executeCommand(Commands.DisableDebugLogging);
}
}, 60000);
}
@ -201,7 +201,7 @@ async function showWelcomeOrWhatsNew(container: Container, version: string, prev
if (window.state.focused) {
await container.storage.delete(GlobalState.PendingWelcomeOnFocus);
await commands.executeCommand(Commands.ShowWelcomePage);
await executeCommand(Commands.ShowWelcomePage);
} else {
// Save pending on window getting focus
await container.storage.store(GlobalState.PendingWelcomeOnFocus, true);
@ -214,7 +214,7 @@ async function showWelcomeOrWhatsNew(container: Container, version: string, prev
if (container.storage.get(GlobalState.PendingWelcomeOnFocus) === true) {
void container.storage.delete(GlobalState.PendingWelcomeOnFocus);
if (container.config.showWelcomeOnInstall) {
void commands.executeCommand(Commands.ShowWelcomePage);
void executeCommand(Commands.ShowWelcomePage);
}
}
});

+ 3
- 3
src/git/gitProviderService.ts View File

@ -17,7 +17,7 @@ import {
} from 'vscode';
import { resetAvatarCache } from '../avatars';
import { configuration } from '../configuration';
import { BuiltInGitConfiguration, GlyphChars, Schemes } from '../constants';
import { CoreGitConfiguration, GlyphChars, Schemes } from '../constants';
import type { Container } from '../container';
import { ContextKeys, setContext } from '../context';
import { ProviderNotFoundError } from '../errors';
@ -209,7 +209,7 @@ export class GitProviderService implements Disposable {
if (e.added.length) {
const autoRepositoryDetection =
configuration.getAny<boolean | 'subFolders' | 'openEditors'>(
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<boolean | 'subFolders' | 'openEditors'>(
BuiltInGitConfiguration.AutoRepositoryDetection,
CoreGitConfiguration.AutoRepositoryDetection,
) ?? true;
if (autoRepositoryDetection !== false && autoRepositoryDetection !== 'openEditors') {

+ 9
- 10
src/git/models/repository.ts View File

@ -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<boolean>(BuiltInGitConfiguration.FetchOnPull, Uri.file(this.path))) {
} else if (configuration.getAny<boolean>(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,
));
}

+ 1
- 1
src/hovers/hovers.ts View File

@ -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;

+ 4
- 4
src/partners.ts View File

@ -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<T>(
@ -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;

+ 1
- 1
src/quickpicks/commitQuickPickItems.ts View File

@ -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));
}
}

+ 2
- 1
src/views/branchesView.ts View File

@ -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(

+ 2
- 1
src/views/commitsView.ts View File

@ -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(

+ 2
- 1
src/views/contributorsView.ts View File

@ -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
return [
commands.registerCommand(
this.getQualifiedCommand('copy'),
() => commands.executeCommand('gitlens.views.copy', this.selection),
() => executeCommand(Commands.ViewsCopy, this.selection),
this,
),
commands.registerCommand(

+ 2
- 1
src/views/fileHistoryView.ts View File

@ -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
return [
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),

+ 2
- 1
src/views/lineHistoryView.ts View File

@ -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
return [
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),

+ 2
- 2
src/views/nodes/mergeConflictCurrentChangesNode.ts View File

@ -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
if (this.status.mergeBase == null) {
return {
title: 'Open Revision',
command: BuiltInCommands.Open,
command: CoreCommands.Open,
arguments: [this.view.container.git.getRevisionUri('HEAD', this.file.path, this.status.repoPath)],
};
}

+ 2
- 2
src/views/nodes/mergeConflictFileNode.ts View File

@ -1,5 +1,5 @@
import { Command, MarkdownString, ThemeIcon, TreeItem, TreeItemCollapsibleState, Uri } from 'vscode';
import { BuiltInCommands } from '../../constants';
import { CoreCommands } from '../../constants';
import { StatusFileFormatter } from '../../git/formatters';
import { GitUri } from '../../git/gitUri';
import { GitFile, GitMergeStatus, GitRebaseStatus } from '../../git/models';
@ -119,7 +119,7 @@ export class MergeConflictFileNode 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),
{

+ 2
- 2
src/views/nodes/mergeConflictIncomingChangesNode.ts View File

@ -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
if (this.status.mergeBase == null) {
return {
title: 'Open Revision',
command: BuiltInCommands.Open,
command: CoreCommands.Open,
arguments: [
this.view.container.git.getRevisionUri(this.status.HEAD.ref, this.file.path, this.status.repoPath),
],

+ 4
- 13
src/views/nodes/rebaseStatusNode.ts View File

@ -1,16 +1,7 @@
import {
Command,
commands,
MarkdownString,
ThemeColor,
ThemeIcon,
TreeItem,
TreeItemCollapsibleState,
Uri,
} from 'vscode';
import { Commands, DiffWithPreviousCommandArgs } from '../../commands';
import { Command, MarkdownString, ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState, Uri } from 'vscode';
import { Commands, DiffWithPreviousCommandArgs, executeCoreCommand } from '../../commands';
import { ViewFilesLayout } from '../../configuration';
import { BuiltInCommands } from '../../constants';
import { CoreCommands } from '../../constants';
import { CommitFormatter } from '../../git/formatters';
import { GitUri } from '../../git/gitUri';
import { GitBranch, GitCommit, GitRebaseStatus, GitReference, GitRevisionReference, GitStatus } from '../../git/models';
@ -121,7 +112,7 @@ export class RebaseStatusNode 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,
});
}

+ 2
- 1
src/views/remotesView.ts View File

@ -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(

+ 2
- 1
src/views/repositoriesView.ts View File

@ -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
return [
commands.registerCommand(
this.getQualifiedCommand('copy'),
() => commands.executeCommand('gitlens.views.copy', this.selection),
() => executeCommand(Commands.ViewsCopy, this.selection),
this,
),
commands.registerCommand(

+ 2
- 2
src/views/searchAndCompareView.ts View File

@ -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
commands.registerCommand(this.getQualifiedCommand('clear'), () => 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),

+ 2
- 1
src/views/stashesView.ts View File

@ -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(

+ 2
- 1
src/views/tagsView.ts View File

@ -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(

+ 7
- 3
src/views/viewBase.ts View File

@ -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<string, number | undefined>();
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);
}

+ 7
- 5
src/views/viewCommands.ts View File

@ -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);
// }
}

+ 3
- 4
src/webviews/rebaseEditor.ts View File

@ -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,
});

Loading…
Cancel
Save