JSON language support#282
Open
selfagency wants to merge 3 commits into
Open
Conversation
Add complete JSON language support using tree-sitter-json v0.24.8 with 20 prepared queries covering all JSON grammatical elements: Core queries: - Comments, Objects, Arrays, Strings, Numbers - Boolean literals, Null values Advanced queries: - Object key-value pairs, Array elements, String escape sequences - All values (catch-all for all JSON types) Structure queries: - Nested objects, Nested arrays, Mixed structures - Integer numbers, Float numbers, Double-quoted strings - Top-level values, Empty objects All queries use inline strings following Python pattern for consistency. Added comprehensive test coverage: 19 test cases with 170 lines of JSON test data, 19 snapshot files validating correct scoping behavior. CLI integration complete with JsonScope struct supporting --json flag. All 812 tests passing (501 unit + 40 module + 59 CLI + 199 langs + 1 README + 2 regression + 12 doctests). Clippy pedantic mode passing with zero warnings.
- Fix Objects query to match all objects including empty ones: (object) @object - Fix Arrays query to match all arrays including empty ones: (array) @array - Fix ObjectKeyValuePairs to only capture pair nodes (remove redundant @object capture) - Fix ArrayElements to only capture element nodes (remove redundant @array capture) - Fix IntegerNumbers with #match? predicate to only match numbers without decimal point - Fix FloatNumbers with #match? predicate to only match numbers containing a decimal point - Fix TopLevelValues to use (document (_value) @value) - now actually matches content - Fix EmptyObjects with #match? predicate to only match truly empty objects {} - Fix MixedStructures: reorder query pattern and add matching test data to base.json - Update DoubleQuotedStrings doc to clarify it's equivalent to Strings - Update all doc comments to be more precise about behavior - Regenerate all affected snapshots - Update README via FIX_README=1 Agent-Logs-Url: https://github.com/selfagency/srgn/sessions/dfcf5c43-b13c-4755-b1d7-a128b34d0250 Co-authored-by: selfagency <2541728+selfagency@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds first-class JSON language scoping to srgn by integrating tree-sitter-json, exposing prepared queries via the CLI, and validating behavior through snapshot-based language tests.
Changes:
- Added a new JSON language module (
PreparedQuery+CompiledQuery) and registered it in the language system. - Wired JSON scoping into the CLI (
--json,--json-query,--json-query-file) and documented it in the README help output. - Added JSON test corpus plus snapshot coverage for all prepared queries.
Reviewed changes
Copilot reviewed 26 out of 27 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/scoping/langs/json.rs |
Implements JSON prepared queries and compiled query wrapper for tree-sitter execution. |
src/scoping/langs.rs |
Registers the new json language module. |
src/main.rs |
Adds --json CLI scope group and hooks JSON into the language-scope selection macro. |
tests/langs/mod.rs |
Extends language scoper tests to include JSON prepared queries and custom-query compilation checks. |
tests/langs/json/base.json |
Adds JSON(+comments) fixture data used by snapshot tests. |
tests/langs/snapshots/r#mod__langs__base.json_*.snap |
Snapshot baselines for each JSON prepared query scope. |
README.md |
Updates generated CLI help section to include JSON flags and prepared query list. |
Cargo.toml |
Adds tree-sitter-json = "0.24.8" dependency. |
Cargo.lock |
Locks tree-sitter-json and updates dependency graph accordingly. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+77
to
+81
| impl PreparedQuery { | ||
| /// Returns the tree-sitter query string for this prepared query. | ||
| #[must_use] | ||
| pub const fn as_string(self) -> &'static str { | ||
| #[allow(clippy::match_same_arms)] |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add complete JSON language support to srgn using tree-sitter-json v0.24.8 with 20 prepared queries covering all JSON grammatical elements.
Changes
Core Features
src/scoping/langs/json.rs(133 lines)PreparedQueryvariants covering all JSON grammatical elementsFindandLanguageScopertraitsPrepared Query Coverage
Core queries (6):
Advanced queries (9):
Specific patterns (5):
CLI Integration
JsonScopestruct with--jsonflag supportsrc/main.rsTest Coverage
Examples
Basic usage
Complex scoping
Test Results
All 812 tests passing:
Clippy pedantic mode passing with zero warnings.
Technical Details
Query Fixes Applied
_valueinstead ofvalue(tree-sitter JSON grammar)NestedObjectspattern:(object (pair value: (object) @nested)) @parentDependencies
tree-sitter-json = "0.24.8"toCargo.toml