code-symbol-index 0.3.2__tar.gz → 0.3.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: code-symbol-index
3
- Version: 0.3.2
3
+ Version: 0.3.3
4
4
  Summary: Tree-sitter backed symbol search and inspection for codebases.
5
5
  Author-email: hit9 <hit9@icloud.com>
6
6
  License-Expression: MIT
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: code-symbol-index
3
- Version: 0.3.2
3
+ Version: 0.3.3
4
4
  Summary: Tree-sitter backed symbol search and inspection for codebases.
5
5
  Author-email: hit9 <hit9@icloud.com>
6
6
  License-Expression: MIT
@@ -22,7 +22,7 @@ from tree_sitter import Node
22
22
  from tree_sitter_language_pack import get_parser
23
23
 
24
24
 
25
- __version__ = "0.3.2"
25
+ __version__ = "0.3.3"
26
26
  SCHEMA_VERSION = 5
27
27
  DEFAULT_INDEX_DIR = ".code-symbol-index"
28
28
  DEFAULT_INDEX_DB = "index.sqlite"
@@ -2516,7 +2516,7 @@ def _parse_file(
2516
2516
  except (OSError, UnicodeDecodeError, BinaryFileError):
2517
2517
  return None
2518
2518
 
2519
- tree = _parser_for_language(spec.name).parse(source_text)
2519
+ tree = _parse_source(_parser_for_language(spec.name), source_text)
2520
2520
  root_node = tree.root_node() if callable(tree.root_node) else tree.root_node
2521
2521
  source_bytes = source_text.encode("utf-8")
2522
2522
  symbols, references = _extract_symbols_and_references(
@@ -2579,6 +2579,16 @@ def _file_contains_bytes(path: Path, needle: bytes) -> bool:
2579
2579
  _PARSER_TLS = threading.local()
2580
2580
 
2581
2581
 
2582
+ def _parse_source(parser, source: str):
2583
+ # tree-sitter's parse() signature varies across versions/builds: some accept str, others
2584
+ # require bytes (raising "source must be a bytestring or a callable, not str"). Try str first,
2585
+ # then fall back to encoded bytes so both bindings work. Byte offsets are identical either way.
2586
+ try:
2587
+ return parser.parse(source)
2588
+ except TypeError:
2589
+ return parser.parse(source.encode("utf-8"))
2590
+
2591
+
2582
2592
  def _parser_for_language(language: str):
2583
2593
  if language not in LANGUAGE_BY_NAME:
2584
2594
  raise UnsupportedLanguageError(f"Unsupported language: {language}")
@@ -3691,7 +3701,7 @@ def _definition_ranges_for_symbols(
3691
3701
  for symbol in symbols
3692
3702
  }
3693
3703
  ranges: dict[str, Range] = {}
3694
- tree = _parser_for_language(spec.name).parse(source)
3704
+ tree = _parse_source(_parser_for_language(spec.name), source)
3695
3705
  root_node = tree.root_node() if callable(tree.root_node) else tree.root_node
3696
3706
 
3697
3707
  def walk(node: Node) -> None:
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "code-symbol-index"
7
- version = "0.3.2"
7
+ version = "0.3.3"
8
8
  description = "Tree-sitter backed symbol search and inspection for codebases."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"