Skip to content

Commit 9624efb

Browse files
Added trim-end-optional! predicate (#3373)
1 parent c4ad41f commit 9624efb

15 files changed

Lines changed: 480 additions & 57 deletions

‎packages/app-web-docs/src/docs/user/languages/fixtures/markdown.json‎

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,54 @@
2323
}
2424
]
2525
},
26+
{
27+
"name": "scopes/markdown/collectionItem.unenclosed.iteration2",
28+
"languageId": "markdown",
29+
"facet": "collectionItem.unenclosed.iteration",
30+
"code": "- First item\n Paragraph\n- Second item",
31+
"scopes": [
32+
{
33+
"targets": [
34+
{
35+
"content": "0:0-2:13"
36+
}
37+
],
38+
"domain": "0:0-2:13"
39+
}
40+
]
41+
},
42+
{
43+
"name": "scopes/markdown/collectionItem.unenclosed.iteration3",
44+
"languageId": "markdown",
45+
"facet": "collectionItem.unenclosed.iteration",
46+
"code": "- [ ] First item\n- [ ] Second item",
47+
"scopes": [
48+
{
49+
"targets": [
50+
{
51+
"content": "0:0-1:17"
52+
}
53+
],
54+
"domain": "0:0-1:17"
55+
},
56+
{
57+
"targets": [
58+
{
59+
"content": "0:3-0:4"
60+
}
61+
],
62+
"domain": "0:3-0:4"
63+
},
64+
{
65+
"targets": [
66+
{
67+
"content": "1:3-1:4"
68+
}
69+
],
70+
"domain": "1:3-1:4"
71+
}
72+
]
73+
},
2674
{
2775
"name": "scopes/markdown/collectionItem.unenclosed.multiLine",
2876
"languageId": "markdown",
@@ -51,13 +99,83 @@
5199
"targets": [
52100
{
53101
"content": "2:2-2:42",
54-
"removal": "2:0-2:42"
102+
"removal": "1:39-2:42"
55103
}
56104
],
57105
"domain": "2:0-2:42"
58106
}
59107
]
60108
},
109+
{
110+
"name": "scopes/markdown/collectionItem.unenclosed.multiLine2",
111+
"languageId": "markdown",
112+
"facet": "collectionItem.unenclosed.multiLine",
113+
"code": "- First item\n Paragraph\n- Second item",
114+
"scopes": [
115+
{
116+
"targets": [
117+
{
118+
"content": "0:2-1:11",
119+
"removal": "0:0-2:0"
120+
}
121+
],
122+
"domain": "0:0-1:11"
123+
},
124+
{
125+
"targets": [
126+
{
127+
"content": "2:2-2:13",
128+
"removal": "1:11-2:13"
129+
}
130+
],
131+
"domain": "2:0-2:13"
132+
}
133+
]
134+
},
135+
{
136+
"name": "scopes/markdown/collectionItem.unenclosed.multiLine3",
137+
"languageId": "markdown",
138+
"facet": "collectionItem.unenclosed.multiLine",
139+
"code": "- [ ] First item\n- [ ] Second item",
140+
"scopes": [
141+
{
142+
"targets": [
143+
{
144+
"content": "0:2-0:16",
145+
"removal": "0:0-1:0"
146+
}
147+
],
148+
"domain": "0:0-0:16"
149+
},
150+
{
151+
"targets": [
152+
{
153+
"content": "0:3-0:4",
154+
"removal": "0:3-0:4"
155+
}
156+
],
157+
"domain": "0:3-0:4"
158+
},
159+
{
160+
"targets": [
161+
{
162+
"content": "1:2-1:17",
163+
"removal": "0:16-1:17"
164+
}
165+
],
166+
"domain": "1:0-1:17"
167+
},
168+
{
169+
"targets": [
170+
{
171+
"content": "1:3-1:4",
172+
"removal": "1:3-1:4"
173+
}
174+
],
175+
"domain": "1:3-1:4"
176+
}
177+
]
178+
},
61179
{
62180
"name": "scopes/markdown/comment.block",
63181
"languageId": "markdown",

‎packages/app-web-docs/src/docs/user/languages/markdown.mdx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,20 @@ Below are visualizations of all our scope tests for this language. These were cr
1919

2020
<ScopeVisualizer fixtureName="scopes/markdown/collectionItem.unenclosed.multiLine" languageId="markdown" />
2121

22+
<ScopeVisualizer fixtureName="scopes/markdown/collectionItem.unenclosed.multiLine2" languageId="markdown" />
23+
24+
<ScopeVisualizer fixtureName="scopes/markdown/collectionItem.unenclosed.multiLine3" languageId="markdown" />
25+
2226
#### 2. Collection item: Unenclosed (iteration)
2327

2428
<i>Iteration scope for items in a comma-separated list without enclosing delimiters</i>
2529

2630
<ScopeVisualizer fixtureName="scopes/markdown/collectionItem.unenclosed.iteration" languageId="markdown" />
2731

32+
<ScopeVisualizer fixtureName="scopes/markdown/collectionItem.unenclosed.iteration2" languageId="markdown" />
33+
34+
<ScopeVisualizer fixtureName="scopes/markdown/collectionItem.unenclosed.iteration3" languageId="markdown" />
35+
2836
### Comment
2937

3038
#### 1. Comment: Block

‎packages/app-web-docs/src/docs/user/scopes/collectionItem.mdx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ Default: `item`
117117

118118
<ScopeVisualizer fixtureName="scopes/markdown/collectionItem.unenclosed.multiLine" />
119119

120+
<ScopeVisualizer fixtureName="scopes/markdown/collectionItem.unenclosed.multiLine2" />
121+
122+
<ScopeVisualizer fixtureName="scopes/markdown/collectionItem.unenclosed.multiLine3" />
123+
120124
##### Scala
121125

122126
<ScopeVisualizer fixtureName="scopes/scala/collectionItem/collectionItem.unenclosed.multiLine" />
@@ -255,6 +259,10 @@ Default: `item`
255259

256260
<ScopeVisualizer fixtureName="scopes/markdown/collectionItem.unenclosed.iteration" />
257261

262+
<ScopeVisualizer fixtureName="scopes/markdown/collectionItem.unenclosed.iteration2" />
263+
264+
<ScopeVisualizer fixtureName="scopes/markdown/collectionItem.unenclosed.iteration3" />
265+
258266
##### Python
259267

260268
<ScopeVisualizer fixtureName="scopes/python/collectionItem/collectionItem.unenclosed.iteration" />

‎packages/app-web-docs/src/docs/user/scopes/fixtures/collectionItem.json‎

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,54 @@
14991499
}
15001500
]
15011501
},
1502+
{
1503+
"name": "scopes/markdown/collectionItem.unenclosed.iteration2",
1504+
"languageId": "markdown",
1505+
"facet": "collectionItem.unenclosed.iteration",
1506+
"code": "- First item\n Paragraph\n- Second item",
1507+
"scopes": [
1508+
{
1509+
"targets": [
1510+
{
1511+
"content": "0:0-2:13"
1512+
}
1513+
],
1514+
"domain": "0:0-2:13"
1515+
}
1516+
]
1517+
},
1518+
{
1519+
"name": "scopes/markdown/collectionItem.unenclosed.iteration3",
1520+
"languageId": "markdown",
1521+
"facet": "collectionItem.unenclosed.iteration",
1522+
"code": "- [ ] First item\n- [ ] Second item",
1523+
"scopes": [
1524+
{
1525+
"targets": [
1526+
{
1527+
"content": "0:0-1:17"
1528+
}
1529+
],
1530+
"domain": "0:0-1:17"
1531+
},
1532+
{
1533+
"targets": [
1534+
{
1535+
"content": "0:3-0:4"
1536+
}
1537+
],
1538+
"domain": "0:3-0:4"
1539+
},
1540+
{
1541+
"targets": [
1542+
{
1543+
"content": "1:3-1:4"
1544+
}
1545+
],
1546+
"domain": "1:3-1:4"
1547+
}
1548+
]
1549+
},
15021550
{
15031551
"name": "scopes/markdown/collectionItem.unenclosed.multiLine",
15041552
"languageId": "markdown",
@@ -1527,13 +1575,83 @@
15271575
"targets": [
15281576
{
15291577
"content": "2:2-2:42",
1530-
"removal": "2:0-2:42"
1578+
"removal": "1:39-2:42"
15311579
}
15321580
],
15331581
"domain": "2:0-2:42"
15341582
}
15351583
]
15361584
},
1585+
{
1586+
"name": "scopes/markdown/collectionItem.unenclosed.multiLine2",
1587+
"languageId": "markdown",
1588+
"facet": "collectionItem.unenclosed.multiLine",
1589+
"code": "- First item\n Paragraph\n- Second item",
1590+
"scopes": [
1591+
{
1592+
"targets": [
1593+
{
1594+
"content": "0:2-1:11",
1595+
"removal": "0:0-2:0"
1596+
}
1597+
],
1598+
"domain": "0:0-1:11"
1599+
},
1600+
{
1601+
"targets": [
1602+
{
1603+
"content": "2:2-2:13",
1604+
"removal": "1:11-2:13"
1605+
}
1606+
],
1607+
"domain": "2:0-2:13"
1608+
}
1609+
]
1610+
},
1611+
{
1612+
"name": "scopes/markdown/collectionItem.unenclosed.multiLine3",
1613+
"languageId": "markdown",
1614+
"facet": "collectionItem.unenclosed.multiLine",
1615+
"code": "- [ ] First item\n- [ ] Second item",
1616+
"scopes": [
1617+
{
1618+
"targets": [
1619+
{
1620+
"content": "0:2-0:16",
1621+
"removal": "0:0-1:0"
1622+
}
1623+
],
1624+
"domain": "0:0-0:16"
1625+
},
1626+
{
1627+
"targets": [
1628+
{
1629+
"content": "0:3-0:4",
1630+
"removal": "0:3-0:4"
1631+
}
1632+
],
1633+
"domain": "0:3-0:4"
1634+
},
1635+
{
1636+
"targets": [
1637+
{
1638+
"content": "1:2-1:17",
1639+
"removal": "0:16-1:17"
1640+
}
1641+
],
1642+
"domain": "1:0-1:17"
1643+
},
1644+
{
1645+
"targets": [
1646+
{
1647+
"content": "1:3-1:4",
1648+
"removal": "1:3-1:4"
1649+
}
1650+
],
1651+
"domain": "1:3-1:4"
1652+
}
1653+
]
1654+
},
15371655
{
15381656
"name": "scopes/plaintext/collectionItem/collectionItem.textual.iteration",
15391657
"languageId": "plaintext",

‎packages/lib-engine/src/languages/TreeSitterQuery/QueryPredicateOperator.ts‎

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ export abstract class QueryPredicateOperator<T extends HasSchema> {
3535
*/
3636
abstract readonly schema: InferSchemaType<T>;
3737

38+
/**
39+
* Whether it is ok for a node argument to be missing. If true, then the
40+
* operator will just accept the pattern if the given node is missing. If
41+
* false, then the operator will throw an error if the node is missing.
42+
*
43+
* This is useful if we want to set some flag on a node, but only if it's
44+
* present.
45+
*/
46+
protected allowMissingNode: boolean = false;
47+
3848
/**
3949
* Given a list of operands, return whether the operator accepts the given
4050
* operands. This is where the actual logic of the operator is implemented.
@@ -47,21 +57,6 @@ export abstract class QueryPredicateOperator<T extends HasSchema> {
4757
...args: AcceptFunctionArgs<z.infer<InferSchemaType<T>>>
4858
): boolean;
4959

50-
/**
51-
* Whether it is ok for a node argument to be missing. If true, then the
52-
* operator will just accept the pattern if the given node is missing. If
53-
* false, then the operator will throw an error if the node is missing.
54-
*
55-
* This is useful if we want to set some flag on a node, but only if it's
56-
* present.
57-
*
58-
* @returns A boolean indicating whether it is ok for a node argument to be
59-
* missing.
60-
*/
61-
protected allowMissingNode(): boolean {
62-
return false;
63-
}
64-
6560
/**
6661
* Given a list of operands, return a predicate function that can be used to
6762
* test whether a given match satisfies the predicate.
@@ -84,7 +79,7 @@ export abstract class QueryPredicateOperator<T extends HasSchema> {
8479
} catch (error) {
8580
if (
8681
error instanceof CaptureNotFoundError &&
87-
this.allowMissingNode()
82+
this.allowMissingNode
8883
) {
8984
return true;
9085
}

0 commit comments

Comments
 (0)