|
|
@ -1,37 +1,37 @@ |
|
|
|
import { Disposable, InputBox, QuickInputButton, QuickInputButtons, QuickPick, QuickPickItem, window } from 'vscode'; |
|
|
|
import { configuration, GitCommandSorting } from '../configuration'; |
|
|
|
import { configuration } from '../configuration'; |
|
|
|
import { Commands } from '../constants'; |
|
|
|
import type { Container } from '../container'; |
|
|
|
import { KeyMapping } from '../keyboard'; |
|
|
|
import { Directive, DirectiveQuickPickItem } from '../quickpicks'; |
|
|
|
import { Usage, WorkspaceState } from '../storage'; |
|
|
|
import { Directive, DirectiveQuickPickItem } from '../quickpicks/items/directive'; |
|
|
|
import { command } from '../system/command'; |
|
|
|
import { log } from '../system/decorators/log'; |
|
|
|
import { isPromise } from '../system/promise'; |
|
|
|
import { command, Command, CommandContext } from './base'; |
|
|
|
import { BranchGitCommand, BranchGitCommandArgs } from './git/branch'; |
|
|
|
import { CherryPickGitCommand, CherryPickGitCommandArgs } from './git/cherry-pick'; |
|
|
|
import { CoAuthorsGitCommand, CoAuthorsGitCommandArgs } from './git/coauthors'; |
|
|
|
import { FetchGitCommand, FetchGitCommandArgs } from './git/fetch'; |
|
|
|
import { LogGitCommand, LogGitCommandArgs } from './git/log'; |
|
|
|
import { MergeGitCommand, MergeGitCommandArgs } from './git/merge'; |
|
|
|
import { PullGitCommand, PullGitCommandArgs } from './git/pull'; |
|
|
|
import { PushGitCommand, PushGitCommandArgs } from './git/push'; |
|
|
|
import { RebaseGitCommand, RebaseGitCommandArgs } from './git/rebase'; |
|
|
|
import { ResetGitCommand, ResetGitCommandArgs } from './git/reset'; |
|
|
|
import { RevertGitCommand, RevertGitCommandArgs } from './git/revert'; |
|
|
|
import { SearchGitCommand, SearchGitCommandArgs } from './git/search'; |
|
|
|
import { ShowGitCommand, ShowGitCommandArgs } from './git/show'; |
|
|
|
import { StashGitCommand, StashGitCommandArgs } from './git/stash'; |
|
|
|
import { StatusGitCommand, StatusGitCommandArgs } from './git/status'; |
|
|
|
import { SwitchGitCommand, SwitchGitCommandArgs } from './git/switch'; |
|
|
|
import { TagGitCommand, TagGitCommandArgs } from './git/tag'; |
|
|
|
import { Command, CommandContext } from './base'; |
|
|
|
import type { BranchGitCommandArgs } from './git/branch'; |
|
|
|
import type { CherryPickGitCommandArgs } from './git/cherry-pick'; |
|
|
|
import type { CoAuthorsGitCommandArgs } from './git/coauthors'; |
|
|
|
import type { FetchGitCommandArgs } from './git/fetch'; |
|
|
|
import type { LogGitCommandArgs } from './git/log'; |
|
|
|
import type { MergeGitCommandArgs } from './git/merge'; |
|
|
|
import type { PullGitCommandArgs } from './git/pull'; |
|
|
|
import type { PushGitCommandArgs } from './git/push'; |
|
|
|
import type { RebaseGitCommandArgs } from './git/rebase'; |
|
|
|
import type { ResetGitCommandArgs } from './git/reset'; |
|
|
|
import type { RevertGitCommandArgs } from './git/revert'; |
|
|
|
import type { SearchGitCommandArgs } from './git/search'; |
|
|
|
import type { ShowGitCommandArgs } from './git/show'; |
|
|
|
import type { StashGitCommandArgs } from './git/stash'; |
|
|
|
import type { StatusGitCommandArgs } from './git/status'; |
|
|
|
import type { SwitchGitCommandArgs } from './git/switch'; |
|
|
|
import type { TagGitCommandArgs } from './git/tag'; |
|
|
|
import { PickCommandStep } from './gitCommands.utils'; |
|
|
|
import { |
|
|
|
isQuickInputStep, |
|
|
|
isQuickPickStep, |
|
|
|
QuickCommand, |
|
|
|
QuickInputStep, |
|
|
|
QuickPickStep, |
|
|
|
StepGenerator, |
|
|
|
StepSelection, |
|
|
|
} from './quickCommand'; |
|
|
|
import { QuickCommandButtons, ToggleQuickInputButton } from './quickCommand.buttons'; |
|
|
@ -58,23 +58,8 @@ export type GitCommandsCommandArgs = |
|
|
|
| SwitchGitCommandArgs |
|
|
|
| TagGitCommandArgs; |
|
|
|
|
|
|
|
function* nullSteps(): StepGenerator { |
|
|
|
/* noop */ |
|
|
|
} |
|
|
|
|
|
|
|
@command() |
|
|
|
export class GitCommandsCommand extends Command { |
|
|
|
static getSteps(container: Container, args: GitCommandsCommandArgs, pickedVia: 'menu' | 'command'): StepGenerator { |
|
|
|
const commandsStep = new PickCommandStep(container, args); |
|
|
|
|
|
|
|
const command = commandsStep.find(args.command); |
|
|
|
if (command == null) return nullSteps(); |
|
|
|
|
|
|
|
commandsStep.setCommand(command, pickedVia); |
|
|
|
|
|
|
|
return command.executeSteps(); |
|
|
|
} |
|
|
|
|
|
|
|
private startedWith: 'menu' | 'command' = 'menu'; |
|
|
|
|
|
|
|
constructor(private readonly container: Container) { |
|
|
@ -736,87 +721,3 @@ export class GitCommandsCommand extends Command { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
class PickCommandStep implements QuickPickStep { |
|
|
|
readonly buttons = []; |
|
|
|
private readonly hiddenItems: QuickCommand[]; |
|
|
|
ignoreFocusOut = false; |
|
|
|
readonly items: QuickCommand[]; |
|
|
|
readonly matchOnDescription = true; |
|
|
|
readonly placeholder = 'Choose a git command'; |
|
|
|
readonly title = 'GitLens'; |
|
|
|
|
|
|
|
constructor(private readonly container: Container, args?: GitCommandsCommandArgs) { |
|
|
|
this.items = [ |
|
|
|
new BranchGitCommand(container, args?.command === 'branch' ? args : undefined), |
|
|
|
new CherryPickGitCommand(container, args?.command === 'cherry-pick' ? args : undefined), |
|
|
|
new CoAuthorsGitCommand(container, args?.command === 'co-authors' ? args : undefined), |
|
|
|
new FetchGitCommand(container, args?.command === 'fetch' ? args : undefined), |
|
|
|
new LogGitCommand(container, args?.command === 'log' ? args : undefined), |
|
|
|
new MergeGitCommand(container, args?.command === 'merge' ? args : undefined), |
|
|
|
new PullGitCommand(container, args?.command === 'pull' ? args : undefined), |
|
|
|
new PushGitCommand(container, args?.command === 'push' ? args : undefined), |
|
|
|
new RebaseGitCommand(container, args?.command === 'rebase' ? args : undefined), |
|
|
|
new ResetGitCommand(container, args?.command === 'reset' ? args : undefined), |
|
|
|
new RevertGitCommand(container, args?.command === 'revert' ? args : undefined), |
|
|
|
new SearchGitCommand(container, args?.command === 'search' || args?.command === 'grep' ? args : undefined), |
|
|
|
new ShowGitCommand(container, args?.command === 'show' ? args : undefined), |
|
|
|
new StashGitCommand(container, args?.command === 'stash' ? args : undefined), |
|
|
|
new StatusGitCommand(container, args?.command === 'status' ? args : undefined), |
|
|
|
new SwitchGitCommand( |
|
|
|
container, |
|
|
|
args?.command === 'switch' || args?.command === 'checkout' ? args : undefined, |
|
|
|
), |
|
|
|
new TagGitCommand(container, args?.command === 'tag' ? args : undefined), |
|
|
|
]; |
|
|
|
|
|
|
|
if (this.container.config.gitCommands.sortBy === GitCommandSorting.Usage) { |
|
|
|
const usage = this.container.storage.getWorkspace<Usage>(WorkspaceState.GitCommandPaletteUsage); |
|
|
|
if (usage != null) { |
|
|
|
this.items.sort((a, b) => (usage[b.key] ?? 0) - (usage[a.key] ?? 0)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this.hiddenItems = []; |
|
|
|
} |
|
|
|
|
|
|
|
private _command: QuickCommand | undefined; |
|
|
|
get command(): QuickCommand | undefined { |
|
|
|
return this._command; |
|
|
|
} |
|
|
|
|
|
|
|
find(commandName: string, fuzzy: boolean = false) { |
|
|
|
if (fuzzy) { |
|
|
|
const cmd = commandName.toLowerCase(); |
|
|
|
return this.items.find(c => c.isFuzzyMatch(cmd)) ?? this.hiddenItems.find(c => c.isFuzzyMatch(cmd)); |
|
|
|
} |
|
|
|
|
|
|
|
return this.items.find(c => c.isMatch(commandName)) ?? this.hiddenItems.find(c => c.isMatch(commandName)); |
|
|
|
} |
|
|
|
|
|
|
|
setCommand(command: QuickCommand | undefined, via: 'menu' | 'command'): void { |
|
|
|
if (this._command != null) { |
|
|
|
this._command.picked = false; |
|
|
|
} |
|
|
|
|
|
|
|
if (command != null) { |
|
|
|
command.picked = true; |
|
|
|
command.pickedVia = via; |
|
|
|
} |
|
|
|
|
|
|
|
this._command = command; |
|
|
|
if (command != null) { |
|
|
|
void this.updateCommandUsage(command.key, Date.now()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private async updateCommandUsage(id: string, timestamp: number) { |
|
|
|
let usage = this.container.storage.getWorkspace<Usage>(WorkspaceState.GitCommandPaletteUsage); |
|
|
|
if (usage === undefined) { |
|
|
|
usage = Object.create(null) as Usage; |
|
|
|
} |
|
|
|
|
|
|
|
usage[id] = timestamp; |
|
|
|
await this.container.storage.storeWorkspace(WorkspaceState.GitCommandPaletteUsage, usage); |
|
|
|
} |
|
|
|
} |