Bladeren bron

Removes QuickCommand namespace

main
Eric Amodio 1 jaar geleden
bovenliggende
commit
c7f288b5e2
22 gewijzigde bestanden met toevoegingen van 317 en 263 verwijderingen
  1. +16
    -12
      src/commands/git/branch.ts
  2. +6
    -3
      src/commands/git/cherry-pick.ts
  3. +2
    -2
      src/commands/git/coauthors.ts
  4. +12
    -4
      src/commands/git/fetch.ts
  5. +2
    -2
      src/commands/git/log.ts
  6. +6
    -4
      src/commands/git/merge.ts
  7. +4
    -2
      src/commands/git/pull.ts
  8. +4
    -2
      src/commands/git/push.ts
  9. +6
    -4
      src/commands/git/rebase.ts
  10. +16
    -12
      src/commands/git/remote.ts
  11. +11
    -3
      src/commands/git/reset.ts
  12. +11
    -3
      src/commands/git/revert.ts
  13. +6
    -3
      src/commands/git/search.ts
  14. +4
    -4
      src/commands/git/show.ts
  15. +18
    -15
      src/commands/git/stash.ts
  16. +3
    -3
      src/commands/git/status.ts
  17. +4
    -2
      src/commands/git/switch.ts
  18. +18
    -14
      src/commands/git/tag.ts
  19. +21
    -17
      src/commands/git/worktree.ts
  20. +5
    -5
      src/commands/gitCommands.ts
  21. +59
    -62
      src/commands/quickCommand.steps.ts
  22. +83
    -85
      src/commands/quickCommand.ts

+ 16
- 12
src/commands/git/branch.ts Bestand weergeven

