Skip to content

Changes for tree-sitter 0.21 #2409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions data/fixtures/recorded/languages/php/changeRound.yml

This file was deleted.

29 changes: 0 additions & 29 deletions data/fixtures/recorded/languages/php/changeRound2.yml

This file was deleted.

29 changes: 0 additions & 29 deletions data/fixtures/recorded/languages/php/changeRound3.yml

This file was deleted.

23 changes: 0 additions & 23 deletions data/fixtures/recorded/languages/typescript/changeType9.yml

This file was deleted.

23 changes: 0 additions & 23 deletions data/fixtures/recorded/languages/typescript/chuckType5.yml

This file was deleted.

51 changes: 51 additions & 0 deletions data/fixtures/scopes/php/textFragment.string.singleLine.scope
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
"aaa";
'aaa';
`aaa`;
"aaa $bbb ccc"
`aaa $bbb ccc`;
---

[#1 Content] =
[#1 Removal] =
[#1 Domain] = 1:5-1:8
>---<
1| "aaa";

[#1 Insertion delimiter] = " "


[#2 Content] =
[#2 Removal] =
[#2 Domain] = 2:5-2:8
>---<
2| 'aaa';

[#2 Insertion delimiter] = " "


[#3 Content] =
[#3 Removal] =
[#3 Domain] = 3:5-3:8
>---<
3| `aaa`;

[#3 Insertion delimiter] = " "


[#4 Content] =
[#4 Removal] =
[#4 Domain] = 4:5-4:17
>------------<
4| "aaa $bbb ccc"

[#4 Insertion delimiter] = " "


[#5 Content] =
[#5 Removal] =
[#5 Domain] = 5:5-5:17
>------------<
5| `aaa $bbb ccc`;

[#5 Insertion delimiter] = " "
20 changes: 20 additions & 0 deletions data/fixtures/scopes/typescript.core/type.cast2.scope
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
aaa as const
---

[Content] = 0:7-0:12
>-----<
0| aaa as const

[Removal] = 0:3-0:12
>---------<
0| aaa as const

[Leading delimiter] = 0:3-0:7
>----<
0| aaa as const

[Domain] = 0:0-0:12
>------------<
0| aaa as const

[Insertion delimiter] = " "
1 change: 1 addition & 0 deletions packages/common/src/scopeSupportFacets/php.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel;
export const phpScopeSupport: LanguageScopeSupportFacetMap = {
"comment.line": supported,
"comment.block": supported,
"textFragment.string.singleLine": supported,
};
2 changes: 1 addition & 1 deletion packages/cursorless-engine/src/actions/ShowParseTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,6 @@ function parseCursor(
}

function getFieldName(cursor: TreeCursor): string {
const field = cursor.currentFieldName();
const field = cursor.currentFieldName;
return field != null ? `${field}: ` : "";
}
4 changes: 2 additions & 2 deletions packages/cursorless-engine/src/core/Debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class Debug {
cursor: TreeCursor,
index: number,
) {
const field = cursor.currentFieldName();
const field = cursor.currentFieldName;
const fieldText = field != null ? `${field}: ` : "";
const indent = " ".repeat(index);
const nodeIsLast = index === nodes.length - 1;
Expand Down Expand Up @@ -133,7 +133,7 @@ export class Debug {

private cursorGoToChildWithId(cursor: TreeCursor, id: number): boolean {
cursor.gotoFirstChild();
while (cursor.currentNode().id !== id) {
while (cursor.currentNode.id !== id) {
if (!cursor.gotoNextSibling()) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export class LanguageDefinition {
return undefined;
}

if (!(await treeSitter.loadLanguage(languageId))) {
return undefined;
}

const rawQuery = treeSitter
.getLanguage(languageId)!
.query(rawLanguageQueryString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ export class TreeSitterQuery {
end?: Position,
): QueryMatch[] {
return this.query
.matches(
this.treeSitter.getTree(document).rootNode,
start == null ? undefined : positionToPoint(start),
end == null ? undefined : positionToPoint(end),
)
.matches(this.treeSitter.getTree(document).rootNode, {
startPosition: start == null ? undefined : positionToPoint(start),
endPosition: end == null ? undefined : positionToPoint(end),
})
.map(
({ pattern, captures }): MutableQueryMatch => ({
patternIdx: pattern,
Expand Down
2 changes: 1 addition & 1 deletion packages/cursorless-engine/src/languages/latex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function extendToNamedSiblingIfExists(
let endIndex = node.endIndex;
const sibling = node.nextNamedSibling;

if (sibling != null && sibling.isNamed()) {
if (sibling != null && sibling.isNamed) {
endIndex = sibling.endIndex;
}

Expand Down
8 changes: 7 additions & 1 deletion packages/cursorless-engine/src/languages/ruby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,21 @@ const EXPRESSION_TYPES = [
];

const EXPRESSION_STATEMENT_PARENT_TYPES = [
"begin_block",
"begin",
"block_body",
"block",
"do",
"body_statement",
"do_block",
"do",
"else",
"end_block",
"ensure",
"heredoc_beginning",
"interpolation",
"lambda",
"method",
"parenthesized_statements",
"program",
"singleton_class",
"singleton_method",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ const delimiterToTextOverrides: Record<string, Partial<DelimiterMap>> = {
['"', "]]"],
],
},

python: {
// FIXME: We technically can't distinguish between single and double quotes
// now, but we'll revisit all this; see
// https://github.com/cursorless-dev/cursorless/issues/1812#issuecomment-1691493746
singleQuotes: ["string_start", "string_end"],
doubleQuotes: ["string_start", "string_end"],
},
};

export const leftToRightMap: Record<string, string> = Object.fromEntries(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function findSurroundingPairContainedInNode(
*/
const possibleDelimiterNodes = node
.descendantsOfType(individualDelimiters.map(({ text }) => text))
.filter((node) => !(node.text === "" && node.hasError()));
.filter((node) => !(node.text === "" && node.hasError));

/**
* A list of all delimiter occurrences, generated from the delimiter nodes.
Expand Down
4 changes: 2 additions & 2 deletions packages/cursorless-engine/src/util/treeSitterUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export function getChildNodesForFieldName(
let hasNext = true;

while (hasNext) {
if (treeCursor.currentFieldName() === fieldName) {
ret.push(treeCursor.currentNode());
if (treeCursor.currentFieldName === fieldName) {
ret.push(treeCursor.currentNode);
}

hasNext = treeCursor.gotoNextSibling();
Expand Down
5 changes: 2 additions & 3 deletions queries/cpp.scm
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,19 @@
(function_definition
declarator: (_
declarator: (_
namespace: (_) @className
scope: (_) @className
)
)
) @_.domain

(lambda_expression) @anonymousFunction
(attribute) @attribute
(attribute_declaration) @attribute

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

Expand Down
Loading
Loading