Skip to content

Commit 96e06e7

Browse files
authored
Remove actions from graph (cursorless-dev#1374)
## Checklist - [ ] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [ ] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [ ] I have not broken the cheatsheet
1 parent 0d7b536 commit 96e06e7

File tree

17 files changed

+70
-78
lines changed

17 files changed

+70
-78
lines changed

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,22 @@ import ToggleBreakpoint from "./ToggleBreakpoint";
5353
import Wrap from "./Wrap";
5454
import WrapWithSnippet from "./WrapWithSnippet";
5555

56-
class Actions implements ActionRecord {
56+
export class Actions implements ActionRecord {
5757
constructor(private graph: Graph) {}
5858

59-
callAsFunction = new Call(this.graph);
60-
clearAndSetSelection = new Clear(this.graph);
59+
callAsFunction = new Call(this);
60+
clearAndSetSelection = new Clear(this);
6161
copyToClipboard = new CopyToClipboard(this.graph);
62-
cutToClipboard = new CutToClipboard(this.graph);
62+
cutToClipboard = new CutToClipboard(this);
6363
deselect = new Deselect(this.graph);
64-
editNew = new EditNew(this.graph);
65-
editNewLineAfter = new EditNewAfter(this.graph);
66-
editNewLineBefore = new EditNewBefore(this.graph);
64+
editNew = new EditNew(this.graph, this);
65+
editNewLineAfter = new EditNewAfter(this.graph, this);
66+
editNewLineBefore = new EditNewBefore(this.graph, this);
6767
executeCommand = new ExecuteCommand(this.graph);
6868
extractVariable = new ExtractVariable(this.graph);
69-
findInWorkspace = new FindInWorkspace(this.graph);
69+
findInWorkspace = new FindInWorkspace(this);
7070
foldRegion = new Fold(this.graph);
71-
followLink = new FollowLink(this.graph);
71+
followLink = new FollowLink(this);
7272
generateSnippet = new GenerateSnippet(this.graph);
7373
getText = new GetText(this.graph);
7474
highlight = new Highlight(this.graph);
@@ -78,18 +78,18 @@ class Actions implements ActionRecord {
7878
insertEmptyLineAfter = new InsertEmptyLineAfter(this.graph);
7979
insertEmptyLineBefore = new InsertEmptyLineBefore(this.graph);
8080
insertEmptyLinesAround = new InsertEmptyLinesAround(this.graph);
81-
insertSnippet = new InsertSnippet(this.graph);
81+
insertSnippet = new InsertSnippet(this.graph, this);
8282
moveToTarget = new Move(this.graph);
8383
outdentLine = new OutdentLine(this.graph);
84-
pasteFromClipboard = new PasteFromClipboard(this.graph);
85-
randomizeTargets = new Random(this.graph);
84+
pasteFromClipboard = new PasteFromClipboard(this.graph, this);
85+
randomizeTargets = new Random(this);
8686
remove = new Remove(this.graph);
8787
rename = new Rename(this.graph);
8888
replace = new Replace(this.graph);
8989
replaceWithTarget = new Bring(this.graph);
9090
revealDefinition = new RevealDefinition(this.graph);
9191
revealTypeDefinition = new RevealTypeDefinition(this.graph);
92-
reverseTargets = new Reverse(this.graph);
92+
reverseTargets = new Reverse(this);
9393
rewrapWithPairedDelimiter = new Rewrap(this.graph);
9494
scrollToBottom = new ScrollToBottom(this.graph);
9595
scrollToCenter = new ScrollToCenter(this.graph);
@@ -101,13 +101,11 @@ class Actions implements ActionRecord {
101101
showHover = new ShowHover(this.graph);
102102
showQuickFix = new ShowQuickFix(this.graph);
103103
showReferences = new ShowReferences(this.graph);
104-
sortTargets = new Sort(this.graph);
104+
sortTargets = new Sort(this);
105105
swapTargets = new Swap(this.graph);
106106
toggleLineBreakpoint = new ToggleBreakpoint(this.graph);
107107
toggleLineComment = new ToggleLineComment(this.graph);
108108
unfoldRegion = new Unfold(this.graph);
109109
wrapWithPairedDelimiter = new Wrap(this.graph);
110110
wrapWithSnippet = new WrapWithSnippet(this.graph);
111111
}
112-
113-
export default Actions;

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Target } from "../typings/target.types";
2-
import { Graph } from "../typings/Graph";
32
import { ensureSingleTarget } from "../util/targetUtils";
3+
import { Actions } from "./Actions";
44
import { Action, ActionReturnValue } from "./actions.types";
55

66
export default class Call implements Action {
7-
constructor(private graph: Graph) {
7+
constructor(private actions: Actions) {
88
this.run = this.run.bind(this);
99
}
1010

@@ -14,16 +14,13 @@ export default class Call implements Action {
1414
]): Promise<ActionReturnValue> {
1515
ensureSingleTarget(sources);
1616

17-
const { returnValue: texts } = await this.graph.actions.getText.run(
18-
[sources],
19-
{
20-
showDecorations: false,
21-
},
22-
);
17+
const { returnValue: texts } = await this.actions.getText.run([sources], {
18+
showDecorations: false,
19+
});
2320

2421
// NB: We unwrap and then rewrap the return value here so that we don't include the source mark
2522
const { thatSelections: thatMark } =
26-
await this.graph.actions.wrapWithPairedDelimiter.run(
23+
await this.actions.wrapWithPairedDelimiter.run(
2724
[destinations],
2825
texts[0] + "(",
2926
")",

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { ide } from "../singletons/ide.singleton";
21
import { PlainTarget } from "../processTargets/targets";
2+
import { ide } from "../singletons/ide.singleton";
33
import { Target } from "../typings/target.types";
4-
import { Graph } from "../typings/Graph";
54
import { setSelectionsAndFocusEditor } from "../util/setSelectionsAndFocusEditor";
65
import { ensureSingleEditor } from "../util/targetUtils";
6+
import { Actions } from "./Actions";
77
import { Action, ActionReturnValue } from "./actions.types";
88

99
export default class Clear implements Action {
10-
constructor(private graph: Graph) {
10+
constructor(private actions: Actions) {
1111
this.run = this.run.bind(this);
1212
}
1313

@@ -24,7 +24,7 @@ export default class Clear implements Action {
2424
}),
2525
);
2626

27-
const { thatTargets } = await this.graph.actions.remove.run([plainTargets]);
27+
const { thatTargets } = await this.actions.remove.run([plainTargets]);
2828

2929
if (thatTargets != null) {
3030
await setSelectionsAndFocusEditor(

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import {
77
} from "@cursorless/common";
88
import { ide } from "../singletons/ide.singleton";
99
import { Target } from "../typings/target.types";
10-
import { Graph } from "../typings/Graph";
10+
import { Actions } from "./Actions";
1111
import { Action, ActionReturnValue } from "./actions.types";
1212

1313
export class CutToClipboard implements Action {
14-
constructor(private graph: Graph) {
14+
constructor(private actions: Actions) {
1515
this.run = this.run.bind(this);
1616
}
1717

@@ -55,12 +55,9 @@ export class CutToClipboard implements Action {
5555

5656
const options = { showDecorations: false };
5757

58-
await this.graph.actions.copyToClipboard.run([targets], options);
58+
await this.actions.copyToClipboard.run([targets], options);
5959

60-
const { thatTargets } = await this.graph.actions.remove.run(
61-
[targets],
62-
options,
63-
);
60+
const { thatTargets } = await this.actions.remove.run([targets], options);
6461

6562
return { thatTargets };
6663
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
import { ide } from "../../singletons/ide.singleton";
21
import { containingLineIfUntypedStage } from "../../processTargets/modifiers/commonContainingScopeIfUntypedStages";
32
import PositionStage from "../../processTargets/modifiers/PositionStage";
43
import { ModifierStage } from "../../processTargets/PipelineStages.types";
5-
import { Target } from "../../typings/target.types";
4+
import { ide } from "../../singletons/ide.singleton";
65
import { Graph } from "../../typings/Graph";
6+
import { Target } from "../../typings/target.types";
77
import { setSelectionsAndFocusEditor } from "../../util/setSelectionsAndFocusEditor";
88
import { createThatMark, ensureSingleEditor } from "../../util/targetUtils";
9+
import { Actions } from "../Actions";
910
import { Action, ActionReturnValue } from "../actions.types";
1011
import { State } from "./EditNew.types";
11-
import { runInsertLineAfterTargets } from "./runInsertLineAfterTargets";
1212
import { runEditTargets } from "./runEditTargets";
13+
import { runInsertLineAfterTargets } from "./runInsertLineAfterTargets";
1314
import { runEditNewNotebookCellTargets } from "./runNotebookCellTargets";
1415

1516
export class EditNew implements Action {
1617
getFinalStages(): ModifierStage[] {
1718
return [containingLineIfUntypedStage];
1819
}
1920

20-
constructor(private graph: Graph) {
21+
constructor(private graph: Graph, private actions: Actions) {
2122
this.run = this.run.bind(this);
2223
}
2324

@@ -26,7 +27,7 @@ export class EditNew implements Action {
2627
// It is not possible to "pour" a notebook cell and something else,
2728
// because each notebook cell is its own editor, and you can't have
2829
// cursors in multiple editors.
29-
return runEditNewNotebookCellTargets(this.graph, targets);
30+
return runEditNewNotebookCellTargets(this.actions, targets);
3031
}
3132

3233
const editableEditor = ide().getEditableTextEditor(

packages/cursorless-engine/src/actions/EditNew/runNotebookCellTargets.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { Selection } from "@cursorless/common";
2-
import { ide } from "../../singletons/ide.singleton";
32
import { NotebookCellPositionTarget } from "../../processTargets/targets";
3+
import { ide } from "../../singletons/ide.singleton";
44
import { Target } from "../../typings/target.types";
5-
import { Graph } from "../../typings/Graph";
65
import { createThatMark, ensureSingleTarget } from "../../util/targetUtils";
6+
import { Actions } from "../Actions";
77
import { ActionReturnValue } from "../actions.types";
88

99
export async function runEditNewNotebookCellTargets(
10-
graph: Graph,
10+
actions: Actions,
1111
targets: Target[],
1212
): Promise<ActionReturnValue> {
1313
// Can only run on one target because otherwise we'd end up with cursors in
@@ -16,7 +16,7 @@ export async function runEditNewNotebookCellTargets(
1616
const editor = ide().getEditableTextEditor(target.editor);
1717
const isAbove = target.position === "before";
1818

19-
await graph.actions.setSelection.run([targets]);
19+
await actions.setSelection.run([targets]);
2020

2121
let modifyThatMark = (selection: Selection) => selection;
2222
if (isAbove) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { showWarning } from "@cursorless/common";
22
import { ide } from "../singletons/ide.singleton";
33
import { Target } from "../typings/target.types";
4-
import { Graph } from "../typings/Graph";
54
import { ensureSingleTarget } from "../util/targetUtils";
5+
import { Actions } from "./Actions";
66
import { Action, ActionReturnValue } from "./actions.types";
77

88
export class FindInWorkspace implements Action {
9-
constructor(private graph: Graph) {
9+
constructor(private actions: Actions) {
1010
this.run = this.run.bind(this);
1111
}
1212

1313
async run([targets]: [Target[]]): Promise<ActionReturnValue> {
1414
ensureSingleTarget(targets);
1515

16-
const { returnValue, thatTargets } = await this.graph.actions.getText.run([
16+
const { returnValue, thatTargets } = await this.actions.getText.run([
1717
targets,
1818
]);
1919
const [text] = returnValue as [string];

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { FlashStyle } from "@cursorless/common";
22
import { ide } from "../singletons/ide.singleton";
33
import { Target } from "../typings/target.types";
4-
import { Graph } from "../typings/Graph";
54
import {
65
createThatMark,
76
ensureSingleTarget,
87
flashTargets,
98
} from "../util/targetUtils";
9+
import { Actions } from "./Actions";
1010
import { Action, ActionReturnValue } from "./actions.types";
1111

1212
export default class FollowLink implements Action {
13-
constructor(private graph: Graph) {
13+
constructor(private actions: Actions) {
1414
this.run = this.run.bind(this);
1515
}
1616

@@ -24,7 +24,7 @@ export default class FollowLink implements Action {
2424
.openLink(target.contentRange);
2525

2626
if (!openedLink) {
27-
await this.graph.actions.executeCommand.run(
27+
await this.actions.executeCommand.run(
2828
[targets],
2929
"editor.action.revealDefinition",
3030
{ restoreSelection: false },

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { SnippetParser } from "../snippets/vendor/vscodeSnippet/snippetParser";
1919
import { Graph } from "../typings/Graph";
2020
import { Target } from "../typings/target.types";
2121
import { ensureSingleEditor } from "../util/targetUtils";
22+
import { Actions } from "./Actions";
2223
import { Action, ActionReturnValue } from "./actions.types";
2324

2425
interface NamedSnippetArg {
@@ -37,7 +38,7 @@ type InsertSnippetArg = NamedSnippetArg | CustomSnippetArg;
3738
export default class InsertSnippet implements Action {
3839
private snippetParser = new SnippetParser();
3940

40-
constructor(private graph: Graph) {
41+
constructor(private graph: Graph, private actions: Actions) {
4142
this.run = this.run.bind(this);
4243
}
4344

@@ -131,7 +132,7 @@ export default class InsertSnippet implements Action {
131132

132133
const snippetString = parsedSnippet.toTextmateString();
133134

134-
await this.graph.actions.editNew.run([targets]);
135+
await this.actions.editNew.run([targets]);
135136

136137
const targetSelectionInfos = editor.selections.map((selection) =>
137138
getSelectionInfo(

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import {
88
callFunctionAndUpdateSelectionsWithBehavior,
99
} from "../core/updateSelections/updateSelections";
1010
import { ide } from "../singletons/ide.singleton";
11-
import { Target } from "../typings/target.types";
1211
import { Graph } from "../typings/Graph";
12+
import { Target } from "../typings/target.types";
1313
import { setSelectionsWithoutFocusingEditor } from "../util/setSelectionsAndFocusEditor";
1414
import { ensureSingleEditor } from "../util/targetUtils";
15+
import { Actions } from "./Actions";
1516
import { ActionReturnValue } from "./actions.types";
1617

1718
export class PasteFromClipboard {
18-
constructor(private graph: Graph) {}
19+
constructor(private graph: Graph, private actions: Actions) {}
1920

2021
async run([targets]: [Target[]]): Promise<ActionReturnValue> {
2122
const editor = ide().getEditableTextEditor(ensureSingleEditor(targets));
@@ -27,7 +28,7 @@ export class PasteFromClipboard {
2728
const [originalCursorSelections] = await callFunctionAndUpdateSelections(
2829
this.graph.rangeUpdater,
2930
async () => {
30-
await this.graph.actions.editNew.run([targets]);
31+
await this.actions.editNew.run([targets]);
3132
},
3233
editor.document,
3334
[editor.selections],

0 commit comments

Comments
 (0)