Skip to content

Commit 09e4322

Browse files
Added git actions (#2821)
Fixes #2812 ## Release notes Added several new commends for manipulating your local changes with `git`: `"git stage <target>"` to stage changes `"git unstage <target>"` to unstage changes `"git revert <target>"` to revert changes `"git accept <target>"` to accept conflicts (`<target>`s can span multiple lines or even hunks of changes. When smaller than a line, VS Code will operate on the line containing the target.) --------- Co-authored-by: Phil Cohen <[email protected]>
1 parent e295399 commit 09e4322

File tree

15 files changed

+151
-5
lines changed

15 files changed

+151
-5
lines changed

cursorless-talon/src/spoken_forms.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
"fold": "foldRegion",
2929
"follow split": "followLinkAside",
3030
"follow": "followLink",
31+
"git accept": "gitAccept",
32+
"git stage": "gitStage",
33+
"git unstage": "gitUnstage",
34+
"git revert": "gitRevert",
3135
"give": "deselect",
3236
"highlight": "highlight",
3337
"hover": "showHover",

packages/common/src/ide/fake/FakeCapabilities.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,9 @@ export class FakeCapabilities implements Capabilities {
1919
unfold: undefined,
2020
showReferences: undefined,
2121
insertLineAfter: undefined,
22+
gitAccept: undefined,
23+
gitRevert: undefined,
24+
gitStage: undefined,
25+
gitUnstage: undefined,
2226
};
2327
}

packages/common/src/ide/types/CommandId.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ export type CommandId =
1414
| "showHover"
1515
| "showDebugHover"
1616
| "extractVariable"
17-
| "insertLineAfter";
17+
| "insertLineAfter"
18+
| "gitAccept"
19+
| "gitRevert"
20+
| "gitStage"
21+
| "gitUnstage";

packages/common/src/types/TextEditor.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,28 @@ export interface EditableTextEditor extends TextEditor {
237237
* @param range A {@link Range range}
238238
*/
239239
extractVariable(range?: Range): Promise<void>;
240+
241+
/**
242+
* Git accept conflict (use the range to resolve a conflict hunk)
243+
* @param range A {@link Range range}
244+
*/
245+
gitAccept(range?: Range): Promise<void>;
246+
247+
/**
248+
* Git revert range
249+
* @param range A {@link Range range}
250+
*/
251+
gitRevert(range?: Range): Promise<void>;
252+
253+
/**
254+
* Git stage range
255+
* @param range A {@link Range range}
256+
*/
257+
gitStage(range?: Range): Promise<void>;
258+
259+
/**
260+
* Git unstage range
261+
* @param range A {@link Range range}
262+
*/
263+
gitUnstage(range?: Range): Promise<void>;
240264
}

