Skip to content

Commit da757c2

Browse files
authored
Initial work for smarter that marks (#957)
* Initial work for smarter `that` marks * No target serialization default attribute removal * test transformer [to remove] * Run transformation script on that and source marks
1 parent 9195c6a commit da757c2

File tree

291 files changed

+2427
-835
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

291 files changed

+2427
-835
lines changed

src/actions/BringMoveSwap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class BringMoveSwap implements Action {
261261

262262
await this.decorateThatMark(thatMark);
263263

264-
return { thatMark, sourceMark };
264+
return { thatSelections: thatMark, sourceSelections: sourceMark };
265265
}
266266
}
267267

src/actions/Call.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ export default class Call implements Action {
2222
);
2323

2424
// NB: We unwrap and then rewrap the return value here so that we don't include the source mark
25-
const { thatMark } = await this.graph.actions.wrapWithPairedDelimiter.run(
26-
[destinations],
27-
texts[0] + "(",
28-
")"
29-
);
25+
const { thatSelections: thatMark } =
26+
await this.graph.actions.wrapWithPairedDelimiter.run(
27+
[destinations],
28+
texts[0] + "(",
29+
")"
30+
);
3031

31-
return { thatMark };
32+
return { thatSelections: thatMark };
3233
}
3334
}

src/actions/Clear.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ export default class Clear implements Action {
2323
})
2424
);
2525

26-
const { thatMark } = await this.graph.actions.remove.run([plainTargets]);
26+
const { thatSelections: thatMark } = await this.graph.actions.remove.run([
27+
plainTargets,
28+
]);
2729

2830
if (thatMark != null) {
2931
await setSelectionsAndFocusEditor(
@@ -32,6 +34,6 @@ export default class Clear implements Action {
3234
);
3335
}
3436

35-
return { thatMark };
37+
return { thatSelections: thatMark };
3638
}
3739
}

src/actions/CommandAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,6 @@ export default class CommandAction implements Action {
129129
await focusEditor(originalEditor);
130130
}
131131

132-
return { thatMark };
132+
return { thatSelections: thatMark };
133133
}
134134
}

src/actions/CutCopy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ export class Cut implements Action {
4242

4343
await this.graph.actions.copyToClipboard.run([targets], options);
4444

45-
const { thatMark } = await this.graph.actions.remove.run(
45+
const { thatSelections: thatMark } = await this.graph.actions.remove.run(
4646
[targets],
4747
options
4848
);
4949

50-
return { thatMark };
50+
return { thatSelections: thatMark };
5151
}
5252
}
5353

src/actions/Deselect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default class Deselect implements Action {
3030
});
3131

3232
return {
33-
thatMark: createThatMark(targets),
33+
thatSelections: createThatMark(targets),
3434
};
3535
}
3636
}

src/actions/EditNew/EditNew.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class EditNew implements Action {
5050
await setSelectionsAndFocusEditor(editor, newSelections);
5151

5252
return {
53-
thatMark: createThatMark(state.targets, state.thatRanges),
53+
thatSelections: createThatMark(state.targets, state.thatRanges),
5454
};
5555
}
5656
}

src/actions/EditNew/runNotebookCellTargets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ export async function runNotebookCellTargets(
2525
);
2626
}
2727

28-
return { thatMark };
28+
return { thatSelections: thatMark };
2929
}

src/actions/Find.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ export class FindInFiles implements Action {
1414

1515
const {
1616
returnValue: [query],
17-
thatMark,
17+
thatSelections: thatMark,
1818
} = await this.graph.actions.getText.run([targets]);
1919

2020
await commands.executeCommand("workbench.action.findInFiles", {
2121
query,
2222
});
2323

24-
return { thatMark };
24+
return { thatSelections: thatMark };
2525
}
2626
}

src/actions/Fold.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class FoldAction implements Action {
4545
}
4646

4747
return {
48-
thatMark: createThatMark(targets),
48+
thatSelections: createThatMark(targets),
4949
};
5050
}
5151
}

src/actions/FollowLink.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default class FollowLink implements Action {
3030
}
3131

3232
return {
33-
thatMark: createThatMark(targets),
33+
thatSelections: createThatMark(targets),
3434
};
3535
}
3636

src/actions/GenerateSnippet/GenerateSnippet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export default class GenerateSnippet implements Action {
229229
});
230230

