Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added git actions #2821

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cursorless-talon/src/spoken_forms.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
"fold": "foldRegion",
"follow split": "followLinkAside",
"follow": "followLink",
"git accept": "gitAccept",
"git add": "gitStage",
"git reset": "gitUnstage",
"git revert": "gitRevert",
"give": "deselect",
"highlight": "highlight",
"hover": "showHover",
Expand Down
4 changes: 4 additions & 0 deletions packages/common/src/ide/fake/FakeCapabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ export class FakeCapabilities implements Capabilities {
unfold: undefined,
showReferences: undefined,
insertLineAfter: undefined,
gitAccept: undefined,
gitRevert: undefined,
gitStage: undefined,
gitUnstage: undefined,
};
}
6 changes: 5 additions & 1 deletion packages/common/src/ide/types/CommandId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ export type CommandId =
| "showHover"
| "showDebugHover"
| "extractVariable"
| "insertLineAfter";
| "insertLineAfter"
| "gitAccept"
| "gitRevert"
| "gitStage"
| "gitUnstage";
24 changes: 24 additions & 0 deletions packages/common/src/types/TextEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,28 @@ export interface EditableTextEditor extends TextEditor {
* @param range A {@link Range range}
*/
extractVariable(range?: Range): Promise<void>;

/**
* Git accept conflict
* @param range A {@link Range range}
*/
gitAccept(range?: Range): Promise<void>;

/**
* Git revert
* @param range A {@link Range range}
*/
gitRevert(range?: Range): Promise<void>;

/**
* Git stage
* @param range A {@link Range range}
*/
gitStage(range?: Range): Promise<void>;

/**
* Git unstage
* @param range A {@link Range range}
*/
gitUnstage(range?: Range): Promise<void>;
}
4 changes: 4 additions & 0 deletions packages/common/src/types/command/ActionDescriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export const simpleActionNames = [
"foldRegion",
"followLink",
"followLinkAside",
"gitAccept",
"gitRevert",
"gitStage",
"gitUnstage",
"increment",
"indentLine",
"insertCopyAfter",
Expand Down
4 changes: 4 additions & 0 deletions packages/cursorless-engine/src/CommandHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ function sanitizeActionInPlace(action: ActionDescriptor): void {
case "followLinkAside":
case "generateSnippet":
case "getText":
case "gitAccept":
case "gitRevert":
case "gitStage":
case "gitUnstage":
case "highlight":
case "increment":
case "indentLine":
Expand Down
18 changes: 14 additions & 4 deletions packages/cursorless-engine/src/actions/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ import ShowParseTree from "./ShowParseTree";
import {
ExtractVariable,
Fold,
GitAccept,
GitRevert,
GitStage,
GitUnstage,
Rename,
RevealDefinition,
RevealTypeDefinition,
Expand Down Expand Up @@ -105,6 +109,10 @@ export class Actions implements ActionRecord {
followLinkAside = new FollowLink({ openAside: true });
generateSnippet = new GenerateSnippet(this.snippets);
getText = new GetText();
gitAccept = new GitAccept(this.rangeUpdater);
gitRevert = new GitRevert(this.rangeUpdater);
gitStage = new GitStage(this.rangeUpdater);
gitUnstage = new GitUnstage(this.rangeUpdater);
highlight = new Highlight();
increment = new Increment(this);
indentLine = new IndentLine(this.rangeUpdater);
Expand Down Expand Up @@ -154,10 +162,6 @@ export class Actions implements ActionRecord {
scrollToBottom = new ScrollToBottom();
scrollToCenter = new ScrollToCenter();
scrollToTop = new ScrollToTop();
["private.setKeyboardTarget"] = new SetSpecialTarget("keyboard");
["experimental.setInstanceReference"] = new SetSpecialTarget(
"instanceReference",
);
setSelection = new SetSelection();
setSelectionAfter = new SetSelectionAfter();
setSelectionBefore = new SetSelectionBefore();
Expand All @@ -176,6 +180,12 @@ export class Actions implements ActionRecord {
this.snippets,
this.modifierStageFactory,
);

["experimental.setInstanceReference"] = new SetSpecialTarget(
"instanceReference",
);

["private.showParseTree"] = new ShowParseTree(this.treeSitter);
["private.getTargets"] = new GetTargets();
["private.setKeyboardTarget"] = new SetSpecialTarget("keyboard");
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,26 @@ export class ExtractVariable extends SimpleIdeCommandAction {
restoreSelection = false;
}

export class GitAccept extends SimpleIdeCommandAction {
command: CommandId = "gitAccept";
ensureSingleTarget = true;
}

export class GitRevert extends SimpleIdeCommandAction {
command: CommandId = "gitRevert";
ensureSingleTarget = true;
}

export class GitStage extends SimpleIdeCommandAction {
command: CommandId = "gitStage";
ensureSingleTarget = true;
}

export class GitUnstage extends SimpleIdeCommandAction {
command: CommandId = "gitUnstage";
ensureSingleTarget = true;
}

function callback(
editor: EditableTextEditor,
ranges: Range[] | undefined,
Expand Down Expand Up @@ -167,6 +187,14 @@ function callback(
return editor.showDebugHover(ranges?.[0]);
case "extractVariable":
return editor.extractVariable(ranges?.[0]);
case "gitAccept":
return editor.gitAccept(ranges?.[0]);
case "gitRevert":
return editor.gitRevert(ranges?.[0]);
case "gitStage":
return editor.gitStage(ranges?.[0]);
case "gitUnstage":
return editor.gitUnstage(ranges?.[0]);

// Unsupported as simple action
case "highlight":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ export const defaultSpokenFormMapCore: DefaultSpokenFormMapDefinition = {
insertSnippet: "snippet",
pasteFromClipboard: "paste",
joinLines: "join",
gitAccept: "git accept",
gitRevert: "git revert",
gitStage: "git add",
gitUnstage: "git reset",

["private.showParseTree"]: isPrivate("parse tree"),
["experimental.setInstanceReference"]: isDisabledByDefault("from"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ const COMMAND_CAPABILITIES: CommandCapabilityMap = {
insertLineAfter: undefined,
indentLine: undefined,
outdentLine: undefined,
gitAccept: undefined,
gitRevert: undefined,
gitStage: undefined,
gitUnstage: undefined,
};

export class TalonJsCapabilities implements Capabilities {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,20 @@ export class TalonJsEditor implements EditableTextEditor {
editNewNotebookCellBelow(): Promise<void> {
throw new Error("editNewNotebookCellBelow not implemented.");
}

public async gitAccept(_range?: Range): Promise<void> {
throw Error("gitAccept not implemented");
}

public async gitRevert(_range?: Range): Promise<void> {
throw Error("gitRevert not implemented");
}

public async gitStage(_range?: Range): Promise<void> {
throw Error("gitStage not implemented");
}

public async gitUnstage(_range?: Range): Promise<void> {
throw Error("gitUnstage not implemented");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ const COMMAND_CAPABILITIES: CommandCapabilityMap = {
unfold: { acceptsLocation: true },
showReferences: { acceptsLocation: false },
insertLineAfter: { acceptsLocation: false },
gitAccept: { acceptsLocation: false },
gitRevert: { acceptsLocation: false },
gitStage: { acceptsLocation: false },
gitUnstage: { acceptsLocation: false },
};

export class VscodeCapabilities implements Capabilities {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,20 @@ export class VscodeTextEditorImpl implements EditableTextEditor {

await sleep(250);
}

public async gitAccept(_range?: Range): Promise<void> {
await vscode.commands.executeCommand("merge-conflict.accept.selection");
}

public async gitRevert(_range?: Range): Promise<void> {
await vscode.commands.executeCommand("git.revertSelectedRanges");
}

public async gitStage(_range?: Range): Promise<void> {
await vscode.commands.executeCommand("git.stageSelectedRanges");
}

public async gitUnstage(_range?: Range): Promise<void> {
await vscode.commands.executeCommand("git.unstageSelectedRanges");
}
}
4 changes: 4 additions & 0 deletions packages/neovim-common/src/ide/neovim/NeovimCapabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ const COMMAND_CAPABILITIES: CommandCapabilityMap = {
unfold: undefined,
showReferences: undefined,
insertLineAfter: undefined,
gitAccept: undefined,
gitRevert: undefined,
gitStage: undefined,
gitUnstage: undefined,
};

export class NeovimCapabilities implements Capabilities {
Expand Down
16 changes: 16 additions & 0 deletions packages/neovim-common/src/ide/neovim/NeovimTextEditorImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,20 @@ export class NeovimTextEditorImpl implements EditableTextEditor {
public async extractVariable(_range?: Range): Promise<void> {
throw Error("extractVariable Not implemented");
}

public async gitAccept(_range?: Range): Promise<void> {
throw Error("gitAccept Not implemented");
}

public async gitRevert(_range?: Range): Promise<void> {
throw Error("gitRevert Not implemented");
}

public async gitStage(_range?: Range): Promise<void> {
throw Error("gitStage Not implemented");
}

public async gitUnstage(_range?: Range): Promise<void> {
throw Error("gitUnstage Not implemented");
}
}
Loading