-
-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathgrammarUtil.ts
More file actions
119 lines (109 loc) · 2.89 KB
/
Copy pathgrammarUtil.ts
File metadata and controls
119 lines (109 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import type {
BringMoveActionDescriptor,
DestinationDescriptor,
Direction,
InsertionMode,
PartialListTargetDescriptor,
PartialRangeTargetDescriptor,
PartialTargetMark,
PrimitiveDestinationDescriptor,
RelativeScopeModifier,
} from "@cursorless/common";
import {
type ContainingScopeModifier,
type Modifier,
type PartialMark,
type PartialPrimitiveTargetDescriptor,
type PartialTargetDescriptor,
type ScopeType,
type SimpleActionDescriptor,
type SimpleActionName,
type SimplePartialMark,
type SimpleScopeType,
type SimpleScopeTypeType,
type SurroundingPairName,
type SurroundingPairScopeType,
} from "@cursorless/common";
import type { WithPlaceholders } from "./WithPlaceholders";
export function simpleActionDescriptor(
name: SimpleActionName,
target: WithPlaceholders<PartialTargetDescriptor>,
): WithPlaceholders<SimpleActionDescriptor> {
return { name, target };
}
export function bringMoveActionDescriptor(
name: BringMoveActionDescriptor["name"],
source: WithPlaceholders<PartialTargetDescriptor>,
destination: WithPlaceholders<DestinationDescriptor>,
): WithPlaceholders<BringMoveActionDescriptor> {
return { name, source, destination };
}
export function partialPrimitiveTargetDescriptor(
modifiers: Modifier[] | undefined,
mark: WithPlaceholders<PartialMark> | undefined,
): WithPlaceholders<PartialPrimitiveTargetDescriptor> {
const target: WithPlaceholders<PartialPrimitiveTargetDescriptor> = {
type: "primitive",
};
if (modifiers != null) {
target.modifiers = modifiers;
}
if (mark != null) {
target.mark = mark;
}
return target;
}
export function primitiveDestinationDescriptor(
insertionMode: InsertionMode,
target: WithPlaceholders<
| PartialPrimitiveTargetDescriptor
| PartialListTargetDescriptor
| PartialRangeTargetDescriptor
>,
): WithPlaceholders<PrimitiveDestinationDescriptor> {
return { type: "primitive", insertionMode, target };
}
export function containingScopeModifier(
scopeType: ScopeType,
): ContainingScopeModifier {
return {
type: "containingScope",
scopeType,
};
}
export function relativeScopeModifier(
scopeType: ScopeType,
direction: Direction,
): RelativeScopeModifier {
return {
type: "relativeScope",
scopeType,
offset: 1,
length: 1,
direction,
};
}
export function simpleScopeType(type: SimpleScopeTypeType): SimpleScopeType {
return { type };
}
export function surroundingPairScopeType(
delimiter: SurroundingPairName,
): SurroundingPairScopeType {
return { type: "surroundingPair", delimiter };
}
export function simplePartialMark(
type: SimplePartialMark["type"],
): SimplePartialMark {
return { type };
}
export function createPlaceholderTarget(
index: string,
): WithPlaceholders<PartialTargetMark> {
return {
type: "target",
target: {
type: "placeholder",
index: index.length === 0 ? 0 : parseInt(index) - 1,
},
};
}