From ee48c3b44aab4933b09b2306b3db1ec7fd265ad9 Mon Sep 17 00:00:00 2001 From: Akuli Date: Tue, 6 Sep 2022 12:35:13 +0300 Subject: [PATCH 1/6] tree-sitter: add missing members --- stubs/tree-sitter/tree_sitter/binding.pyi | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/stubs/tree-sitter/tree_sitter/binding.pyi b/stubs/tree-sitter/tree_sitter/binding.pyi index 8e175394426a..02e06c87ab5e 100644 --- a/stubs/tree-sitter/tree_sitter/binding.pyi +++ b/stubs/tree-sitter/tree_sitter/binding.pyi @@ -1,5 +1,6 @@ from typing import Any, ClassVar from typing_extensions import final +from _typeshed import Incomplete from tree_sitter import Language @@ -18,6 +19,8 @@ class Node: @property def has_error(self) -> bool: ... @property + def id(self) -> int: ... + @property def is_missing(self) -> bool: ... @property def is_named(self) -> bool: ... @@ -28,6 +31,8 @@ class Node: @property def children(self) -> list[Node]: ... @property + def named_children(self) -> list[Node]: ... + @property def next_named_sibling(self) -> Node | None: ... @property def next_sibling(self) -> Node | None: ... @@ -41,9 +46,12 @@ class Node: def text(self) -> bytes | Any: ... # can be None, but annoying to check @property def type(self) -> str: ... - __hash__: ClassVar[None] # type: ignore[assignment] + def children_by_field_name(self, name: str) -> list[Node]: ... + def children_by_field_id(self, __id: int) -> list[Node]: ... + def field_name_for_chlid(self, __child_index: int) -> str: ... def child_by_field_id(self, __id: int) -> Node | None: ... def child_by_field_name(self, __name: str) -> Node | None: ... + __hash__: ClassVar[None] # type: ignore[assignment] def sexp(self) -> str: ... def walk(self) -> TreeCursor: ... def __eq__(self, other: object) -> bool: ... @@ -82,12 +90,14 @@ class Tree: old_end_point: tuple[int, int], new_end_point: tuple[int, int], ) -> None: ... + def get_changed_ranges(self, new_tree: Tree) -> list[Incomplete]: ... def walk(self) -> TreeCursor: ... @final class TreeCursor: @property def node(self) -> Node: ... + def copy(self) -> TreeCursor: ... def current_field_name(self) -> str | None: ... def goto_first_child(self) -> bool: ... def goto_next_sibling(self) -> bool: ... From c0376a4bf48f3e0fd5d137020311aabbcc590477 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 6 Sep 2022 09:42:58 +0000 Subject: [PATCH 2/6] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stubs/tree-sitter/tree_sitter/binding.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/tree-sitter/tree_sitter/binding.pyi b/stubs/tree-sitter/tree_sitter/binding.pyi index 02e06c87ab5e..d217ef851123 100644 --- a/stubs/tree-sitter/tree_sitter/binding.pyi +++ b/stubs/tree-sitter/tree_sitter/binding.pyi @@ -1,6 +1,6 @@ +from _typeshed import Incomplete from typing import Any, ClassVar from typing_extensions import final -from _typeshed import Incomplete from tree_sitter import Language From 0ed038782988787fbe91338af269a651ac19bfdd Mon Sep 17 00:00:00 2001 From: Akuli Date: Tue, 6 Sep 2022 12:50:20 +0300 Subject: [PATCH 3/6] Fixes --- stubs/tree-sitter/@tests/stubtest_allowlist.txt | 8 ++++++++ stubs/tree-sitter/tree_sitter/binding.pyi | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/stubs/tree-sitter/@tests/stubtest_allowlist.txt b/stubs/tree-sitter/@tests/stubtest_allowlist.txt index 0b012eb99055..45a56be70b9f 100644 --- a/stubs/tree-sitter/@tests/stubtest_allowlist.txt +++ b/stubs/tree-sitter/@tests/stubtest_allowlist.txt @@ -1,18 +1,24 @@ # "self" argument is missing when stubtest inspects these methods tree_sitter.Node.child_by_field_id tree_sitter.Node.child_by_field_name +tree_sitter.Node.children_by_field_id +tree_sitter.Node.children_by_field_name tree_sitter.Node.sexp tree_sitter.Node.walk tree_sitter.Parser.parse tree_sitter.Parser.set_language tree_sitter.Tree.edit +tree_sitter.Tree.get_changed_ranges tree_sitter.Tree.walk +tree_sitter.TreeCursor.copy tree_sitter.TreeCursor.current_field_name tree_sitter.TreeCursor.goto_first_child tree_sitter.TreeCursor.goto_next_sibling tree_sitter.TreeCursor.goto_parent tree_sitter.binding.Node.child_by_field_id tree_sitter.binding.Node.child_by_field_name +tree_sitter.binding.Node.children_by_field_id +tree_sitter.binding.Node.children_by_field_name tree_sitter.binding.Node.sexp tree_sitter.binding.Node.walk tree_sitter.binding.Parser.parse @@ -20,7 +26,9 @@ tree_sitter.binding.Parser.set_language tree_sitter.binding.Query.captures tree_sitter.binding.Query.matches tree_sitter.binding.Tree.edit +tree_sitter.binding.Tree.get_changed_ranges tree_sitter.binding.Tree.walk +tree_sitter.binding.TreeCursor.copy tree_sitter.binding.TreeCursor.current_field_name tree_sitter.binding.TreeCursor.goto_first_child tree_sitter.binding.TreeCursor.goto_next_sibling diff --git a/stubs/tree-sitter/tree_sitter/binding.pyi b/stubs/tree-sitter/tree_sitter/binding.pyi index 02e06c87ab5e..67e9a09af897 100644 --- a/stubs/tree-sitter/tree_sitter/binding.pyi +++ b/stubs/tree-sitter/tree_sitter/binding.pyi @@ -48,7 +48,7 @@ class Node: def type(self) -> str: ... def children_by_field_name(self, name: str) -> list[Node]: ... def children_by_field_id(self, __id: int) -> list[Node]: ... - def field_name_for_chlid(self, __child_index: int) -> str: ... + def field_name_for_child(self, __child_index: int) -> str: ... def child_by_field_id(self, __id: int) -> Node | None: ... def child_by_field_name(self, __name: str) -> Node | None: ... __hash__: ClassVar[None] # type: ignore[assignment] From 91524e74914b87f910ffc0644284395617b27ed3 Mon Sep 17 00:00:00 2001 From: Akuli Date: Tue, 6 Sep 2022 12:55:10 +0300 Subject: [PATCH 4/6] add Range --- stubs/tree-sitter/tree_sitter/binding.pyi | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/stubs/tree-sitter/tree_sitter/binding.pyi b/stubs/tree-sitter/tree_sitter/binding.pyi index a07ab9b69d83..af816d1522b1 100644 --- a/stubs/tree-sitter/tree_sitter/binding.pyi +++ b/stubs/tree-sitter/tree_sitter/binding.pyi @@ -1,4 +1,3 @@ -from _typeshed import Incomplete from typing import Any, ClassVar from typing_extensions import final @@ -75,6 +74,17 @@ class Query: # start_point and end_point arguments don't seem to do anything def captures(self) -> list[tuple[Node, str]]: ... +@final +class Range: + @property + def start_byte(self) -> int:... + @property + def end_byte(self) -> int:... + @property + def start_point(self) -> tuple[int, int]:... + @property + def end_point(self) -> tuple[int, int]: ... + @final class Tree: @property @@ -90,7 +100,7 @@ class Tree: old_end_point: tuple[int, int], new_end_point: tuple[int, int], ) -> None: ... - def get_changed_ranges(self, new_tree: Tree) -> list[Incomplete]: ... + def get_changed_ranges(self, new_tree: Tree) -> list[Range]: ... def walk(self) -> TreeCursor: ... @final From d86b16c58ab7475ac229ad77375e8261799d87f1 Mon Sep 17 00:00:00 2001 From: Akuli Date: Tue, 6 Sep 2022 12:56:30 +0300 Subject: [PATCH 5/6] Update comment --- stubs/tree-sitter/tree_sitter/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/tree-sitter/tree_sitter/__init__.pyi b/stubs/tree-sitter/tree_sitter/__init__.pyi index 2450e0a9540f..12060f23f332 100644 --- a/stubs/tree-sitter/tree_sitter/__init__.pyi +++ b/stubs/tree-sitter/tree_sitter/__init__.pyi @@ -2,7 +2,7 @@ import ctypes from _typeshed import StrPath from collections.abc import Sequence -# Query is missing at runtime for some reason +# At runtime, Query and Range are available only in tree_sitter.binding from tree_sitter.binding import Node as Node, Parser as Parser, Tree as Tree, TreeCursor as TreeCursor class Language: From 3e195346727e5c9f6745cd90b8f14405b6e0f88e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 6 Sep 2022 09:56:06 +0000 Subject: [PATCH 6/6] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stubs/tree-sitter/tree_sitter/binding.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stubs/tree-sitter/tree_sitter/binding.pyi b/stubs/tree-sitter/tree_sitter/binding.pyi index af816d1522b1..ec4b031ddccd 100644 --- a/stubs/tree-sitter/tree_sitter/binding.pyi +++ b/stubs/tree-sitter/tree_sitter/binding.pyi @@ -77,11 +77,11 @@ class Query: @final class Range: @property - def start_byte(self) -> int:... + def start_byte(self) -> int: ... @property - def end_byte(self) -> int:... + def end_byte(self) -> int: ... @property - def start_point(self) -> tuple[int, int]:... + def start_point(self) -> tuple[int, int]: ... @property def end_point(self) -> tuple[int, int]: ...