rbtr-lang-json 2026.7.0.dev0__py3-none-any.whl
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.
- rbtr_lang_json/__init__.py +1 -0
- rbtr_lang_json/json.scm +2 -0
- rbtr_lang_json/plugin.py +29 -0
- rbtr_lang_json/py.typed +0 -0
- rbtr_lang_json/tests/__init__.py +0 -0
- rbtr_lang_json/tests/__snapshots__/test_samples/test_edges_match_snapshot.json +1 -0
- rbtr_lang_json/tests/__snapshots__/test_samples/test_extraction_matches_snapshot.json +110 -0
- rbtr_lang_json/tests/cases_extraction.py +30 -0
- rbtr_lang_json/tests/samples/json/json.json +9 -0
- rbtr_lang_json/tests/test_extraction.py +17 -0
- rbtr_lang_json/tests/test_samples.py +68 -0
- rbtr_lang_json-2026.7.0.dev0.dist-info/METADATA +8 -0
- rbtr_lang_json-2026.7.0.dev0.dist-info/RECORD +15 -0
- rbtr_lang_json-2026.7.0.dev0.dist-info/WHEEL +4 -0
- rbtr_lang_json-2026.7.0.dev0.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""JSON language plugin package."""
|
rbtr_lang_json/json.scm
ADDED
rbtr_lang_json/plugin.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""JSON language plugin.
|
|
2
|
+
|
|
3
|
+
Splits JSON by top-level keys in the root object via a
|
|
4
|
+
tree-sitter query, one config-key chunk per key. Non-object JSON
|
|
5
|
+
(arrays, scalars) produces no structural chunks and falls through
|
|
6
|
+
to plaintext.
|
|
7
|
+
|
|
8
|
+
Extracted chunks::
|
|
9
|
+
|
|
10
|
+
{ → config_key "name", scope ""
|
|
11
|
+
"name": "my-project", → config_key "version", scope ""
|
|
12
|
+
"version": "1.0.0", → config_key "dependencies", scope ""
|
|
13
|
+
"dependencies": { ... }
|
|
14
|
+
}
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
from rbtr.languages.registration import LanguageRegistration, QueryExtraction, load_query
|
|
20
|
+
|
|
21
|
+
json = LanguageRegistration(
|
|
22
|
+
id="json",
|
|
23
|
+
extensions=frozenset({".json"}),
|
|
24
|
+
grammar_module="tree_sitter_json",
|
|
25
|
+
extraction=QueryExtraction(
|
|
26
|
+
query=load_query(__package__, "json"),
|
|
27
|
+
),
|
|
28
|
+
extraction_serial=2,
|
|
29
|
+
)
|
rbtr_lang_json/py.typed
ADDED
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "0b774143d92e16f9",
|
|
4
|
+
"blob_sha": "sha1",
|
|
5
|
+
"file_path": "json.json",
|
|
6
|
+
"kind": "config_key",
|
|
7
|
+
"name": "name",
|
|
8
|
+
"scope": "",
|
|
9
|
+
"language": "json",
|
|
10
|
+
"content": "\"name\": \"greeter\"",
|
|
11
|
+
"line_start": 2,
|
|
12
|
+
"line_end": 2,
|
|
13
|
+
"metadata": {
|
|
14
|
+
"module": "",
|
|
15
|
+
"names": "",
|
|
16
|
+
"dots": "",
|
|
17
|
+
"language_hint": ""
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"id": "54a915ff53825252",
|
|
22
|
+
"blob_sha": "sha1",
|
|
23
|
+
"file_path": "json.json",
|
|
24
|
+
"kind": "config_key",
|
|
25
|
+
"name": "version",
|
|
26
|
+
"scope": "",
|
|
27
|
+
"language": "json",
|
|
28
|
+
"content": "\"version\": \"1.0.0\"",
|
|
29
|
+
"line_start": 3,
|
|
30
|
+
"line_end": 3,
|
|
31
|
+
"metadata": {
|
|
32
|
+
"module": "",
|
|
33
|
+
"names": "",
|
|
34
|
+
"dots": "",
|
|
35
|
+
"language_hint": ""
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"id": "cfbbdfe2bde40fed",
|
|
40
|
+
"blob_sha": "sha1",
|
|
41
|
+
"file_path": "json.json",
|
|
42
|
+
"kind": "config_key",
|
|
43
|
+
"name": "defaults",
|
|
44
|
+
"scope": "",
|
|
45
|
+
"language": "json",
|
|
46
|
+
"content": "\"defaults\": {\n \"greeting\": \"Hello\",\n \"locale\": \"en\"\n }",
|
|
47
|
+
"line_start": 4,
|
|
48
|
+
"line_end": 7,
|
|
49
|
+
"metadata": {
|
|
50
|
+
"module": "",
|
|
51
|
+
"names": "",
|
|
52
|
+
"dots": "",
|
|
53
|
+
"language_hint": ""
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"id": "29b185429b752875",
|
|
58
|
+
"blob_sha": "sha1",
|
|
59
|
+
"file_path": "json.json",
|
|
60
|
+
"kind": "config_key",
|
|
61
|
+
"name": "greeting",
|
|
62
|
+
"scope": "",
|
|
63
|
+
"language": "json",
|
|
64
|
+
"content": "\"greeting\": \"Hello\"",
|
|
65
|
+
"line_start": 5,
|
|
66
|
+
"line_end": 5,
|
|
67
|
+
"metadata": {
|
|
68
|
+
"module": "",
|
|
69
|
+
"names": "",
|
|
70
|
+
"dots": "",
|
|
71
|
+
"language_hint": ""
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"id": "09a53d90a2485af8",
|
|
76
|
+
"blob_sha": "sha1",
|
|
77
|
+
"file_path": "json.json",
|
|
78
|
+
"kind": "config_key",
|
|
79
|
+
"name": "locale",
|
|
80
|
+
"scope": "",
|
|
81
|
+
"language": "json",
|
|
82
|
+
"content": "\"locale\": \"en\"",
|
|
83
|
+
"line_start": 6,
|
|
84
|
+
"line_end": 6,
|
|
85
|
+
"metadata": {
|
|
86
|
+
"module": "",
|
|
87
|
+
"names": "",
|
|
88
|
+
"dots": "",
|
|
89
|
+
"language_hint": ""
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"id": "228dee714cb21401",
|
|
94
|
+
"blob_sha": "sha1",
|
|
95
|
+
"file_path": "json.json",
|
|
96
|
+
"kind": "config_key",
|
|
97
|
+
"name": "locales",
|
|
98
|
+
"scope": "",
|
|
99
|
+
"language": "json",
|
|
100
|
+
"content": "\"locales\": [\"en\", \"fr\"]",
|
|
101
|
+
"line_start": 8,
|
|
102
|
+
"line_end": 8,
|
|
103
|
+
"metadata": {
|
|
104
|
+
"module": "",
|
|
105
|
+
"names": "",
|
|
106
|
+
"dots": "",
|
|
107
|
+
"language_hint": ""
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
]
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""JSON extraction test cases (object keys -> config_key)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pytest_cases import case
|
|
6
|
+
|
|
7
|
+
type SymbolCase = tuple[str, str, list[tuple[str, str, str]]]
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@case(tags=["symbol"])
|
|
11
|
+
def case_json_top_level_keys() -> SymbolCase:
|
|
12
|
+
"""JSON splits by top-level keys."""
|
|
13
|
+
src = """\
|
|
14
|
+
{
|
|
15
|
+
"name": "my-project",
|
|
16
|
+
"version": "1.0.0",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"foo": "^1.0"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
"""
|
|
22
|
+
return (
|
|
23
|
+
"json",
|
|
24
|
+
src,
|
|
25
|
+
[
|
|
26
|
+
("config_key", "name", ""),
|
|
27
|
+
("config_key", "version", ""),
|
|
28
|
+
("config_key", "dependencies", ""),
|
|
29
|
+
],
|
|
30
|
+
)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""JSON extraction tests (cases in `cases_extraction.py`)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pytest_cases import parametrize_with_cases
|
|
6
|
+
|
|
7
|
+
from rbtr.git import FileEntry
|
|
8
|
+
from rbtr.languages.extract import extract_file
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@parametrize_with_cases("lang, source, expected", cases=".cases_extraction", has_tag="symbol")
|
|
12
|
+
def test_extracts_expected_symbols(lang: str, source: str, expected: list) -> None:
|
|
13
|
+
"""Each expected (kind, name, scope) tuple appears in the output."""
|
|
14
|
+
chunks = extract_file(FileEntry("input", "sha1", source.encode()), lang)
|
|
15
|
+
symbols = [(c.kind, c.name, c.scope) for c in chunks]
|
|
16
|
+
for exp in expected:
|
|
17
|
+
assert exp in symbols, f"expected {exp} not found in {symbols}"
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""JSON sample extraction: the `samples/json/` project through the real pipeline."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import TYPE_CHECKING
|
|
7
|
+
|
|
8
|
+
import pytest
|
|
9
|
+
from tree_sitter import Parser
|
|
10
|
+
|
|
11
|
+
from rbtr.git import FileEntry
|
|
12
|
+
from rbtr.index.models import Chunk, ChunkKind, Edge
|
|
13
|
+
from rbtr.languages.edges import build_resolution_map, infer_import_edges
|
|
14
|
+
from rbtr.languages.extract import extract_file
|
|
15
|
+
from rbtr.languages.manager import get_manager
|
|
16
|
+
from rbtr.testing import render_edges
|
|
17
|
+
|
|
18
|
+
if TYPE_CHECKING:
|
|
19
|
+
from syrupy.assertion import SnapshotAssertion
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@pytest.fixture
|
|
23
|
+
def project() -> list[tuple[str, str]]:
|
|
24
|
+
root = Path(__file__).parent / "samples" / "json"
|
|
25
|
+
return [
|
|
26
|
+
(str(p.relative_to(root)), p.read_text()) for p in sorted(root.rglob("*")) if p.is_file()
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@pytest.fixture
|
|
31
|
+
def chunks(project: list[tuple[str, str]]) -> list[Chunk]:
|
|
32
|
+
manager = get_manager()
|
|
33
|
+
out: list[Chunk] = []
|
|
34
|
+
for path, text in project:
|
|
35
|
+
lang = manager.detect_language(path) or "json"
|
|
36
|
+
out.extend(extract_file(FileEntry(path, "sha1", text.encode()), lang))
|
|
37
|
+
return out
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@pytest.fixture
|
|
41
|
+
def edges(project: list[tuple[str, str]], chunks: list[Chunk]) -> list[Edge]:
|
|
42
|
+
manager = get_manager()
|
|
43
|
+
repo_files = {path for path, _ in project}
|
|
44
|
+
return infer_import_edges(chunks, repo_files, build_resolution_map(manager))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_emits_expected_kinds(chunks: list[Chunk]) -> None:
|
|
48
|
+
"""The sample exercises JSON's config-key chunks."""
|
|
49
|
+
kinds = {c.kind for c in chunks}
|
|
50
|
+
assert {ChunkKind.CONFIG_KEY} <= kinds
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_parses_cleanly(project: list[tuple[str, str]]) -> None:
|
|
54
|
+
manager = get_manager()
|
|
55
|
+
for path, text in project:
|
|
56
|
+
grammar = manager.grammar(manager.detect_language(path) or "json")
|
|
57
|
+
assert grammar is not None
|
|
58
|
+
assert not Parser(grammar).parse(text.encode()).root_node.has_error, path
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_extraction_matches_snapshot(chunks: list[Chunk], snapshot_json: SnapshotAssertion) -> None:
|
|
62
|
+
assert chunks == snapshot_json
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_edges_match_snapshot(
|
|
66
|
+
chunks: list[Chunk], edges: list[Edge], snapshot_json: SnapshotAssertion
|
|
67
|
+
) -> None:
|
|
68
|
+
assert render_edges(edges, chunks) == snapshot_json
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
rbtr_lang_json/__init__.py,sha256=Q_3UgmslagCM1dhOhfS3iuZf_RcvJJ1VwgQKZm5o3pY,36
|
|
2
|
+
rbtr_lang_json/json.scm,sha256=dp4t-6IAQP1AbWf6Fyw9Ogce7gwEKFo3tuB7tGVF1Hw,67
|
|
3
|
+
rbtr_lang_json/plugin.py,sha256=GPdhenB12pEjmgxKYTg9LpI2r-5-Q5nYiVTt_WiwYrE,863
|
|
4
|
+
rbtr_lang_json/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
rbtr_lang_json/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
rbtr_lang_json/tests/__snapshots__/test_samples/test_edges_match_snapshot.json,sha256=N1F-Xz3GaBn2H1p7uKzhkhKCQV8QVR0t76XD6wmFtXA,3
|
|
7
|
+
rbtr_lang_json/tests/__snapshots__/test_samples/test_extraction_matches_snapshot.json,sha256=wiLYSmBBNab_N43QVip8TRXJCMib5OjxoOEp4AysFDg,2282
|
|
8
|
+
rbtr_lang_json/tests/cases_extraction.py,sha256=ACUvBDCRd_H3wl3gRbNmQqbkN04glv0vybQsCthtlfk,615
|
|
9
|
+
rbtr_lang_json/tests/samples/json/json.json,sha256=77t_wBYqNR8KpFsHfVqHg6bfYANhKSy3YfbuS6UIxrc,138
|
|
10
|
+
rbtr_lang_json/tests/test_extraction.py,sha256=N9FY-lfhuoNTktkgV3j5brfKewzv0uEKM2IuKV30Us8,713
|
|
11
|
+
rbtr_lang_json/tests/test_samples.py,sha256=M6w4VpSwY9EoOUhOG4T7bHwOHfWAp2tr0E8xZS20Flo,2212
|
|
12
|
+
rbtr_lang_json-2026.7.0.dev0.dist-info/WHEEL,sha256=CoDSoyhtC_eO_tlxRYzsTraPv1fPJRXFx91k6ISeAvA,81
|
|
13
|
+
rbtr_lang_json-2026.7.0.dev0.dist-info/entry_points.txt,sha256=GRozVTQXoabsA2r1egOcXN6ahHLnlGcWuuSqLc9R0FM,52
|
|
14
|
+
rbtr_lang_json-2026.7.0.dev0.dist-info/METADATA,sha256=1MLuqg8m9YWffvuG0u5OwtkGzj6YnldlrSfMqt8CxTU,220
|
|
15
|
+
rbtr_lang_json-2026.7.0.dev0.dist-info/RECORD,,
|