@ -19,6 +19,10 @@ import type {
} from '../quickCommand';
import {
appendReposToTitle,
canPickStepContinue,
createConfirmStep,
createPickStep,
endSteps,
inputBranchNameStep,
pickBranchesStep,
pickBranchOrTagStep,
@ -243,7 +247,7 @@ export class BranchGitCommand extends QuickCommand {
state.name = undefined!;
break;
default:
QuickCommand.endSteps(state);
endSteps(state);
break;
}
@ -257,7 +261,7 @@ export class BranchGitCommand extends QuickCommand {
}
private *pickSubcommandStep(state: PartialStepState<State>): StepResultGenerator<State['subcommand']> {
const step = QuickCommand.createPickStep<QuickPickItemOfT<State['subcommand']>>({
const step = createPickStep<QuickPickItemOfT<State['subcommand']>>({
title: this.title,
placeholder: `Choose a ${this.label} command`,
items: [
@ -283,7 +287,7 @@ export class BranchGitCommand extends QuickCommand {
buttons: [QuickInputButtons.Back],
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
private async *createCommandSteps(state: CreateStepState, context: Context): AsyncStepResultGenerator<void> {
@ -328,7 +332,7 @@ export class BranchGitCommand extends QuickCommand {
state.flags = result;
}
QuickCommand.endSteps(state);
endSteps(state);
if (state.flags.includes('--switch')) {
await state.repo.switch(state.reference.ref, { createBranch: state.name });
} else {
@ -341,7 +345,7 @@ export class BranchGitCommand extends QuickCommand {
state: CreateStepState<CreateState>,
context: Context,
): StepResultGenerator<CreateFlags[]> {
const step: QuickPickStep<FlagsQuickPickItem<CreateFlags>> = QuickCommand.createConfirmStep(
const step: QuickPickStep<FlagsQuickPickItem<CreateFlags>> = createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context),
[
createFlagsQuickPickItem<CreateFlags>(state.flags, [], {
@ -361,7 +365,7 @@ export class BranchGitCommand extends QuickCommand {
context,
);
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
private async *deleteCommandSteps(state: DeleteStepState, context: Context): AsyncStepResultGenerator<void> {
@ -404,7 +408,7 @@ export class BranchGitCommand extends QuickCommand {
state.flags = result;
QuickCommand.endSteps(state);
endSteps(state);
state.repo.branchDelete(state.references, {
force: state.flags.includes('--force'),
remote: state.flags.includes('--remotes'),
@ -455,13 +459,13 @@ export class BranchGitCommand extends QuickCommand {
}
}
const step: QuickPickStep<FlagsQuickPickItem<DeleteFlags>> = QuickCommand.createConfirmStep(
const step: QuickPickStep<FlagsQuickPickItem<DeleteFlags>> = createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context),
confirmations,
context,
);
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
private async *renameCommandSteps(state: RenameStepState, context: Context): AsyncStepResultGenerator<void> {
@ -500,7 +504,7 @@ export class BranchGitCommand extends QuickCommand {
state.flags = result;
QuickCommand.endSteps(state);
endSteps(state);
state.repo.branch(...state.flags, state.reference.ref, state.name);
}
}
@ -509,7 +513,7 @@ export class BranchGitCommand extends QuickCommand {
state: RenameStepState<RenameState>,
context: Context,
): StepResultGenerator<RenameFlags[]> {
const step: QuickPickStep<FlagsQuickPickItem<RenameFlags>> = QuickCommand.createConfirmStep(
const step: QuickPickStep<FlagsQuickPickItem<RenameFlags>> = createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context),
[
createFlagsQuickPickItem<RenameFlags>(state.flags, ['-m'], {
@ -520,6 +524,6 @@ export class BranchGitCommand extends QuickCommand {
context,
);
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
}

+ 6
- 3
src/commands/git/cherry-pick.ts Bestand weergeven

@ -16,6 +16,9 @@ import type {
} from '../quickCommand';
import {
appendReposToTitle,
canPickStepContinue,
createConfirmStep,
endSteps,
pickBranchOrTagStep,
pickCommitsStep,
pickRepositoryStep,
@ -203,7 +206,7 @@ export class CherryPickGitCommand extends QuickCommand {
state.flags = result;
}
QuickCommand.endSteps(state);
endSteps(state);
this.execute(state as CherryPickStepState<State<GitReference[]>>);
}
@ -211,7 +214,7 @@ export class CherryPickGitCommand extends QuickCommand {
}
private *confirmStep(state: CherryPickStepState, context: Context): StepResultGenerator<Flags[]> {
const step: QuickPickStep<FlagsQuickPickItem<Flags>> = QuickCommand.createConfirmStep(
const step: QuickPickStep<FlagsQuickPickItem<Flags>> = createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context),
[
createFlagsQuickPickItem<Flags>(state.flags, [], {
@ -238,6 +241,6 @@ export class CherryPickGitCommand extends QuickCommand {
context,
);
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
}

+ 2
- 2
src/commands/git/coauthors.ts Bestand weergeven

@ -6,7 +6,7 @@ import { executeCoreCommand } from '../../system/command';
import { normalizePath } from '../../system/path';
import type { ViewsWithRepositoryFolders } from '../../views/viewBase';
import type { PartialStepState, StepGenerator, StepState } from '../quickCommand';
import { pickContributorsStep, pickRepositoryStep, QuickCommand, StepResult } from '../quickCommand';
import { endSteps , pickContributorsStep, pickRepositoryStep, QuickCommand, StepResult } from '../quickCommand';
interface Context {
repos: Repository[];
@ -154,7 +154,7 @@ export class CoAuthorsGitCommand extends QuickCommand {
state.contributors = result;
}
QuickCommand.endSteps(state);
endSteps(state);
void this.execute(state as CoAuthorStepState);
}

+ 12
- 4
src/commands/git/fetch.ts Bestand weergeven

@ -17,7 +17,15 @@ import type {
StepSelection,
StepState,
} from '../quickCommand';
import { appendReposToTitle, pickRepositoriesStep, QuickCommand, StepResult } from '../quickCommand';
import {
appendReposToTitle,
canPickStepContinue,
createConfirmStep,
endSteps,
pickRepositoriesStep,
QuickCommand,
StepResult,
} from '../quickCommand';
interface Context {
repos: Repository[];
@ -122,7 +130,7 @@ export class FetchGitCommand extends QuickCommand {
state.flags = result;
}
QuickCommand.endSteps(state);
endSteps(state);
void this.execute(state as FetchStepState);
}
@ -156,7 +164,7 @@ export class FetchGitCommand extends QuickCommand {
? `$(repo) ${state.repos[0].formattedName}`
: `${state.repos.length} repositories`;
step = QuickCommand.createConfirmStep(
step = createConfirmStep(
appendReposToTitle(`Confirm ${this.title}`, state, context, lastFetchedOn),
[
createFlagsQuickPickItem<Flags>(state.flags, [], {
@ -184,6 +192,6 @@ export class FetchGitCommand extends QuickCommand {
}
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
}

+ 2
- 2
src/commands/git/log.ts Bestand weergeven

@ -10,7 +10,7 @@ import { pad } from '../../system/string';
import type { ViewsWithRepositoryFolders } from '../../views/viewBase';
import { getSteps } from '../gitCommands.utils';
import type { PartialStepState, StepGenerator } from '../quickCommand';
import { pickBranchOrTagStep, pickCommitStep, pickRepositoryStep, QuickCommand, StepResult } from '../quickCommand';
import { endSteps , pickBranchOrTagStep, pickCommitStep, pickRepositoryStep, QuickCommand, StepResult } from '../quickCommand';
interface Context {
repos: Repository[];
@ -213,7 +213,7 @@ export class LogGitCommand extends QuickCommand {
state.counter--;
if (result === StepResult.Break) {
QuickCommand.endSteps(state);
endSteps(state);
}
}

+ 6
- 4
src/commands/git/merge.ts Bestand weergeven

@ -4,7 +4,7 @@ import type { GitLog } from '../../git/models/log';
import { GitReference, GitRevision } from '../../git/models/reference';
import type { Repository } from '../../git/models/repository';
import type { DirectiveQuickPickItem } from '../../quickpicks/items/directive';
import { createDirectiveQuickPickItem , Directive } from '../../quickpicks/items/directive';
import { createDirectiveQuickPickItem, Directive } from '../../quickpicks/items/directive';
import type { FlagsQuickPickItem } from '../../quickpicks/items/flags';
import { createFlagsQuickPickItem } from '../../quickpicks/items/flags';
import { pluralize } from '../../system/string';
@ -19,6 +19,8 @@ import type {
} from '../quickCommand';
import {
appendReposToTitle,
canPickStepContinue,
endSteps,
pickBranchOrTagStep,
pickCommitStep,
pickRepositoryStep,
@ -200,7 +202,7 @@ export class MergeGitCommand extends QuickCommand {
state.flags = result;
QuickCommand.endSteps(state);
endSteps(state);
this.execute(state as MergeStepState);
}
@ -224,7 +226,7 @@ export class MergeGitCommand extends QuickCommand {
}),
);
const selection: StepSelection<typeof step> = yield step;
QuickCommand.canPickStepContinue(step, state, selection);
canPickStepContinue(step, state, selection);
return StepResult.Break;
}
@ -271,6 +273,6 @@ export class MergeGitCommand extends QuickCommand {
],
);
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
}

+ 4
- 2
src/commands/git/pull.ts Bestand weergeven

@ -21,6 +21,8 @@ import type {
} from '../quickCommand';
import {
appendReposToTitle,
canPickStepContinue,
endSteps,
pickRepositoriesStep,
QuickCommand,
QuickCommandButtons,
@ -135,7 +137,7 @@ export class PullGitCommand extends QuickCommand {
state.flags = result;
}
QuickCommand.endSteps(state);
endSteps(state);
void this.execute(state as PullStepState);
}
@ -246,6 +248,6 @@ export class PullGitCommand extends QuickCommand {
}
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
}

+ 4
- 2
src/commands/git/push.ts Bestand weergeven

@ -22,6 +22,8 @@ import type {
} from '../quickCommand';
import {
appendReposToTitle,
canPickStepContinue,
endSteps,
pickRepositoriesStep,
pickRepositoryStep,
QuickCommand,
@ -150,7 +152,7 @@ export class PushGitCommand extends QuickCommand {
state.flags = result;
}
QuickCommand.endSteps(state);
endSteps(state);
void this.execute(state as State<Repository[]>);
}
@ -410,6 +412,6 @@ export class PushGitCommand extends QuickCommand {
}
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
}

+ 6
- 4
src/commands/git/rebase.ts Bestand weergeven

@ -4,7 +4,7 @@ import type { GitLog } from '../../git/models/log';
import { GitReference, GitRevision } from '../../git/models/reference';
import type { Repository } from '../../git/models/repository';
import type { DirectiveQuickPickItem } from '../../quickpicks/items/directive';
import { createDirectiveQuickPickItem , Directive } from '../../quickpicks/items/directive';
import { createDirectiveQuickPickItem, Directive } from '../../quickpicks/items/directive';
import type { FlagsQuickPickItem } from '../../quickpicks/items/flags';
import { createFlagsQuickPickItem } from '../../quickpicks/items/flags';
import { pluralize } from '../../system/string';
@ -20,6 +20,8 @@ import type {
} from '../quickCommand';
import {
appendReposToTitle,
canPickStepContinue,
endSteps,
pickBranchOrTagStep,
pickCommitStep,
pickRepositoryStep,
@ -209,7 +211,7 @@ export class RebaseGitCommand extends QuickCommand {
state.flags = result;
QuickCommand.endSteps(state);
endSteps(state);
void this.execute(state as RebaseStepState);
}
@ -236,7 +238,7 @@ export class RebaseGitCommand extends QuickCommand {
}),
);
const selection: StepSelection<typeof step> = yield step;
QuickCommand.canPickStepContinue(step, state, selection);
canPickStepContinue(step, state, selection);
return StepResult.Break;
}
@ -260,6 +262,6 @@ export class RebaseGitCommand extends QuickCommand {
],
);
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
}

+ 16
- 12
src/commands/git/remote.ts Bestand weergeven

@ -21,6 +21,10 @@ import type {
} from '../quickCommand';
import {
appendReposToTitle,
canPickStepContinue,
createConfirmStep,
createPickStep,
endSteps,
inputRemoteNameStep,
inputRemoteUrlStep,
pickRemoteStep,
@ -233,7 +237,7 @@ export class RemoteGitCommand extends QuickCommand {
yield* this.removeCommandSteps(state, context);
break;
default:
QuickCommand.endSteps(state);
endSteps(state);
break;
}
@ -247,7 +251,7 @@ export class RemoteGitCommand extends QuickCommand {
}
private *pickSubcommandStep(state: PartialStepState<State>): StepResultGenerator<State['subcommand']> {
const step = QuickCommand.createPickStep<QuickPickItemOfT<State['subcommand']>>({
const step = createPickStep<QuickPickItemOfT<State['subcommand']>>({
title: this.title,
placeholder: `Choose a ${this.label} command`,
items: [
@ -273,7 +277,7 @@ export class RemoteGitCommand extends QuickCommand {
buttons: [QuickInputButtons.Back],
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
private async *addCommandSteps(state: AddStepState, context: Context): AsyncStepResultGenerator<void> {
@ -317,7 +321,7 @@ export class RemoteGitCommand extends QuickCommand {
state.flags = result;
}
QuickCommand.endSteps(state);
endSteps(state);
await state.repo.addRemote(state.name, state.url, state.flags.includes('-f') ? { fetch: true } : undefined);
if (state.reveal !== false) {
@ -330,7 +334,7 @@ export class RemoteGitCommand extends QuickCommand {
}
private *addCommandConfirmStep(state: AddStepState<AddState>, context: Context): StepResultGenerator<AddFlags[]> {
const step: QuickPickStep<FlagsQuickPickItem<AddFlags>> = QuickCommand.createConfirmStep(
const step: QuickPickStep<FlagsQuickPickItem<AddFlags>> = createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context),
[
createFlagsQuickPickItem<AddFlags>(state.flags, [], {
@ -346,7 +350,7 @@ export class RemoteGitCommand extends QuickCommand {
context,
);
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
private async *removeCommandSteps(state: RemoveStepState, context: Context): AsyncStepResultGenerator<void> {
@ -379,7 +383,7 @@ export class RemoteGitCommand extends QuickCommand {
const result = yield* this.removeCommandConfirmStep(state, context);
if (result === StepResult.Break) continue;
QuickCommand.endSteps(state);
endSteps(state);
try {
await state.repo.removeRemote(state.remote.name);
} catch (ex) {
@ -393,7 +397,7 @@ export class RemoteGitCommand extends QuickCommand {
state: RemoveStepState<ExcludeSome<RemoveState, 'remote', string>>,
context: Context,
): StepResultGenerator<void> {
const step: QuickPickStep<QuickPickItem> = QuickCommand.createConfirmStep(
const step: QuickPickStep<QuickPickItem> = createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context),
[
{
@ -404,7 +408,7 @@ export class RemoteGitCommand extends QuickCommand {
context,
);
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? undefined : StepResult.Break;
return canPickStepContinue(step, state, selection) ? undefined : StepResult.Break;
}
private async *pruneCommandSteps(state: PruneStepState, context: Context): AsyncStepResultGenerator<void> {
@ -435,7 +439,7 @@ export class RemoteGitCommand extends QuickCommand {
const result = yield* this.pruneCommandConfirmStep(state, context);
if (result === StepResult.Break) continue;
QuickCommand.endSteps(state);
endSteps(state);
void state.repo.pruneRemote(state.remote.name);
}
}
@ -444,7 +448,7 @@ export class RemoteGitCommand extends QuickCommand {
state: PruneStepState<ExcludeSome<PruneState, 'remote', string>>,
context: Context,
): StepResultGenerator<void> {
const step: QuickPickStep<QuickPickItem> = QuickCommand.createConfirmStep(
const step: QuickPickStep<QuickPickItem> = createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context),
[
{
@ -455,6 +459,6 @@ export class RemoteGitCommand extends QuickCommand {
context,
);
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? undefined : StepResult.Break;
return canPickStepContinue(step, state, selection) ? undefined : StepResult.Break;
}
}

+ 11
- 3
src/commands/git/reset.ts Bestand weergeven

@ -15,7 +15,15 @@ import type {
StepSelection,
StepState,
} from '../quickCommand';
import { appendReposToTitle, pickCommitStep, pickRepositoryStep, QuickCommand, StepResult } from '../quickCommand';
import {
appendReposToTitle,
canPickStepContinue,
endSteps,
pickCommitStep,
pickRepositoryStep,
QuickCommand,
StepResult,
} from '../quickCommand';
interface Context {
repos: Repository[];
@ -153,7 +161,7 @@ export class ResetGitCommand extends QuickCommand {
state.flags = result;
}
QuickCommand.endSteps(state);
endSteps(state);
this.execute(state as ResetStepState);
}
@ -187,6 +195,6 @@ export class ResetGitCommand extends QuickCommand {
],
);
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
}

+ 11
- 3
src/commands/git/revert.ts Bestand weergeven

@ -15,7 +15,15 @@ import type {
StepSelection,
StepState,
} from '../quickCommand';
import { appendReposToTitle, pickCommitsStep, pickRepositoryStep, QuickCommand, StepResult } from '../quickCommand';
import {
appendReposToTitle,
canPickStepContinue,
endSteps,
pickCommitsStep,
pickRepositoryStep,
QuickCommand,
StepResult,
} from '../quickCommand';
interface Context {
repos: Repository[];
@ -157,7 +165,7 @@ export class RevertGitCommand extends QuickCommand {
state.flags = result;
QuickCommand.endSteps(state);
endSteps(state);
this.execute(state as RevertStepState<State<GitRevisionReference[]>>);
}
@ -181,6 +189,6 @@ export class RevertGitCommand extends QuickCommand {
],
);
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
}

+ 6
- 3
src/commands/git/search.ts Bestand weergeven

@ -17,6 +17,9 @@ import { getSteps } from '../gitCommands.utils';
import type { PartialStepState, StepGenerator, StepResultGenerator, StepSelection, StepState } from '../quickCommand';
import {
appendReposToTitle,
canPickStepContinue,
createPickStep,
endSteps,
pickCommitStep,
pickRepositoryStep,
QuickCommand,
@ -266,7 +269,7 @@ export class SearchGitCommand extends QuickCommand {
state.counter--;
if (result === StepResult.Break) {
QuickCommand.endSteps(state);
endSteps(state);
}
}
@ -310,7 +313,7 @@ export class SearchGitCommand extends QuickCommand {
const matchAllButton = new QuickCommandButtons.MatchAllToggle(state.matchAll);
const matchRegexButton = new QuickCommandButtons.MatchRegexToggle(state.matchRegex);
const step = QuickCommand.createPickStep<QuickPickItemOfT<SearchOperators>>({
const step = createPickStep<QuickPickItemOfT<SearchOperators>>({
title: appendReposToTitle(context.title, state, context),
placeholder: 'e.g. "Updates dependencies" author:eamodio',
matchOnDescription: true,
@ -386,7 +389,7 @@ export class SearchGitCommand extends QuickCommand {
},
});
const selection: StepSelection<typeof step> = yield step;
if (!QuickCommand.canPickStepContinue(step, state, selection)) {
if (!canPickStepContinue(step, state, selection)) {
// Since we simulated a step above, we need to remove it here
state.counter--;
return StepResult.Break;

+ 4
- 4
src/commands/git/show.ts Bestand weergeven

@ -8,7 +8,7 @@ import { CommandQuickPickItem } from '../../quickpicks/items/common';
import { GitCommandQuickPickItem } from '../../quickpicks/items/gitCommands';
import type { ViewsWithRepositoryFolders } from '../../views/viewBase';
import type { PartialStepState, StepGenerator } from '../quickCommand';
import {
import { endSteps ,
pickCommitStep,
pickRepositoryStep,
QuickCommand,
@ -186,14 +186,14 @@ export class ShowGitCommand extends QuickCommand {
const r = yield* result.executeSteps(this.pickedVia);
state.counter--;
if (r === StepResult.Break) {
QuickCommand.endSteps(state);
endSteps(state);
}
continue;
}
if (result instanceof CommandQuickPickItem && !(result instanceof CommitFilesQuickPickItem)) {
QuickCommand.endSteps(state);
endSteps(state);
void result.execute();
break;
@ -236,7 +236,7 @@ export class ShowGitCommand extends QuickCommand {
}
if (result instanceof CommandQuickPickItem) {
QuickCommand.endSteps(state);
endSteps(state);
void result.execute();
break;

+ 18
- 15
src/commands/git/stash.ts Bestand weergeven

@ -29,6 +29,12 @@ import type {
} from '../quickCommand';
import {
appendReposToTitle,
canInputStepContinue,
canPickStepContinue,
canStepContinue,
createInputStep,
createPickStep,
endSteps,
pickRepositoryStep,
pickStashStep,
QuickCommand,
@ -219,7 +225,7 @@ export class StashGitCommand extends QuickCommand {
yield* this.pushCommandSteps(state as PushStepState, context);
break;
default:
QuickCommand.endSteps(state);
endSteps(state);
break;
}
@ -233,7 +239,7 @@ export class StashGitCommand extends QuickCommand {
}
private *pickSubcommandStep(state: PartialStepState<State>): StepResultGenerator<State['subcommand']> {
const step = QuickCommand.createPickStep<QuickPickItemOfT<State['subcommand']>>({
const step = createPickStep<QuickPickItemOfT<State['subcommand']>>({
title: this.title,
placeholder: `Choose a ${this.label} command`,
items: [
@ -273,7 +279,7 @@ export class StashGitCommand extends QuickCommand {
buttons: [QuickInputButtons.Back],
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
private async *applyOrPopCommandSteps(state: ApplyStepState | PopStepState, context: Context): StepGenerator {
@ -300,7 +306,7 @@ export class StashGitCommand extends QuickCommand {
state.subcommand = result;
}
QuickCommand.endSteps(state);
endSteps(state);
try {
await state.repo.stashApply(
@ -382,7 +388,7 @@ export class StashGitCommand extends QuickCommand {
},
);
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
private async *dropCommandSteps(state: DropStepState, context: Context): StepGenerator {
@ -403,7 +409,7 @@ export class StashGitCommand extends QuickCommand {
const result = yield* this.dropCommandConfirmStep(state, context);
if (result === StepResult.Break) continue;
QuickCommand.endSteps(state);
endSteps(state);
try {
// drop can only take a stash index, e.g. `stash@{1}`
await state.repo.stashDelete(`stash@{${state.reference.number}}`, state.reference.ref);
@ -446,7 +452,7 @@ export class StashGitCommand extends QuickCommand {
},
);
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? undefined : StepResult.Break;
return canPickStepContinue(step, state, selection) ? undefined : StepResult.Break;
}
private async *listCommandSteps(state: ListStepState, context: Context): StepGenerator {
@ -479,7 +485,7 @@ export class StashGitCommand extends QuickCommand {
);
state.counter--;
if (result === StepResult.Break) {
QuickCommand.endSteps(state);
endSteps(state);
}
}
}
@ -510,7 +516,7 @@ export class StashGitCommand extends QuickCommand {
state.flags = result;
}
QuickCommand.endSteps(state);
endSteps(state);
try {
await state.repo.stashSave(state.message, state.uris, {
includeUntracked: state.flags.includes('--include-untracked'),
@ -537,7 +543,7 @@ export class StashGitCommand extends QuickCommand {
state: PushStepState,
context: Context,
): AsyncStepResultGenerator<string> {
const step = QuickCommand.createInputStep({
const step = createInputStep({
title: appendReposToTitle(
context.title,
state,
@ -556,10 +562,7 @@ export class StashGitCommand extends QuickCommand {
});
const value: StepSelection<typeof step> = yield step;
if (
!QuickCommand.canStepContinue(step, state, value) ||
!(await QuickCommand.canInputStepContinue(step, state, value))
) {
if (!canStepContinue(step, state, value) || !(await canInputStepContinue(step, state, value))) {
return StepResult.Break;
}
@ -608,6 +611,6 @@ export class StashGitCommand extends QuickCommand {
{ placeholder: `Confirm ${context.title}` },
);
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
}

+ 3
- 3
src/commands/git/status.ts Bestand weergeven

@ -8,7 +8,7 @@ import { GitCommandQuickPickItem } from '../../quickpicks/items/gitCommands';
import { pad } from '../../system/string';
import type { ViewsWithRepositoryFolders } from '../../views/viewBase';
import type { PartialStepState, StepGenerator, StepState } from '../quickCommand';
import { pickRepositoryStep, QuickCommand, showRepositoryStatusStep, StepResult } from '../quickCommand';
import { endSteps, pickRepositoryStep, QuickCommand, showRepositoryStatusStep, StepResult } from '../quickCommand';
interface Context {
repos: Repository[];
@ -109,14 +109,14 @@ export class StatusGitCommand extends QuickCommand {
const r = yield* result.executeSteps(this.pickedVia);
state.counter--;
if (r === StepResult.Break) {
QuickCommand.endSteps(state);
endSteps(state);
}
continue;
}
if (result instanceof CommandQuickPickItem) {
QuickCommand.endSteps(state);
endSteps(state);
void result.execute();
break;

+ 4
- 2
src/commands/git/switch.ts Bestand weergeven

@ -16,6 +16,8 @@ import type {
} from '../quickCommand';
import {
appendReposToTitle,
canPickStepContinue,
endSteps,
inputBranchNameStep,
pickBranchOrTagStepMultiRepo,
pickRepositoriesStep,
@ -191,7 +193,7 @@ export class SwitchGitCommand extends QuickCommand {
}
}
QuickCommand.endSteps(state);
endSteps(state);
void this.execute(state as SwitchStepState);
}
@ -244,6 +246,6 @@ export class SwitchGitCommand extends QuickCommand {
{ placeholder: `Confirm ${context.title}` },
);
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
}

+ 18
- 14
src/commands/git/tag.ts Bestand weergeven

@ -20,6 +20,13 @@ import type {
} from '../quickCommand';
import {
appendReposToTitle,
canInputStepContinue,
canPickStepContinue,
canStepContinue,
createConfirmStep,
createInputStep,
createPickStep,
endSteps,
inputTagNameStep,
pickBranchOrTagStep,
pickRepositoryStep,
@ -186,7 +193,7 @@ export class TagGitCommand extends QuickCommand {
yield* this.deleteCommandSteps(state as DeleteStepState, context);
break;
default:
QuickCommand.endSteps(state);
endSteps(state);
break;
}
@ -200,7 +207,7 @@ export class TagGitCommand extends QuickCommand {
}
private *pickSubcommandStep(state: PartialStepState<State>): StepResultGenerator<State['subcommand']> {
const step = QuickCommand.createPickStep<QuickPickItemOfT<State['subcommand']>>({
const step = createPickStep<QuickPickItemOfT<State['subcommand']>>({
title: this.title,
placeholder: `Choose a ${this.label} command`,
items: [
@ -220,7 +227,7 @@ export class TagGitCommand extends QuickCommand {
buttons: [QuickInputButtons.Back],
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
private async *createCommandSteps(state: CreateStepState, context: Context): AsyncStepResultGenerator<void> {
@ -272,7 +279,7 @@ export class TagGitCommand extends QuickCommand {
state.flags = result;
}
QuickCommand.endSteps(state);
endSteps(state);
state.repo.tag(
...state.flags,
...(state.message.length !== 0 ? [`"${state.message}"`] : []),
@ -286,7 +293,7 @@ export class TagGitCommand extends QuickCommand {
state: CreateStepState,
context: Context,
): AsyncStepResultGenerator<string> {
const step = QuickCommand.createInputStep({
const step = createInputStep({
title: appendReposToTitle(
`${context.title} at ${GitReference.toString(state.reference, { capitalize: true, icon: false })}`,
state,
@ -299,10 +306,7 @@ export class TagGitCommand extends QuickCommand {
const value: StepSelection<typeof step> = yield step;
if (
!QuickCommand.canStepContinue(step, state, value) ||
!(await QuickCommand.canInputStepContinue(step, state, value))
) {
if (!canStepContinue(step, state, value) || !(await canInputStepContinue(step, state, value))) {
return StepResult.Break;
}
@ -313,7 +317,7 @@ export class TagGitCommand extends QuickCommand {
state: CreateStepState<CreateState>,
context: Context,
): StepResultGenerator<CreateFlags[]> {
const step: QuickPickStep<FlagsQuickPickItem<CreateFlags>> = QuickCommand.createConfirmStep(
const step: QuickPickStep<FlagsQuickPickItem<CreateFlags>> = createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context),
[
createFlagsQuickPickItem<CreateFlags>(state.flags, state.message.length !== 0 ? ['-m'] : [], {
@ -336,7 +340,7 @@ export class TagGitCommand extends QuickCommand {
context,
);
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
private async *deleteCommandSteps(state: DeleteStepState, context: Context): StepGenerator {
@ -363,7 +367,7 @@ export class TagGitCommand extends QuickCommand {
const result = yield* this.deleteCommandConfirmStep(state, context);
if (result === StepResult.Break) continue;
QuickCommand.endSteps(state);
endSteps(state);
state.repo.tagDelete(state.references);
}
}
@ -372,7 +376,7 @@ export class TagGitCommand extends QuickCommand {
state: DeleteStepState<DeleteState>,
context: Context,
): StepResultGenerator<void> {
const step: QuickPickStep<QuickPickItem> = QuickCommand.createConfirmStep(
const step: QuickPickStep<QuickPickItem> = createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context),
[
{
@ -383,6 +387,6 @@ export class TagGitCommand extends QuickCommand {
context,
);
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? undefined : StepResult.Break;
return canPickStepContinue(step, state, selection) ? undefined : StepResult.Break;
}
}

+ 21
- 17
src/commands/git/worktree.ts Bestand weergeven

@ -36,6 +36,13 @@ import type {
} from '../quickCommand';
import {
appendReposToTitle,
canInputStepContinue,
canPickStepContinue,
canStepContinue,
createConfirmStep,
createCustomStep,
createPickStep,
endSteps,
ensureAccessStep,
inputBranchNameStep,
pickBranchOrTagStep,
@ -238,7 +245,7 @@ export class WorktreeGitCommand extends QuickCommand {
break;
}
default:
QuickCommand.endSteps(state);
endSteps(state);
break;
}
@ -252,7 +259,7 @@ export class WorktreeGitCommand extends QuickCommand {
}
private *pickSubcommandStep(state: PartialStepState<State>): StepResultGenerator<State['subcommand']> {
const step = QuickCommand.createPickStep<QuickPickItemOfT<State['subcommand']>>({
const step = createPickStep<QuickPickItemOfT<State['subcommand']>>({
title: this.title,
placeholder: `Choose a ${this.label} command`,
items: [
@ -278,7 +285,7 @@ export class WorktreeGitCommand extends QuickCommand {
buttons: [QuickInputButtons.Back],
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
private async *createCommandSteps(state: CreateStepState, context: Context): AsyncStepResultGenerator<void> {
@ -487,7 +494,7 @@ export class WorktreeGitCommand extends QuickCommand {
}
}
QuickCommand.endSteps(state);
endSteps(state);
}
}
@ -496,7 +503,7 @@ export class WorktreeGitCommand extends QuickCommand {
context: Context,
options: { titleContext: string; defaultUri?: Uri },
): AsyncStepResultGenerator<Uri> {
const step = QuickCommand.createCustomStep<Uri>({
const step = createCustomStep<Uri>({
show: async (_step: CustomStep<Uri>) => {
const hasDefault = options?.defaultUri != null;
const result = await window.showInformationMessage(
@ -526,10 +533,7 @@ export class WorktreeGitCommand extends QuickCommand {
const value: StepSelection<typeof step> = yield step;
if (
!QuickCommand.canStepContinue(step, state, value) ||
!(await QuickCommand.canInputStepContinue(step, state, value))
) {
if (!canStepContinue(step, state, value) || !(await canInputStepContinue(step, state, value))) {
return StepResult.Break;
}
@ -587,7 +591,7 @@ export class WorktreeGitCommand extends QuickCommand {
const isRemoteBranch = state.reference?.refType === 'branch' && state.reference?.remote;
const step: QuickPickStep<FlagsQuickPickItem<CreateFlags, Uri>> = QuickCommand.createConfirmStep(
const step: QuickPickStep<FlagsQuickPickItem<CreateFlags, Uri>> = createConfirmStep(
appendReposToTitle(
`Confirm ${context.title} \u2022 ${GitReference.toString(state.reference, {
icon: false,
@ -650,7 +654,7 @@ export class WorktreeGitCommand extends QuickCommand {
context,
);
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection)
return canPickStepContinue(step, state, selection)
? [selection[0].context, selection[0].item]
: StepResult.Break;
}
@ -685,7 +689,7 @@ export class WorktreeGitCommand extends QuickCommand {
state.flags = result;
QuickCommand.endSteps(state);
endSteps(state);
for (const uri of state.uris) {
let retry = false;
@ -743,7 +747,7 @@ export class WorktreeGitCommand extends QuickCommand {
}
private *deleteCommandConfirmStep(state: DeleteStepState, context: Context): StepResultGenerator<DeleteFlags[]> {
const step: QuickPickStep<FlagsQuickPickItem<DeleteFlags>> = QuickCommand.createConfirmStep(
const step: QuickPickStep<FlagsQuickPickItem<DeleteFlags>> = createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context),
[
createFlagsQuickPickItem<DeleteFlags>(state.flags, [], {
@ -766,7 +770,7 @@ export class WorktreeGitCommand extends QuickCommand {
);
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
private async *openCommandSteps(state: OpenStepState, context: Context): StepGenerator {
@ -798,7 +802,7 @@ export class WorktreeGitCommand extends QuickCommand {
state.flags = result;
QuickCommand.endSteps(state);
endSteps(state);
const worktree = context.worktrees.find(wt => wt.uri.toString() === state.uri.toString())!;
if (state.flags.includes('--reveal-explorer')) {
@ -814,7 +818,7 @@ export class WorktreeGitCommand extends QuickCommand {
}
private *openCommandConfirmStep(state: OpenStepState, context: Context): StepResultGenerator<OpenFlags[]> {
const step: QuickPickStep<FlagsQuickPickItem<OpenFlags>> = QuickCommand.createConfirmStep(
const step: QuickPickStep<FlagsQuickPickItem<OpenFlags>> = createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context),
[
createFlagsQuickPickItem<OpenFlags>(state.flags, [], {
@ -840,6 +844,6 @@ export class WorktreeGitCommand extends QuickCommand {
);
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
}

+ 5
- 5
src/commands/gitCommands.ts Bestand weergeven

@ -31,8 +31,8 @@ import type { SwitchGitCommandArgs } from './git/switch';
import type { TagGitCommandArgs } from './git/tag';
import type { WorktreeGitCommandArgs } from './git/worktree';
import { PickCommandStep } from './gitCommands.utils';
import type { CustomStep, QuickInputStep, QuickPickStep, StepSelection } from './quickCommand';
import { isCustomStep, isQuickInputStep, isQuickPickStep, QuickCommand, StepResult } from './quickCommand';
import type { CustomStep, QuickCommand, QuickInputStep, QuickPickStep, StepSelection } from './quickCommand';
import { isCustomStep , isQuickCommand, isQuickInputStep, isQuickPickStep, StepResult } from './quickCommand';
import { QuickCommandButtons, ToggleQuickInputButton } from './quickCommand.buttons';
const sanitizeLabel = /\$\(.+?\)|\s/g;
@ -538,7 +538,7 @@ export class GitCommandsCommand extends Command {
let activeCommand;
if (commandsStep.command == null && quickpick.activeItems.length !== 0) {
const active = quickpick.activeItems[0];
if (QuickCommand.is(active)) {
if (isQuickCommand(active)) {
activeCommand = active;
}
}
@ -657,7 +657,7 @@ export class GitCommandsCommand extends Command {
if (commandsStep.command != null || quickpick.activeItems.length === 0) return;
const command = quickpick.activeItems[0];
if (!QuickCommand.is(command)) return;
if (!isQuickCommand(command)) return;
quickpick.buttons = this.getButtons(undefined, command);
}),
@ -744,7 +744,7 @@ export class GitCommandsCommand extends Command {
if (commandsStep.command == null) {
const [command] = items;
if (!QuickCommand.is(command)) return;
if (!isQuickCommand(command)) return;
commandsStep.setCommand(command, this.startedWith);
}

+ 59
- 62
src/commands/quickCommand.steps.ts Bestand weergeven

@ -99,7 +99,16 @@ import type {
StepSelection,
StepState,
} from './quickCommand';
import { QuickCommand, QuickCommandButtons, StepResult } from './quickCommand';
import {
canInputStepContinue,
canPickStepContinue,
canStepContinue,
createInputStep,
createPickStep,
endSteps,
QuickCommandButtons,
StepResult,
} from './quickCommand';
export function appendReposToTitle<
State extends { repo: Repository } | { repos: Repository[] },
@ -485,7 +494,7 @@ export async function* inputBranchNameStep<
context: Context,
options: { placeholder: string; titleContext?: string; value?: string },
): AsyncStepResultGenerator<string> {
const step = QuickCommand.createInputStep({
const step = createInputStep({
title: appendReposToTitle(`${context.title}${options.titleContext ?? ''}`, state, context),
placeholder: options.placeholder,
value: options.value,
@ -515,10 +524,7 @@ export async function* inputBranchNameStep<
});
const value: StepSelection<typeof step> = yield step;
if (
!QuickCommand.canStepContinue(step, state, value) ||
!(await QuickCommand.canInputStepContinue(step, state, value))
) {
if (!canStepContinue(step, state, value) || !(await canInputStepContinue(step, state, value))) {
return StepResult.Break;
}
@ -533,7 +539,7 @@ export async function* inputRemoteNameStep<
context: Context,
options: { placeholder: string; titleContext?: string; value?: string },
): AsyncStepResultGenerator<string> {
const step = QuickCommand.createInputStep({
const step = createInputStep({
title: appendReposToTitle(`${context.title}${options.titleContext ?? ''}`, state, context),
placeholder: options.placeholder,
value: options.value,
@ -559,10 +565,7 @@ export async function* inputRemoteNameStep<
});
const value: StepSelection<typeof step> = yield step;
if (
!QuickCommand.canStepContinue(step, state, value) ||
!(await QuickCommand.canInputStepContinue(step, state, value))
) {
if (!canStepContinue(step, state, value) || !(await canInputStepContinue(step, state, value))) {
return StepResult.Break;
}
@ -577,7 +580,7 @@ export async function* inputRemoteUrlStep<
context: Context,
options: { placeholder: string; titleContext?: string; value?: string },
): AsyncStepResultGenerator<string> {
const step = QuickCommand.createInputStep({
const step = createInputStep({
title: appendReposToTitle(`${context.title}${options.titleContext ?? ''}`, state, context),
placeholder: options.placeholder,
value: options.value,
@ -594,10 +597,7 @@ export async function* inputRemoteUrlStep<
});
const value: StepSelection<typeof step> = yield step;
if (
!QuickCommand.canStepContinue(step, state, value) ||
!(await QuickCommand.canInputStepContinue(step, state, value))
) {
if (!canStepContinue(step, state, value) || !(await canInputStepContinue(step, state, value))) {
return StepResult.Break;
}
@ -612,7 +612,7 @@ export async function* inputTagNameStep<
context: Context,
options: { placeholder: string; titleContext?: string; value?: string },
): AsyncStepResultGenerator<string> {
const step = QuickCommand.createInputStep({
const step = createInputStep({
title: appendReposToTitle(`${context.title}${options.titleContext ?? ''}`, state, context),
placeholder: options.placeholder,
value: options.value,
@ -642,10 +642,7 @@ export async function* inputTagNameStep<
});
const value: StepSelection<typeof step> = yield step;
if (
!QuickCommand.canStepContinue(step, state, value) ||
!(await QuickCommand.canInputStepContinue(step, state, value))
) {
if (!canStepContinue(step, state, value) || !(await canInputStepContinue(step, state, value))) {
return StepResult.Break;
}
@ -676,7 +673,7 @@ export async function* pickBranchStep<
picked: picked,
});
const step = QuickCommand.createPickStep<BranchQuickPickItem>({
const step = createPickStep<BranchQuickPickItem>({
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
placeholder: branches.length === 0 ? `No branches found in ${state.repo.formattedName}` : placeholder,
matchOnDetail: true,
@ -701,7 +698,7 @@ export async function* pickBranchStep<
},
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
export async function* pickBranchesStep<
@ -731,7 +728,7 @@ export async function* pickBranchesStep<
sort: sort,
});
const step = QuickCommand.createPickStep<BranchQuickPickItem>({
const step = createPickStep<BranchQuickPickItem>({
multiselect: branches.length !== 0,
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
placeholder: branches.length === 0 ? `No branches found in ${state.repo.formattedName}` : placeholder,
@ -757,7 +754,7 @@ export async function* pickBranchesStep<
},
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
}
export async function* pickBranchOrTagStep<
@ -801,7 +798,7 @@ export async function* pickBranchOrTagStep<
};
const branchesAndOrTags = await getBranchesAndOrTagsFn();
const step = QuickCommand.createPickStep<ReferencesQuickPickItem>({
const step = createPickStep<ReferencesQuickPickItem>({
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
placeholder:
branchesAndOrTags.length === 0
@ -872,7 +869,7 @@ export async function* pickBranchOrTagStep<
onValidateValue: getValidateGitReferenceFn(state.repo, { ranges: ranges }),
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
export async function* pickBranchOrTagStepMultiRepo<
@ -910,7 +907,7 @@ export async function* pickBranchOrTagStepMultiRepo<
};
const branchesAndOrTags = await getBranchesAndOrTagsFn();
const step = QuickCommand.createPickStep<ReferencesQuickPickItem>({
const step = createPickStep<ReferencesQuickPickItem>({
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
placeholder:
branchesAndOrTags.length === 0
@ -986,7 +983,7 @@ export async function* pickBranchOrTagStepMultiRepo<
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
export async function* pickCommitStep<
@ -1038,7 +1035,7 @@ export async function* pickCommitStep<
];
}
const step = QuickCommand.createPickStep<CommandQuickPickItem | CommitQuickPickItem>({
const step = createPickStep<CommandQuickPickItem | CommitQuickPickItem>({
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
placeholder: typeof placeholder === 'string' ? placeholder : placeholder(context, log),
ignoreFocusOut: ignoreFocusOut,
@ -1111,10 +1108,10 @@ export async function* pickCommitStep<
}),
});
const selection: StepSelection<typeof step> = yield step;
if (!QuickCommand.canPickStepContinue(step, state, selection)) return StepResult.Break;
if (!canPickStepContinue(step, state, selection)) return StepResult.Break;
if (CommandQuickPickItem.is(selection[0])) {
QuickCommand.endSteps(state);
endSteps(state);
await selection[0].execute();
return StepResult.Break;
@ -1164,7 +1161,7 @@ export function* pickCommitsStep<
];
}
const step = QuickCommand.createPickStep<CommitQuickPickItem>({
const step = createPickStep<CommitQuickPickItem>({
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
multiselect: log != null,
placeholder: typeof placeholder === 'string' ? placeholder : placeholder(context, log),
@ -1215,7 +1212,7 @@ export function* pickCommitsStep<
},
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
}
export async function* pickContributorsStep<
@ -1228,7 +1225,7 @@ export async function* pickContributorsStep<
): AsyncStepResultGenerator<GitContributor[]> {
const message = (await Container.instance.git.getOrOpenScmRepository(state.repo.path))?.inputBox.value;
const step = QuickCommand.createPickStep<ContributorQuickPickItem>({
const step = createPickStep<ContributorQuickPickItem>({
title: appendReposToTitle(context.title, state, context),
allowEmpty: true,
multiselect: true,
@ -1256,7 +1253,7 @@ export async function* pickContributorsStep<
},
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
}
export async function* pickRemoteStep<
@ -1283,7 +1280,7 @@ export async function* pickRemoteStep<
picked: picked,
});
const step = QuickCommand.createPickStep<RemoteQuickPickItem>({
const step = createPickStep<RemoteQuickPickItem>({
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
placeholder: remotes.length === 0 ? `No remotes found in ${state.repo.formattedName}` : placeholder,
matchOnDetail: true,
@ -1308,7 +1305,7 @@ export async function* pickRemoteStep<
},
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
export async function* pickRemotesStep<
@ -1335,7 +1332,7 @@ export async function* pickRemotesStep<
picked: picked,
});
const step = QuickCommand.createPickStep<RemoteQuickPickItem>({
const step = createPickStep<RemoteQuickPickItem>({
multiselect: remotes.length !== 0,
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
placeholder: remotes.length === 0 ? `No remotes found in ${state.repo.formattedName}` : placeholder,
@ -1361,7 +1358,7 @@ export async function* pickRemotesStep<
},
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
}
export async function* pickRepositoryStep<
@ -1374,7 +1371,7 @@ export async function* pickRepositoryStep<
}
const active = state.repo ?? (await Container.instance.git.getOrOpenRepositoryForEditor());
const step = QuickCommand.createPickStep<RepositoryQuickPickItem>({
const step = createPickStep<RepositoryQuickPickItem>({
title: context.title,
placeholder: placeholder,
items:
@ -1411,7 +1408,7 @@ export async function* pickRepositoryStep<
},
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
export async function* pickRepositoriesStep<
@ -1439,7 +1436,7 @@ export async function* pickRepositoriesStep<
actives = active != null ? [active] : [];
}
const step = QuickCommand.createPickStep<RepositoryQuickPickItem>({
const step = createPickStep<RepositoryQuickPickItem>({
multiselect: true,
title: context.title,
placeholder: options.placeholder,
@ -1481,7 +1478,7 @@ export async function* pickRepositoriesStep<
},
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
}
export function* pickStashStep<
@ -1504,7 +1501,7 @@ export function* pickStashStep<
titleContext?: string;
},
): StepResultGenerator<GitStashCommit> {
const step = QuickCommand.createPickStep<CommitQuickPickItem<GitStashCommit>>({
const step = createPickStep<CommitQuickPickItem<GitStashCommit>>({
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
placeholder: typeof placeholder === 'string' ? placeholder : placeholder(context, stash),
ignoreFocusOut: ignoreFocusOut,
@ -1540,7 +1537,7 @@ export function* pickStashStep<
},
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
export async function* pickTagsStep<
@ -1567,7 +1564,7 @@ export async function* pickTagsStep<
picked: picked,
});
const step = QuickCommand.createPickStep<TagQuickPickItem>({
const step = createPickStep<TagQuickPickItem>({
multiselect: tags.length !== 0,
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
placeholder: tags.length === 0 ? `No tags found in ${state.repo.formattedName}` : placeholder,
@ -1597,7 +1594,7 @@ export async function* pickTagsStep<
},
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
}
export async function* pickWorktreeStep<
@ -1627,7 +1624,7 @@ export async function* pickWorktreeStep<
picked: picked,
});
const step = QuickCommand.createPickStep<WorktreeQuickPickItem>({
const step = createPickStep<WorktreeQuickPickItem>({
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
placeholder: worktrees.length === 0 ? `No worktrees found in ${state.repo.formattedName}` : placeholder,
matchOnDetail: true,
@ -1657,7 +1654,7 @@ export async function* pickWorktreeStep<
},
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
export async function* pickWorktreesStep<
@ -1687,7 +1684,7 @@ export async function* pickWorktreesStep<
picked: picked,
});
const step = QuickCommand.createPickStep<WorktreeQuickPickItem>({
const step = createPickStep<WorktreeQuickPickItem>({
multiselect: worktrees.length !== 0,
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
placeholder: worktrees.length === 0 ? `No worktrees found in ${state.repo.formattedName}` : placeholder,
@ -1718,7 +1715,7 @@ export async function* pickWorktreesStep<
},
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
}
export async function* showCommitOrStashStep<
@ -1729,7 +1726,7 @@ export async function* showCommitOrStashStep<
context: Context,
): AsyncStepResultGenerator<CommitFilesQuickPickItem | GitCommandQuickPickItem | CommandQuickPickItem> {
const step: QuickPickStep<CommitFilesQuickPickItem | GitCommandQuickPickItem | CommandQuickPickItem> =
QuickCommand.createPickStep({
createPickStep({
title: appendReposToTitle(
GitReference.toString(state.reference, {
capitalize: true,
@ -1779,7 +1776,7 @@ export async function* showCommitOrStashStep<
},
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0] : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0] : StepResult.Break;
}
async function getShowCommitOrStashStepItems<
@ -2003,7 +2000,7 @@ export function* showCommitOrStashFilesStep<
debugger;
}
const step: QuickPickStep<CommitFilesQuickPickItem | CommitFileQuickPickItem> = QuickCommand.createPickStep({
const step: QuickPickStep<CommitFilesQuickPickItem | CommitFileQuickPickItem> = createPickStep({
title: appendReposToTitle(
GitReference.toString(state.reference, {
capitalize: true,
@ -2063,7 +2060,7 @@ export function* showCommitOrStashFilesStep<
},
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0] : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0] : StepResult.Break;
}
export async function* showCommitOrStashFileStep<
@ -2074,7 +2071,7 @@ export async function* showCommitOrStashFileStep<
},
Context extends { repos: Repository[]; title: string },
>(state: State, context: Context): AsyncStepResultGenerator<CommandQuickPickItem> {
const step: QuickPickStep<CommandQuickPickItem> = QuickCommand.createPickStep<CommandQuickPickItem>({
const step: QuickPickStep<CommandQuickPickItem> = createPickStep<CommandQuickPickItem>({
title: appendReposToTitle(
GitReference.toString(state.reference, {
capitalize: true,
@ -2130,7 +2127,7 @@ export async function* showCommitOrStashFileStep<
},
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0] : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0] : StepResult.Break;
}
async function getShowCommitOrStashFileStepItems<
@ -2242,7 +2239,7 @@ export function* showRepositoryStatusStep<
>(state: State, context: Context): StepResultGenerator<CommandQuickPickItem> {
const upstream = context.status.getUpstreamStatus({ expand: true, separator: ', ' });
const working = context.status.getFormattedDiffStatus({ expand: true, separator: ', ' });
const step: QuickPickStep<CommandQuickPickItem> = QuickCommand.createPickStep<CommandQuickPickItem>({
const step: QuickPickStep<CommandQuickPickItem> = createPickStep<CommandQuickPickItem>({
title: appendReposToTitle(context.title, state, context),
placeholder: `${upstream ? `${upstream}, ${working}` : working}`, //'Changes to be committed',
ignoreFocusOut: true,
@ -2255,7 +2252,7 @@ export function* showRepositoryStatusStep<
},
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0] : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0] : StepResult.Break;
}
function getShowRepositoryStatusStepItems<
@ -2415,12 +2412,12 @@ export async function* ensureAccessStep<
}
}
const step = QuickCommand.createPickStep<DirectiveQuickPickItem>({
const step = createPickStep<DirectiveQuickPickItem>({
title: appendReposToTitle(context.title, state, context),
placeholder: placeholder,
items: [...directives, createDirectiveQuickPickItem(Directive.Cancel)],
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? undefined : StepResult.Break;
return canPickStepContinue(step, state, selection) ? undefined : StepResult.Break;
}

+ 83
- 85
src/commands/quickCommand.ts Bestand weergeven

@ -3,7 +3,7 @@ import { configuration } from '../configuration';
import type { Container } from '../container';
import type { Keys } from '../keyboard';
import type { DirectiveQuickPickItem } from '../quickpicks/items/directive';
import { createDirectiveQuickPickItem , Directive, isDirective } from '../quickpicks/items/directive';
import { createDirectiveQuickPickItem, Directive, isDirective } from '../quickpicks/items/directive';
export * from './quickCommand.buttons';
export * from './quickCommand.steps';
@ -243,7 +243,7 @@ export abstract class QuickCommand implements QuickPickItem {
cancel?: DirectiveQuickPickItem,
options: Partial<QuickPickStep<T>> = {},
): QuickPickStep<T> {
return QuickCommand.createConfirmStep(title, confirmations, { title: this.title }, cancel, options);
return createConfirmStep(title, confirmations, { title: this.title }, cancel, options);
}
protected getStepState(limitBackNavigation: boolean): PartialStepState<State> {
@ -257,103 +257,101 @@ export abstract class QuickCommand implements QuickPickItem {
}
}
export namespace QuickCommand {
export function is(item: QuickPickItem): item is QuickCommand {
return item instanceof QuickCommand;
export function isQuickCommand(item: QuickPickItem): item is QuickCommand {
return item instanceof QuickCommand;
}
export async function canInputStepContinue<T extends QuickInputStep>(
step: T,
state: PartialStepState,
value: Directive | StepItemType<T>,
) {
if (!canStepContinue(step, state, value)) return false;
const [valid] = (await step.validate?.(value)) ?? [true];
if (valid) {
state.counter++;
return true;
}
export async function canInputStepContinue<T extends QuickInputStep>(
step: T,
state: PartialStepState,
value: Directive | StepItemType<T>,
) {
if (!canStepContinue(step, state, value)) return false;
return false;
}
const [valid] = (await step.validate?.(value)) ?? [true];
if (valid) {
state.counter++;
return true;
}
export function canPickStepContinue<T extends QuickPickStep>(
step: T,
state: PartialStepState,
selection: StepItemType<T> | Directive,
): selection is StepItemType<T> {
if (!canStepContinue(step, state, selection)) return false;
return false;
if (step.validate?.(selection) ?? true) {
state.counter++;
return true;
}
export function canPickStepContinue<T extends QuickPickStep>(
step: T,
state: PartialStepState,
selection: StepItemType<T> | Directive,
): selection is StepItemType<T> {
if (!canStepContinue(step, state, selection)) return false;
return false;
}
if (step.validate?.(selection) ?? true) {
state.counter++;
return true;
export function canStepContinue<T extends QuickInputStep | QuickPickStep>(
step: T,
state: PartialStepState,
result: Directive | StepItemType<T>,
): result is StepItemType<T> {
if (result == null) return false;
if (isDirective(result)) {
switch (result) {
case Directive.Back:
state.counter--;
if (state.counter <= (state.startingStep ?? 0)) {
state.counter = 0;
}
break;
case Directive.Cancel:
endSteps(state);
break;
// case Directive.Noop:
// case Directive.RequiresVerification:
// case Directive.RequiresFreeSubscription:
// case Directive.RequiresProSubscription:
// break;
}
return false;
}
export function canStepContinue<T extends QuickInputStep | QuickPickStep>(
step: T,
state: PartialStepState,
result: Directive | StepItemType<T>,
): result is StepItemType<T> {
if (result == null) return false;
if (isDirective(result)) {
switch (result) {
case Directive.Back:
state.counter--;
if (state.counter <= (state.startingStep ?? 0)) {
state.counter = 0;
}
break;
case Directive.Cancel:
endSteps(state);
break;
// case Directive.Noop:
// case Directive.RequiresVerification:
// case Directive.RequiresFreeSubscription:
// case Directive.RequiresProSubscription:
// break;
}
return false;
}
return true;
}
return true;
}
export function createConfirmStep<T extends QuickPickItem, Context extends { title: string }>(
title: string,
confirmations: T[],
context: Context,
cancel?: DirectiveQuickPickItem,
options: Partial<QuickPickStep<T>> = {},
): QuickPickStep<T> {
return createPickStep<T>({
placeholder: `Confirm ${context.title}`,
title: title,
ignoreFocusOut: true,
items: [...confirmations, cancel ?? createDirectiveQuickPickItem(Directive.Cancel)],
selectedItems: [confirmations.find(c => c.picked) ?? confirmations[0]],
...options,
});
}
export function createConfirmStep<T extends QuickPickItem, Context extends { title: string }>(
title: string,
confirmations: T[],
context: Context,
cancel?: DirectiveQuickPickItem,
options: Partial<QuickPickStep<T>> = {},
): QuickPickStep<T> {
return createPickStep<T>({
placeholder: `Confirm ${context.title}`,
title: title,
ignoreFocusOut: true,
items: [...confirmations, cancel ?? createDirectiveQuickPickItem(Directive.Cancel)],
selectedItems: [confirmations.find(c => c.picked) ?? confirmations[0]],
...options,
});
}
export function createInputStep(step: QuickInputStep): QuickInputStep {
// Make sure any input steps won't close on focus loss
step.ignoreFocusOut = true;
return step;
}
export function createInputStep(step: QuickInputStep): QuickInputStep {
// Make sure any input steps won't close on focus loss
step.ignoreFocusOut = true;
return step;
}
export function createPickStep<T extends QuickPickItem>(step: QuickPickStep<T>): QuickPickStep<T> {
return step;
}
export function createPickStep<T extends QuickPickItem>(step: QuickPickStep<T>): QuickPickStep<T> {
return step;
}
export function createCustomStep<T>(step: CustomStep<T>): CustomStep<T> {
return step;
}
export function createCustomStep<T>(step: CustomStep<T>): CustomStep<T> {
return step;
}
export function endSteps(state: PartialStepState) {
state.counter = -1;
}
export function endSteps(state: PartialStepState) {
state.counter = -1;
}

Laden…
Annuleren
Opslaan