231231
return {
232-
thatMark: targets.map(({ editor, contentSelection }) => ({
232+
thatSelections: targets.map(({ editor, contentSelection }) => ({
233233
editor,
234234
selection: contentSelection,
235235
})),

src/actions/GetText.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default class GetText implements Action {
2828

2929
return {
3030
returnValue: targets.map((target) => target.contentText),
31-
thatMark: createThatMark(targets),
31+
thatSelections: createThatMark(targets),
3232
};
3333
}
3434
}

src/actions/Highlight.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default class Highlight implements Action {
1919
await this.graph.editStyles.setDecorations(targets, style);
2020

2121
return {
22-
thatMark: createThatMark(targets),
22+
thatSelections: createThatMark(targets),
2323
};
2424
}
2525
}

src/actions/InsertCopy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class InsertCopy implements Action {
3333
);
3434

3535
return {
36-
sourceMark: results.flatMap(({ sourceMark }) => sourceMark),
37-
thatMark: results.flatMap(({ thatMark }) => thatMark),
36+
sourceSelections: results.flatMap(({ sourceMark }) => sourceMark),
37+
thatSelections: results.flatMap(({ thatMark }) => thatMark),
3838
};
3939
}
4040

src/actions/InsertEmptyLines.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class InsertEmptyLines implements Action {
8787

8888
const thatMark = results.flatMap((result) => result.thatMark);
8989

90-
return { thatMark };
90+
return { thatSelections: thatMark };
9191
}
9292
}
9393

src/actions/InsertSnippet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export default class InsertSnippet implements Action {
9696
);
9797

9898
return {
99-
thatMark: updatedTargetSelections.map((selection) => ({
99+
thatSelections: updatedTargetSelections.map((selection) => ({
100100
editor,
101101
selection,
102102
})),

src/actions/Paste.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class Paste {
7272
);
7373

7474
return {
75-
thatMark: updatedTargetSelections.map((selection) => ({
75+
thatSelections: updatedTargetSelections.map((selection) => ({
7676
editor: targetEditor,
7777
selection,
7878
})),

src/actions/Remove.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ export default class Delete implements Action {
4242
})
4343
);
4444

45-
return { thatMark };
45+
return { thatSelections: thatMark };
4646
}
4747
}

src/actions/Replace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ export default class Replace implements Action {
7070
)
7171
);
7272

73-
return { thatMark };
73+
return { thatSelections: thatMark };
7474
}
7575
}

src/actions/Rewrap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ export default class Rewrap implements Action {
6060
);
6161

6262
return {
63-
sourceMark: results.flatMap(({ sourceMark }) => sourceMark),
64-
thatMark: results.flatMap(({ thatMark }) => thatMark),
63+
sourceSelections: results.flatMap(({ sourceMark }) => sourceMark),
64+
thatSelections: results.flatMap(({ thatMark }) => thatMark),
6565
};
6666
}
6767
}

src/actions/Scroll.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Scroll implements Action {
5656
);
5757

5858
return {
59-
thatMark: createThatMark(targets),
59+
thatSelections: createThatMark(targets),
6060
};
6161
}
6262
}

src/actions/SetSelection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class SetSelection implements Action {
2121
await setSelectionsAndFocusEditor(editor, selections);
2222

2323
return {
24-
thatMark: createThatMark(targets),
24+
thatSelections: createThatMark(targets),
2525
};
2626
}
2727
}

src/actions/ToggleBreakpoint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export default class ToggleBreakpoint implements Action {
6161
debug.removeBreakpoints(toRemove);
6262

6363
return {
64-
thatMark: createThatMark(thatTargets),
64+
thatSelections: createThatMark(thatTargets),
6565
};
6666
}
6767
}

src/actions/Wrap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ export default class Wrap implements Action {
127127
);
128128

129129
return {
130-
sourceMark: results.flatMap(({ sourceMark }) => sourceMark),
131-
thatMark: results.flatMap(({ thatMark }) => thatMark),
130+
sourceSelections: results.flatMap(({ sourceMark }) => sourceMark),
131+
thatSelections: results.flatMap(({ thatMark }) => thatMark),
132132
};
133133
}
134134
}

src/actions/WrapWithSnippet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export default class WrapWithSnippet implements Action {
8888
);
8989