packages/common/src/types/command/ActionDescriptor.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export const simpleActionNames = [
2727
"foldRegion",
2828
"followLink",
2929
"followLinkAside",
30+
"gitAccept",
31+
"gitRevert",
32+
"gitStage",
33+
"gitUnstage",
3034
"increment",
3135
"indentLine",
3236
"insertCopyAfter",

packages/cursorless-engine/src/CommandHistory.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ function sanitizeActionInPlace(action: ActionDescriptor): void {
160160
case "followLinkAside":
161161
case "generateSnippet":
162162
case "getText":
163+
case "gitAccept":
164+
case "gitRevert":
165+
case "gitStage":
166+
case "gitUnstage":
163167
case "highlight":
164168
case "increment":
165169
case "indentLine":

packages/cursorless-engine/src/actions/Actions.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ import ShowParseTree from "./ShowParseTree";
4949
import {
5050
ExtractVariable,
5151
Fold,
52+
GitAccept,
53+
GitRevert,
54+
GitStage,
55+
GitUnstage,
5256
Rename,
5357
RevealDefinition,
5458
RevealTypeDefinition,
@@ -105,6 +109,10 @@ export class Actions implements ActionRecord {
105109
followLinkAside = new FollowLink({ openAside: true });
106110
generateSnippet = new GenerateSnippet(this.snippets);
107111
getText = new GetText();
112+
gitAccept = new GitAccept(this.rangeUpdater);
113+
gitRevert = new GitRevert(this.rangeUpdater);
114+
gitStage = new GitStage(this.rangeUpdater);
115+
gitUnstage = new GitUnstage(this.rangeUpdater);
108116
highlight = new Highlight();
109117
increment = new Increment(this);
110118
indentLine = new IndentLine(this.rangeUpdater);
@@ -154,10 +162,6 @@ export class Actions implements ActionRecord {
154162
scrollToBottom = new ScrollToBottom();
155163
scrollToCenter = new ScrollToCenter();
156164
scrollToTop = new ScrollToTop();
157-
["private.setKeyboardTarget"] = new SetSpecialTarget("keyboard");
158-
["experimental.setInstanceReference"] = new SetSpecialTarget(
159-
"instanceReference",
160-
);
161165
setSelection = new SetSelection();
162166
setSelectionAfter = new SetSelectionAfter();
163167
setSelectionBefore = new SetSelectionBefore();
@@ -176,6 +180,12 @@ export class Actions implements ActionRecord {
176180
this.snippets,
177181
this.modifierStageFactory,
178182
);
183+
184+
["experimental.setInstanceReference"] = new SetSpecialTarget(
185+
"instanceReference",
186+
);
187+
179188
["private.showParseTree"] = new ShowParseTree(this.treeSitter);
180189
["private.getTargets"] = new GetTargets();
190+
["private.setKeyboardTarget"] = new SetSpecialTarget("keyboard");
181191
}

packages/cursorless-engine/src/actions/SimpleIdeCommandActions.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,26 @@ export class ExtractVariable extends SimpleIdeCommandAction {
128128
restoreSelection = false;
129129
}
130130

131+
export class GitAccept extends SimpleIdeCommandAction {
132+
command: CommandId = "gitAccept";
133+
ensureSingleTarget = true;
134+
}
135+
136+
export class GitRevert extends SimpleIdeCommandAction {
137+
command: CommandId = "gitRevert";
138+
ensureSingleTarget = true;
139+
}
140+
141+
export class GitStage extends SimpleIdeCommandAction {
142+
command: CommandId = "gitStage";
143+
ensureSingleTarget = true;
144+
}
145+
146+
export class GitUnstage extends SimpleIdeCommandAction {
147+
command: CommandId = "gitUnstage";
148+
ensureSingleTarget = true;
149+
}
150+
131151
function callback(
132152
editor: EditableTextEditor,
133153
ranges: Range[] | undefined,
@@ -167,6 +187,14 @@ function callback(
167187
return editor.showDebugHover(ranges?.[0]);
168188
case "extractVariable":
169189
return editor.extractVariable(ranges?.[0]);
190+
case "gitAccept":
191+
return editor.gitAccept(ranges?.[0]);
192+
case "gitRevert":
193+
return editor.gitRevert(ranges?.[0]);
194+
case "gitStage":
195+
return editor.gitStage(ranges?.[0]);
196+
case "gitUnstage":
197+
return editor.gitUnstage(ranges?.[0]);
170198

171199
// Unsupported as simple action
172200
case "highlight":

packages/cursorless-engine/src/spokenForms/defaultSpokenFormMapCore.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ export const defaultSpokenFormMapCore: DefaultSpokenFormMapDefinition = {
204204
insertSnippet: "snippet",
205205
pasteFromClipboard: "paste",
206206
joinLines: "join",
207+
gitAccept: "git accept",
208+
gitRevert: "git revert",
209+
gitStage: "git stage",
210+
gitUnstage: "git unstage",
207211

208212
["private.showParseTree"]: isPrivate("parse tree"),
209213
["experimental.setInstanceReference"]: isDisabledByDefault("from"),

packages/cursorless-everywhere-talon-core/src/ide/TalonJsCapabilities.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ const COMMAND_CAPABILITIES: CommandCapabilityMap = {
1818
insertLineAfter: undefined,
1919
indentLine: undefined,
2020
outdentLine: undefined,
21+
gitAccept: undefined,
22+
gitRevert: undefined,
23+
gitStage: undefined,
24+
gitUnstage: undefined,
2125
};
2226

2327
export class TalonJsCapabilities implements Capabilities {

0 commit comments

Comments
 (0)