Skip to content

Commit b248af6

Browse files
Clean up types
1 parent 3817301 commit b248af6

File tree

3 files changed

+554
-47
lines changed

3 files changed

+554
-47
lines changed

packages/common/src/types/command/legacy/ActionDescriptorV6.ts

Lines changed: 25 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import type { DestinationDescriptorV6 } from "./DestinationDescriptorV6.types";
12
import type {
2-
PartialTargetDescriptor,
3-
ScopeType,
4-
} from "../PartialTargetDescriptor.types";
5-
import type { DestinationDescriptor } from "../DestinationDescriptor.types";
3+
PartialTargetDescriptorV6,
4+
ScopeTypeV6,
5+
} from "./PartialTargetDescriptorV6.types";
66

77
/**
88
* A simple action takes only a single target and no other arguments.
99
*/
10-
const simpleActionNames = [
10+
const _simpleActionNames = [
1111
"addSelection",
1212
"addSelectionAfter",
1313
"addSelectionBefore",
@@ -60,42 +60,20 @@ const simpleActionNames = [
6060
"private.showParseTree",
6161
] as const;
6262

63-
const complexActionNames = [
64-
"callAsFunction",
65-
"editNew",
66-
"executeCommand",
67-
"generateSnippet",
68-
"getText",
69-
"highlight",
70-
"insertSnippet",
71-
"moveToTarget",
72-
"pasteFromClipboard",
73-
"replace",
74-
"replaceWithTarget",
75-
"rewrapWithPairedDelimiter",
76-
"swapTargets",
77-
"wrapWithPairedDelimiter",
78-
"wrapWithSnippet",
79-
"parsed",
80-
] as const;
81-
82-
const actionNames = [...simpleActionNames, ...complexActionNames] as const;
83-
84-
type SimpleActionName = (typeof simpleActionNames)[number];
85-
type ActionType = (typeof actionNames)[number];
63+
type SimpleActionName = (typeof _simpleActionNames)[number];
8664

8765
/**
8866
* A simple action takes only a single target and no other arguments.
8967
*/
9068
interface SimpleActionDescriptor {
9169
name: SimpleActionName;
92-
target: PartialTargetDescriptor;
70+
target: PartialTargetDescriptorV6;
9371
}
9472

9573
interface BringMoveActionDescriptor {
9674
name: "replaceWithTarget" | "moveToTarget";
97-
source: PartialTargetDescriptor;
98-
destination: DestinationDescriptor;
75+
source: PartialTargetDescriptorV6;
76+
destination: DestinationDescriptorV6;
9977
}
10078

10179
interface CallActionDescriptor {
@@ -104,37 +82,37 @@ interface CallActionDescriptor {
10482
/**
10583
* The target to use as the function to be called.
10684
*/
107-
callee: PartialTargetDescriptor;
85+
callee: PartialTargetDescriptorV6;
10886

10987
/**
11088
* The target to wrap in a function call.
11189
*/
112-
argument: PartialTargetDescriptor;
90+
argument: PartialTargetDescriptorV6;
11391
}
11492

11593
interface SwapActionDescriptor {
11694
name: "swapTargets";
117-
target1: PartialTargetDescriptor;
118-
target2: PartialTargetDescriptor;
95+
target1: PartialTargetDescriptorV6;
96+
target2: PartialTargetDescriptorV6;
11997
}
12098

12199
interface WrapWithPairedDelimiterActionDescriptor {
122100
name: "wrapWithPairedDelimiter" | "rewrapWithPairedDelimiter";
123101
left: string;
124102
right: string;
125-
target: PartialTargetDescriptor;
103+
target: PartialTargetDescriptorV6;
126104
}
127105

128106
interface PasteActionDescriptor {
129107
name: "pasteFromClipboard";
130-
destination: DestinationDescriptor;
108+
destination: DestinationDescriptorV6;
131109
}
132110

133111
interface GenerateSnippetActionDescriptor {
134112
name: "generateSnippet";
135113
dirPath?: string;
136114
snippetName?: string;
137-
target: PartialTargetDescriptor;
115+
target: PartialTargetDescriptorV6;
138116
}
139117

140118
interface NamedInsertSnippetArg {
@@ -145,15 +123,15 @@ interface NamedInsertSnippetArg {
145123
interface CustomInsertSnippetArg {
146124
type: "custom";
147125
body: string;
148-
scopeTypes?: ScopeType[];
126+
scopeTypes?: ScopeTypeV6[];
149127
substitutions?: Record<string, string>;
150128
}
151129
type InsertSnippetArg = NamedInsertSnippetArg | CustomInsertSnippetArg;
152130

153131
interface InsertSnippetActionDescriptor {
154132
name: "insertSnippet";
155133
snippetDescription: InsertSnippetArg;
156-
destination: DestinationDescriptor;
134+
destination: DestinationDescriptorV6;
157135
}
158136

159137
interface NamedWrapWithSnippetArg {
@@ -165,14 +143,14 @@ interface CustomWrapWithSnippetArg {
165143
type: "custom";
166144
body: string;
167145
variableName?: string;
168-
scopeType?: ScopeType;
146+
scopeType?: ScopeTypeV6;
169147
}
170148
type WrapWithSnippetArg = NamedWrapWithSnippetArg | CustomWrapWithSnippetArg;
171149

172150
interface WrapWithSnippetActionDescriptor {
173151
name: "wrapWithSnippet";
174152
snippetDescription: WrapWithSnippetArg;
175-
target: PartialTargetDescriptor;
153+
target: PartialTargetDescriptorV6;
176154
}
177155

178156
interface ExecuteCommandOptions {
@@ -187,26 +165,26 @@ interface ExecuteCommandActionDescriptor {
187165
name: "executeCommand";
188166
commandId: string;
189167
options?: ExecuteCommandOptions;
190-
target: PartialTargetDescriptor;
168+
target: PartialTargetDescriptorV6;
191169
}
192170

193171
type ReplaceWith = string[] | { start: number };
194172

195173
interface ReplaceActionDescriptor {
196174
name: "replace";
197175
replaceWith: ReplaceWith;
198-
destination: DestinationDescriptor;
176+
destination: DestinationDescriptorV6;
199177
}
200178

201179
interface HighlightActionDescriptor {
202180
name: "highlight";
203181
highlightId?: string;
204-
target: PartialTargetDescriptor;
182+
target: PartialTargetDescriptorV6;
205183
}
206184

207185
interface EditNewActionDescriptor {
208186
name: "editNew";
209-
destination: DestinationDescriptor;
187+
destination: DestinationDescriptorV6;
210188
}
211189

212190
interface GetTextActionOptions {
@@ -217,7 +195,7 @@ interface GetTextActionOptions {
217195
interface GetTextActionDescriptor {
218196
name: "getText";
219197
options?: GetTextActionOptions;
220-
target: PartialTargetDescriptor;
198+
target: PartialTargetDescriptorV6;
221199
}
222200

223201
interface ParsedActionDescriptor {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import type {
2+
PartialListTargetDescriptorV6,
3+
PartialPrimitiveTargetDescriptorV6,
4+
PartialRangeTargetDescriptorV6,
5+
} from "./PartialTargetDescriptorV6.types";
6+
7+
/**
8+
* The insertion mode to use when inserting relative to a target.
9+
* - `before` inserts before the target. Depending on the target, a delimiter
10+
* may be inserted after the inserted text.
11+
* - `after` inserts after the target. Depending on the target, a delimiter may
12+
* be inserted before the inserted text.
13+
* - `to` replaces the target. However, this insertion mode may also be used
14+
* when the target is really only a pseudo-target. For example, you could say
15+
* `"bring type air to bat"` even if `bat` doesn't already have a type. In
16+
* that case, `"take type bat"` wouldn't work, so `"type bat"` is really just
17+
* a pseudo-target in that situation.
18+
*/
19+
type InsertionMode = "before" | "after" | "to";
20+
21+
interface PrimitiveDestinationDescriptor {
22+
type: "primitive";
23+
24+
/**
25+
* The insertion mode to use when inserting relative to {@link target}.
26+
*/
27+
insertionMode: InsertionMode;
28+
29+
target:
30+
| PartialPrimitiveTargetDescriptorV6
31+
| PartialRangeTargetDescriptorV6
32+
| PartialListTargetDescriptorV6;
33+
}
34+
35+
/**
36+
* A list of destinations. This is used when the user uses more than one insertion mode
37+
* in a single command. For example, `"bring air after bat and before cap"`.
38+
*/
39+
interface ListDestinationDescriptor {
40+
type: "list";
41+
destinations: PrimitiveDestinationDescriptor[];
42+
}
43+
44+
/**
45+
* An implicit destination. This is used for e.g. `"bring air"` (note the user
46+
* doesn't explicitly specify the destination), or `"snip funk"`.
47+
*/
48+
interface ImplicitDestinationDescriptor {
49+
type: "implicit";
50+
}
51+
52+
export type DestinationDescriptorV6 =
53+
| ListDestinationDescriptor
54+
| PrimitiveDestinationDescriptor
55+
| ImplicitDestinationDescriptor;

0 commit comments

Comments
 (0)