9090
return {
91-
thatMark: updatedTargetSelections.map((selection) => ({
91+
thatSelections: updatedTargetSelections.map((selection) => ({
9292
editor,
9393
selection,
9494
})),

src/actions/actions.types.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,41 @@ export type ActionType =
5656
| "wrapWithPairedDelimiter"
5757
| "wrapWithSnippet";
5858

59+
/**
60+
* To be returned by {@link Action.run}
61+
*/
5962
export interface ActionReturnValue {
63+
/**
64+
* The value that should be returned to the caller of the command
65+
*/
6066
returnValue?: any;
61-
thatMark?: SelectionWithEditor[];
62-
sourceMark?: SelectionWithEditor[];
67+
68+
/**
69+
* A list of selections that will become the `that` mark for the next command.
70+
* The given selections will be wrapped in {@link UntypedTarget}s. This
71+
* attribute is provided for convenience. Mutually exclusive with
72+
* {@link thatTargets}
73+
*/
74+
thatSelections?: SelectionWithEditor[];
75+
76+
/**
77+
* A list of targets that will become the `that` mark for the next command.
78+
* Mutually exclusive with {@link thatSelections}
79+
*/
80+
thatTargets?: Target[];
81+
82+
/**
83+
* A list of selections that will become the `source` mark for the next command.
84+
* The given selections will be wrapped in {@link UntypedTarget}s. This
85+
* attribute is provided for convenience. Mutually exclusive with {@link sourceTargets}
86+
*/
87+
sourceSelections?: SelectionWithEditor[];
88+
89+
/**
90+
* A list of targets that will become the `source` mark for the next command.
91+
* Mutually exclusive with {@link sourceSelections}
92+
*/
93+
sourceTargets?: Target[];
6394
}
6495

6596
export interface Action {

src/core/ThatMark.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { SelectionWithEditor } from "../typings/Types";
1+
import { Target } from "../typings/target.types";
22

33
export class ThatMark {
4-
private mark?: SelectionWithEditor[];
4+
private mark?: Target[];
55

6-
set(value?: SelectionWithEditor[]) {
7-
this.mark = value;
6+
set(targets: Target[] | undefined) {
7+
this.mark = targets;
88
}
99

1010
get() {

src/core/commandRunner/CommandRunner.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ import { ActionType } from "../../actions/actions.types";
33
import { OutdatedExtensionError } from "../../errors";
44
import processTargets from "../../processTargets";
55
import isTesting from "../../testUtil/isTesting";
6-
import { Graph, ProcessedTargetsContext } from "../../typings/Types";
6+
import { Target } from "../../typings/target.types";
7+
import {
8+
Graph,
9+
ProcessedTargetsContext,
10+
SelectionWithEditor,
11+
} from "../../typings/Types";
712
import { isString } from "../../util/type";
813
import { canonicalizeAndValidateCommand } from "../commandVersionUpgrades/canonicalizeAndValidateCommand";
914
import { PartialTargetV0V1 } from "../commandVersionUpgrades/upgradeV1ToV2/commandV1.types";
1015
import inferFullTargets from "../inferFullTargets";
1116
import { ThatMark } from "../ThatMark";
1217
import { Command } from "./command.types";
18+
import { selectionToThatTarget } from "./selectionToThatTarget";
1319

1420
// TODO: Do this using the graph once we migrate its dependencies onto the graph
1521
export default class CommandRunner {
@@ -136,12 +142,16 @@ export default class CommandRunner {
136142

137143
const {
138144
returnValue,
139-
thatMark: newThatMark,
140-
sourceMark: newSourceMark,
145+
thatSelections: newThatSelections,
146+
thatTargets: newThatTargets,
147+
sourceSelections: newSourceSelections,
148+
sourceTargets: newSourceTargets,
141149
} = await action.run(targets, ...actionArgs);
142150

143-
this.thatMark.set(newThatMark);
144-
this.sourceMark.set(newSourceMark);
151+
this.thatMark.set(constructThatTarget(newThatTargets, newThatSelections));
152+
this.sourceMark.set(
153+
constructThatTarget(newSourceTargets, newSourceSelections)
154+
);
145155

146156
if (this.graph.testCaseRecorder.isActive()) {
147157
await this.graph.testCaseRecorder.postCommandHook(returnValue);
@@ -210,3 +220,20 @@ export default class CommandRunner {
210220
this.disposables.forEach(({ dispose }) => dispose());
211221
}
212222
}
223+
224+
function constructThatTarget(
225+
targets: Target[] | undefined,
226+
selections: SelectionWithEditor[] | undefined
227+
) {
228+
if (targets != null && selections != null) {
229+
throw Error(
230+
"Actions may only return full targets or selections for that mark"
231+
);
232+
}
233+
234+
if (selections != null) {
235+
return selections.map(selectionToThatTarget);
236+
} else {
237+
return targets;
238+
}
239+
}

0 commit comments

Comments
 (0)