Skip to content

Commit 06eb81c

Browse files
authored
Changes for tree-sitter 0.21 (#2409)
- Depends on cursorless-dev/vscode-parse-tree#84 - Note that this PR will fail CI until cursorless-dev/vscode-parse-tree#84 has been released ## Checklist - [x] 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 1abf38d commit 06eb81c

File tree

26 files changed

+310
-293
lines changed

26 files changed

+310
-293
lines changed

Diff for: data/fixtures/recorded/languages/php/changeRound.yml

-29
This file was deleted.

Diff for: data/fixtures/recorded/languages/php/changeRound2.yml

-29
This file was deleted.

Diff for: data/fixtures/recorded/languages/php/changeRound3.yml

-29
This file was deleted.

Diff for: data/fixtures/recorded/languages/typescript/changeType9.yml

-23
This file was deleted.

Diff for: data/fixtures/recorded/languages/typescript/chuckType5.yml

-23
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
"aaa";
3+
'aaa';
4+
`aaa`;
5+
"aaa $bbb ccc"
6+
`aaa $bbb ccc`;
7+
---
8+
9+
[#1 Content] =
10+
[#1 Removal] =
11+
[#1 Domain] = 1:5-1:8
12+
>---<
13+
1| "aaa";
14+
15+
[#1 Insertion delimiter] = " "
16+
17+
18+
[#2 Content] =
19+
[#2 Removal] =
20+
[#2 Domain] = 2:5-2:8
21+
>---<
22+
2| 'aaa';
23+
24+
[#2 Insertion delimiter] = " "
25+
26+
27+
[#3 Content] =
28+
[#3 Removal] =
29+
[#3 Domain] = 3:5-3:8
30+
>---<
31+
3| `aaa`;
32+
33+
[#3 Insertion delimiter] = " "
34+
35+
36+
[#4 Content] =
37+
[#4 Removal] =
38+
[#4 Domain] = 4:5-4:17
39+
>------------<
40+
4| "aaa $bbb ccc"
41+
42+
[#4 Insertion delimiter] = " "
43+
44+
45+
[#5 Content] =
46+
[#5 Removal] =
47+
[#5 Domain] = 5:5-5:17
48+
>------------<
49+
5| `aaa $bbb ccc`;
50+
51+
[#5 Insertion delimiter] = " "
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
aaa as const
2+
---
3+
4+
[Content] = 0:7-0:12
5+
>-----<
6+
0| aaa as const
7+
8+
[Removal] = 0:3-0:12
9+
>---------<
10+
0| aaa as const
11+
12+
[Leading delimiter] = 0:3-0:7
13+
>----<
14+
0| aaa as const
15+
16+
[Domain] = 0:0-0:12
17+
>------------<
18+
0| aaa as const
19+
20+
[Insertion delimiter] = " "

Diff for: packages/common/src/scopeSupportFacets/php.ts

+1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel;
1111
export const phpScopeSupport: LanguageScopeSupportFacetMap = {
1212
"comment.line": supported,
1313
"comment.block": supported,
14+
"textFragment.string.singleLine": supported,
1415
};

Diff for: packages/cursorless-engine/src/actions/ShowParseTree.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,6 @@ function parseCursor(
116116
}
117117

118118
function getFieldName(cursor: TreeCursor): string {
119-
const field = cursor.currentFieldName();
119+
const field = cursor.currentFieldName;
120120
return field != null ? `${field}: ` : "";
121121
}

Diff for: packages/cursorless-engine/src/core/Debug.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class Debug {
101101
cursor: TreeCursor,
102102
index: number,
103103
) {
104-
const field = cursor.currentFieldName();
104+
const field = cursor.currentFieldName;
105105
const fieldText = field != null ? `${field}: ` : "";
106106
const indent = " ".repeat(index);
107107
const nodeIsLast = index === nodes.length - 1;
@@ -133,7 +133,7 @@ export class Debug {
133133

134134
private cursorGoToChildWithId(cursor: TreeCursor, id: number): boolean {
135135
cursor.gotoFirstChild();
136-
while (cursor.currentNode().id !== id) {
136+
while (cursor.currentNode.id !== id) {
137137
if (!cursor.gotoNextSibling()) {
138138
return false;
139139
}

Diff for: packages/cursorless-engine/src/languages/LanguageDefinition.ts

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ export class LanguageDefinition {
5252
return undefined;
5353
}
5454

55+
if (!(await treeSitter.loadLanguage(languageId))) {
56+
return undefined;
57+
}
58+
5559
const rawQuery = treeSitter
5660
.getLanguage(languageId)!
5761
.query(rawLanguageQueryString);

Diff for: packages/cursorless-engine/src/languages/TreeSitterQuery/TreeSitterQuery.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,10 @@ export class TreeSitterQuery {
6767
end?: Position,
6868
): QueryMatch[] {
6969
return this.query
70-
.matches(
71-
this.treeSitter.getTree(document).rootNode,
72-
start == null ? undefined : positionToPoint(start),
73-
end == null ? undefined : positionToPoint(end),
74-
)
70+
.matches(this.treeSitter.getTree(document).rootNode, {
71+
startPosition: start == null ? undefined : positionToPoint(start),
72+
endPosition: end == null ? undefined : positionToPoint(end),
73+
})
7574
.map(
7675
({ pattern, captures }): MutableQueryMatch => ({
7776
patternIdx: pattern,

Diff for: packages/cursorless-engine/src/languages/latex.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function extendToNamedSiblingIfExists(
108108
let endIndex = node.endIndex;
109109
const sibling = node.nextNamedSibling;
110110

111-
if (sibling != null && sibling.isNamed()) {
111+
if (sibling != null && sibling.isNamed) {
112112
endIndex = sibling.endIndex;
113113
}
114114

Diff for: packages/cursorless-engine/src/languages/ruby.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,21 @@ const EXPRESSION_TYPES = [
9292
];
9393

9494
const EXPRESSION_STATEMENT_PARENT_TYPES = [
95+
"begin_block",
9596
"begin",
97+
"block_body",
9698
"block",
97-
"do",
99+
"body_statement",
98100
"do_block",
101+
"do",
99102
"else",
103+
"end_block",
100104
"ensure",
101105
"heredoc_beginning",
106+
"interpolation",
102107
"lambda",
103108
"method",
109+
"parenthesized_statements",
104110
"program",
105111
"singleton_class",
106112
"singleton_method",

Diff for: packages/cursorless-engine/src/processTargets/modifiers/surroundingPair/delimiterMaps.ts

+8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ const delimiterToTextOverrides: Record<string, Partial<DelimiterMap>> = {
4444
['"', "]]"],
4545
],
4646
},
47+
48+
python: {
49+
// FIXME: We technically can't distinguish between single and double quotes
50+
// now, but we'll revisit all this; see
51+
// https://github.com/cursorless-dev/cursorless/issues/1812#issuecomment-1691493746
52+
singleQuotes: ["string_start", "string_end"],
53+
doubleQuotes: ["string_start", "string_end"],
54+
},
4755
};
4856

4957
export const leftToRightMap: Record<string, string> = Object.fromEntries(

Diff for: packages/cursorless-engine/src/processTargets/modifiers/surroundingPair/findSurroundingPairParseTreeBased.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ function findSurroundingPairContainedInNode(
183183
*/
184184
const possibleDelimiterNodes = node
185185
.descendantsOfType(individualDelimiters.map(({ text }) => text))
186-
.filter((node) => !(node.text === "" && node.hasError()));
186+
.filter((node) => !(node.text === "" && node.hasError));
187187

188188
/**
189189
* A list of all delimiter occurrences, generated from the delimiter nodes.

Diff for: packages/cursorless-engine/src/util/treeSitterUtils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export function getChildNodesForFieldName(
2727
let hasNext = true;
2828

2929
while (hasNext) {
30-
if (treeCursor.currentFieldName() === fieldName) {
31-
ret.push(treeCursor.currentNode());
30+
if (treeCursor.currentFieldName === fieldName) {
31+
ret.push(treeCursor.currentNode);
3232
}
3333

3434
hasNext = treeCursor.gotoNextSibling();

Diff for: queries/cpp.scm

+2-3
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,19 @@
3535
(function_definition
3636
declarator: (_
3737
declarator: (_
38-
namespace: (_) @className
38+
scope: (_) @className
3939
)
4040
)
4141
) @_.domain
4242

4343
(lambda_expression) @anonymousFunction
44-
(attribute) @attribute
44+
(attribute_declaration) @attribute
4545

4646
;; > curl https://raw.githubusercontent.com/tree-sitter/tree-sitter-cpp/master/src/node-types.json | jq '[.[] | select(.type == "_type_specifier") | .subtypes[].type]'
4747
[
4848
(auto)
4949
(decltype)
5050
(dependent_type)
51-
(scoped_type_identifier)
5251
(template_type)
5352
] @type
5453

0 commit comments

Comments
 (0)