Skip to content

Commit

Permalink
👽 Adapt python-tree-sitter 0.23.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Dec 31, 2024
1 parent 2ef620c commit 4d5168f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ exclude: ^template(s)?/

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: fix-byte-order-marker
Expand Down Expand Up @@ -47,15 +47,15 @@ repos:
hooks:
- id: check-mailmap
- repo: https://github.com/rhysd/actionlint
rev: v1.7.2
rev: v1.7.5
hooks:
- id: actionlint
- repo: https://github.com/adrienverge/yamllint
rev: v1.35.1
hooks:
- id: yamllint
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
rev: 0.7.21
hooks:
- id: mdformat
additional_dependencies:
Expand All @@ -69,7 +69,7 @@ repos:
- mdformat-config
- mdformat-web
- repo: https://github.com/DavidAnson/markdownlint-cli2
rev: v0.14.0
rev: v0.17.0
hooks:
- id: markdownlint-cli2
additional_dependencies:
Expand All @@ -79,12 +79,12 @@ repos:
hooks:
- id: update-pyproject.toml
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.7
rev: v0.8.4
hooks:
- id: ruff
- id: ruff-format
- repo: https://github.com/kumaraditya303/mirrors-pyright
rev: v1.1.381
rev: v1.1.391
hooks:
- id: pyright

Expand Down
24 changes: 14 additions & 10 deletions src/lsp_tree_sitter/finders.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ def compare(self, uni: UNI, _uni: UNI) -> bool:
:type _uni: UNI
:rtype: bool
"""
return uni.node.text < _uni.node.text
if uni.node.text and _uni.node.text:
return uni.node.text < _uni.node.text
return True


@dataclass(init=False)
Expand Down Expand Up @@ -597,29 +599,31 @@ def find_all(
return self.captures2unis(captures, uri)

def captures2unis(
self, captures: list[tuple[Node, str]], uri: str
self, captures: dict[str, list[Node]], uri: str
) -> list[UNI]:
r"""Captures2unis.
:param captures:
:type captures: list[tuple[Node, str]]
:type captures: dict[str, list[Node]]
:param uri:
:type uri: str
:rtype: list[UNI]
"""
unis = []
for capture in captures:
if uni := self.capture2uni(capture, uri):
for name, nodes in captures.items():
if uni := self.capture2uni(name, nodes, uri):
unis += [uni]
return unis

def capture2uni(self, capture: tuple[Node, str], uri: str) -> UNI | None:
def capture2uni(self, name: str, nodes: list[Node], uri: str) -> UNI:
r"""Capture2uni.
:param capture:
:type capture: tuple[Node, str]
:param name:
:type name: str
:param nodes:
:type nodes: list[Node]
:param uri:
:type uri: str
:rtype: UNI | None
:rtype: UNI
"""
return UNI(uri, capture[0])
return UNI(uri, nodes[0])

0 comments on commit 4d5168f

Please sign in to comment.