tree_haver 3.1.2 → 3.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f88732dc79b665917e925613ebeed944e011bb3ecb20248ebc940a48069fd41
4
- data.tar.gz: '093f3bc6b818083e4205598dcef5782d2fb201e742464758c9c00f99ff3fba50'
3
+ metadata.gz: 3da36f96aa78d0995c76a3cbd6451889066b65d219414938e098ef9949df317f
4
+ data.tar.gz: 11e11da6c9f53e439d4226700c981466c3b47f0b9411d2e97a5211edade8d81d
5
5
  SHA512:
6
- metadata.gz: 2290e9e88865420ba8c39bb26af72e866797a5efeff30177b6c34d10d066014daf4e473f2a240647428d6d452bd0a46aa8828da5b2161723a37b286508c075c6
7
- data.tar.gz: f31f3e85b30e4558cfbd7c6beb5307938c0a2aceb369b660bf16a3291beac095e5d2eb71291057c3ed49c280c56a85968d0d9bdb04b2d34406ec68c356372338
6
+ metadata.gz: 1dce9daf70fc5573d579d699724601756db9758170fdb0e7be759ea9572a3d02fa491766786c708172e0f66c2473ae9e0da97fb20bddf7b185d93e285cc8bd3e
7
+ data.tar.gz: eaf3a3649233933b523a7f8e49831b7d5c7f00da268d805c7cbc043176424b5b4214da607bbe7e57e03dcd9072269dfedf3feba4383a828e6cb1abb89394b5c8
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -30,6 +30,227 @@ Please file a bug if you notice a violation of semantic versioning.
30
30
 
31
31
  ### Security
32
32
 
33
+ ## [3.2.1] - 2025-12-31
34
+
35
+ - TAG: [v3.2.1][3.2.1t]
36
+ - COVERAGE: 94.75% -- 2075/2190 lines in 22 files
37
+ - BRANCH COVERAGE: 81.35% -- 733/901 branches in 22 files
38
+ - 90.14% documented
39
+
40
+ ### Added
41
+
42
+ - `TreeHaver::LibraryPathUtils` module for consistent path parsing across all backends
43
+ - `derive_symbol_from_path(path)` - derives tree-sitter symbol (e.g., `tree_sitter_toml`) from library path
44
+ - `derive_language_name_from_path(path)` - derives language name (e.g., `toml`) from library path
45
+ - `derive_language_name_from_symbol(symbol)` - strips `tree_sitter_` prefix from symbol
46
+ - Handles various naming conventions: `libtree-sitter-toml.so`, `libtree_sitter_toml.so`, `tree-sitter-toml.so`, `toml.so`
47
+ - Isolated backend RSpec tags for running tests without loading conflicting backends
48
+ - `:ffi_backend_only` - runs FFI tests without triggering `mri_backend_available?` check
49
+ - `:mri_backend_only` - runs MRI tests without triggering `ffi_available?` check
50
+ - Uses `TreeHaver::Backends::BLOCKED_BY` to dynamically determine which availability checks to skip
51
+ - Enables `rake ffi_specs` to run FFI tests before MRI is loaded
52
+ - `DependencyTags.ffi_backend_only_available?` - checks FFI availability without loading MRI
53
+ - `DependencyTags.mri_backend_only_available?` - checks MRI availability without checking FFI
54
+
55
+ ### Changed
56
+
57
+ - All backends now use shared `LibraryPathUtils` for path parsing
58
+ - MRI, Rust, FFI, and Java backends updated for consistency
59
+ - Ensures identical behavior across all tree-sitter backends
60
+ - `TreeHaver::Language` class extracted to `lib/tree_haver/language.rb`
61
+ - No API changes, just file organization
62
+ - Loaded via autoload for lazy loading
63
+ - `TreeHaver::Parser` class extracted to `lib/tree_haver/parser.rb`
64
+ - No API changes, just file organization
65
+ - Loaded via autoload for lazy loading
66
+ - Backend availability exclusions in `dependency_tags.rb` are now dynamic
67
+ - Uses `TreeHaver::Backends::BLOCKED_BY` to skip availability checks for blocked backends
68
+ - When running with `--tag ffi_backend_only`, MRI availability is not checked
69
+ - Prevents MRI from being loaded before FFI tests can run
70
+ - Rakefile `ffi_specs` task now uses `:ffi_backend_only` tag
71
+ - Ensures FFI tests run without loading MRI backend first
72
+
73
+ ### Fixed
74
+
75
+ - Rakefile now uses correct RSpec tags for FFI isolation
76
+ - The `ffi_specs` task uses `:ffi_backend_only` to prevent MRI from loading
77
+ - The `remaining_specs` task excludes `:ffi_backend_only` tests
78
+ - Tags in Rakefile align with canonical tags from `dependency_tags.rb`
79
+ - `TreeHaver::RSpec::DependencyTags.mri_backend_available?` now uses correct require path
80
+ - Was: `require "ruby_tree_sitter"` (wrong - causes LoadError)
81
+ - Now: `require "tree_sitter"` (correct - gem name is ruby_tree_sitter but require path is tree_sitter)
82
+ - This fix ensures the MRI backend is correctly detected as available in CI environments
83
+ - `TreeHaver::Backends::MRI::Language.from_library` now properly derives symbol from path
84
+ - Previously, calling `from_library(path)` without `symbol:` would fail because `language_name` was nil
85
+ - Now delegates to private `from_path` after deriving symbol, ensuring proper language name derivation
86
+ - `from_path` is now private (but still accessible via `send` for testing if needed)
87
+ - Extracts language name from paths like `/usr/lib/libtree-sitter-toml.so` → `tree_sitter_toml`
88
+ - Handles both dash and underscore separators in filenames
89
+ - Handles simple language names like `toml.so` → `tree_sitter_toml`
90
+ - `TreeHaver::Backends::MRI::Parser#language=` now unwraps `TreeHaver::Backends::MRI::Language` wrappers
91
+ - Accepts both raw `TreeSitter::Language` and wrapped `TreeHaver::Backends::MRI::Language`
92
+ - `TreeHaver::GrammarFinder.tree_sitter_runtime_usable?` no longer references `FFI::NotFoundError` directly
93
+ - Prevents `NameError` when FFI gem is not loaded
94
+ - `TreeHaver::Parser#initialize` no longer references `FFI::NotFoundError` directly in rescue clause
95
+ - Uses `defined?(::FFI::NotFoundError)` check to safely handle FFI errors when FFI is loaded
96
+ - Prevents `NameError: uninitialized constant TreeHaver::Parser::FFI` when FFI gem is not available
97
+ - Extracted error handling to `handle_parser_creation_failure` private method for clarity
98
+ - RSpec `dependency_tags.rb` now correctly detects `--tag` options during configuration
99
+ - RSpec's `config.inclusion_filter.rules` is empty during configuration phase
100
+ - Now parses `ARGV` directly to detect `--tag ffi_backend_only` and similar tags
101
+ - Skips grammar availability checks (which load MRI) when running isolated backend tests
102
+ - Skips full dependency summary in `before(:suite)` when backends are blocked
103
+ - `TreeHaver::Backends::FFI.reset!` now uses consistent pattern with other backends
104
+ - Was using `@ffi_gem_available` with `defined?()` check, which returned truthy after `reset!` set it to nil
105
+ - Now uses `@load_attempted` / `@loaded` pattern like MRI, Rust, Citrus, Prism, Psych, etc.
106
+ - This fixes FFI tests failing after the first test when `reset!` was called in `after` blocks
107
+ - `TreeHaver::Language.method_missing` no longer references `FFI::NotFoundError` directly in rescue clause
108
+ - Uses `defined?(::FFI::NotFoundError)` check to safely handle FFI errors when FFI is loaded
109
+ - Prevents `NameError` when FFI gem is not available but tree-sitter backends are used
110
+ - Extracted Citrus fallback logic to `handle_tree_sitter_load_failure` private method
111
+
112
+ ## [3.2.0] - 2025-12-30
113
+
114
+ - TAG: [v3.2.0][3.2.0t]
115
+ - COVERAGE: 86.82% -- 2167/2496 lines in 22 files
116
+ - BRANCH COVERAGE: 66.79% -- 734/1099 branches in 22 files
117
+ - 90.03% documented
118
+
119
+ ### Added
120
+
121
+ - `TreeHaver::CITRUS_DEFAULTS` constant with default Citrus configurations for known languages
122
+ - Enables automatic Citrus fallback for TOML without explicit `citrus_config` parameter
123
+ - Currently includes configuration for `:toml` (gem: `toml-rb`, const: `TomlRB::Document`)
124
+ - Regression test suite for Citrus fallback (`spec/integration/citrus_fallback_spec.rb`)
125
+ - Tests `parser_for` with all tree-sitter backends stubbed as unavailable (simulating TruffleRuby)
126
+ - Tests `CitrusGrammarFinder` with nil `gem_name` and `require_path`
127
+ - Tests explicit Citrus backend usage on MRI via `with_backend(:citrus)`
128
+ - Shared examples for TOML parsing tests (`spec/support/shared_examples/toml_parsing_examples.rb`)
129
+ - `"toml parsing basics"` - tests basic parsing, positions, children, text extraction
130
+ - `"toml node navigation"` - tests first_child, named_children navigation
131
+ - Multi-backend TOML test suite (`spec/integration/multi_backend_toml_spec.rb`)
132
+ - Runs shared examples against both tree-sitter-toml and Citrus/toml-rb backends
133
+ - Tests backend equivalence for parsing results and positions
134
+ - Tagged appropriately so tests run on whichever backends are available
135
+ - Backend Platform Compatibility section to README
136
+ - Complete compatibility matrix showing which backends work on MRI, JRuby, TruffleRuby
137
+ - Detailed explanations for TruffleRuby and JRuby limitations
138
+ - `FFI.available?` method at module level for API consistency with other backends
139
+ - `TreeHaver.resolve_native_backend_module` method for resolving only tree-sitter backends
140
+ - `TreeHaver::NATIVE_BACKENDS` constant listing backends that support shared libraries
141
+ - TruffleRuby short-circuit in `resolve_native_backend_module` for efficiency
142
+ - Avoids trying 3 backends that are all known to fail on TruffleRuby
143
+ - `citrus_available?` method to check if Citrus backend is available
144
+
145
+ ### Fixed
146
+
147
+ - **`TreeHaver::Node#child` now returns `nil` for out-of-bounds indices on all backends**
148
+ - MRI backend (ruby_tree_sitter) raises `IndexError` for invalid indices
149
+ - Other backends return `nil` for invalid indices
150
+ - Now consistently returns `nil` across all backends for API compatibility
151
+ - **Citrus backend `calculate_point` returns negative column values**
152
+ - When `offset` was 0, `@source.rindex("\n", -1)` searched from end of string
153
+ - This caused `column = 0 - (position_of_last_newline) - 1` to be negative (e.g., -34)
154
+ - Fix: Early return `{row: 0, column: 0}` for `offset <= 0`
155
+ - This bug affected both MRI and TruffleRuby when using Citrus backend
156
+ - **Citrus fallback fails on TruffleRuby when no explicit `citrus_config` provided**
157
+ - `parser_for(:toml)` would fail with `TypeError: no implicit conversion of nil into String`
158
+ - Root cause: `citrus_config` defaulted to `{}`, so `citrus_config[:gem_name]` was `nil`
159
+ - `CitrusGrammarFinder` was instantiated with `gem_name: nil`, causing `require nil`
160
+ - On TruffleRuby, this triggered a bug in `bundled_gems.rb` calling `File.path` on nil
161
+ - Fix: Added `CITRUS_DEFAULTS` with known Citrus configurations (TOML currently)
162
+ - Fix: `parser_for` now uses `CITRUS_DEFAULTS[name]` when no explicit config provided
163
+ - Fix: Added guard in `CitrusGrammarFinder#available?` to return false when `require_path` is nil
164
+ - Fix: Added `TypeError` to rescue clause for TruffleRuby-specific edge cases
165
+ - **`from_library` no longer falls back to pure-Ruby backends**
166
+ - Previously, calling `Language.from_library(path)` on TruffleRuby would fall back to Citrus
167
+ backend which then raised a confusing error about not supporting shared libraries
168
+ - Now `from_library` only considers native tree-sitter backends (MRI, Rust, FFI, Java)
169
+ - Clear error message when no native backend is available explaining the situation
170
+ - **Integration specs now use `parser_for` instead of explicit paths**
171
+ - `tree_edge_cases_spec.rb` and `node_edge_cases_spec.rb` now use `TreeHaver.parser_for(:toml)`
172
+ which auto-discovers the best available backend (tree-sitter or Citrus fallback)
173
+ - Tests now work correctly on all platforms (MRI, JRuby, TruffleRuby)
174
+ - Tagged with `:toml_parsing` which passes if ANY toml parser is available
175
+ - **Core specs now use `parser_for` instead of explicit paths**
176
+ - `tree_spec.rb`, `node_spec.rb`, `parser_spec.rb` converted to use `TreeHaver.parser_for(:toml)`
177
+ - All `:toml_grammar` tags changed to `:toml_parsing` for cross-platform compatibility
178
+ - Tests now run on JRuby and TruffleRuby via Citrus/toml-rb fallback
179
+ - FFI backend now properly reports as unavailable on TruffleRuby
180
+ - `ffi_gem_available?` returns `false` on TruffleRuby since tree-sitter uses STRUCT_BY_VALUE return types
181
+ - `FFI.available?` added at module level (was only in Native submodule)
182
+ - Prevents confusing runtime errors (Polyglot::ForeignException) by detecting incompatibility upfront
183
+ - Dependency tags now check `truffleruby?` before attempting FFI backend tests
184
+ - MRI backend now properly reports as unavailable on JRuby and TruffleRuby
185
+ - `available?` returns `false` on non-MRI platforms (C extension only works on MRI)
186
+ - Rust backend now properly reports as unavailable on JRuby and TruffleRuby
187
+ - `available?` returns `false` on non-MRI platforms (magnus requires MRI's C API)
188
+ - Backend compatibility matrix spec now properly skips tests for platform-incompatible backends
189
+ - MRI and Rust backends skip on JRuby/TruffleRuby with clear skip messages
190
+ - FFI backend skips on TruffleRuby with clear skip message
191
+
192
+ ### Changed
193
+
194
+ - **BREAKING: RSpec Dependency Tag Naming Convention Overhaul**
195
+ - All dependency tags now follow consistent naming conventions with suffixes
196
+ - Backend tags now use `*_backend` suffix (e.g., `:commonmarker_backend`, `:markly_backend`)
197
+ - Engine tags now use `*_engine` suffix (e.g., `:mri_engine`, `:jruby_engine`, `:truffleruby_engine`)
198
+ - Grammar tags now use `*_grammar` suffix (e.g., `:bash_grammar`, `:toml_grammar`, `:json_grammar`)
199
+ - Parsing capability tags now use `*_parsing` suffix (e.g., `:toml_parsing`, `:markdown_parsing`)
200
+ - **Migration required**: Update specs using legacy tags:
201
+ - `:commonmarker` → `:commonmarker_backend`
202
+ - `:markly` → `:markly_backend`
203
+ - `:mri` → `:mri_engine`
204
+ - `:jruby` → `:jruby_engine`
205
+ - `:truffleruby` → `:truffleruby_engine`
206
+ - `:tree_sitter_bash` → `:bash_grammar`
207
+ - `:tree_sitter_toml` → `:toml_grammar`
208
+ - `:tree_sitter_json` → `:json_grammar`
209
+ - `:tree_sitter_jsonc` → `:jsonc_grammar`
210
+ - `:toml_backend` → `:toml_parsing`
211
+ - `:markdown_backend` → `:markdown_parsing`
212
+ - **Removed inner-merge dependency tags from tree_haver**
213
+ - Tags `:toml_merge`, `:json_merge`, `:prism_merge`, `:psych_merge` removed
214
+ - These belong in ast-merge gem, not tree_haver
215
+ - Use `require "ast/merge/rspec/dependency_tags"` for merge gem tags
216
+ - **API Consistency**: All backends now have uniform `available?` API at module level:
217
+ - `TreeHaver::Backends::FFI.available?` - checks ffi gem + not TruffleRuby + MRI not loaded
218
+ - `TreeHaver::Backends::MRI.available?` - checks MRI platform + ruby_tree_sitter gem
219
+ - `TreeHaver::Backends::Rust.available?` - checks MRI platform + tree_stump gem
220
+ - `TreeHaver::Backends::Java.available?` - checks JRuby platform + jtreesitter JAR
221
+ - `TreeHaver::Backends::Prism.available?` - checks prism gem (all platforms)
222
+ - `TreeHaver::Backends::Psych.available?` - checks psych stdlib (all platforms)
223
+ - `TreeHaver::Backends::Commonmarker.available?` - checks commonmarker gem (all platforms)
224
+ - `TreeHaver::Backends::Markly.available?` - checks markly gem (all platforms)
225
+ - `TreeHaver::Backends::Citrus.available?` - checks citrus gem (all platforms)
226
+ - README now accurately documents TruffleRuby backend support
227
+ - FFI backend doesn't work on TruffleRuby due to `STRUCT_BY_VALUE` limitation in TruffleRuby's FFI
228
+ - Rust backend (tree_stump) doesn't work due to magnus/rb-sys incompatibility with TruffleRuby's C API
229
+ - TruffleRuby users should use Prism, Psych, Commonmarker, Markly, or Citrus backends
230
+ - Documented confirmed tree-sitter backend limitations:
231
+ - **TruffleRuby**: No tree-sitter backend works (FFI, MRI, Rust all fail)
232
+ - **JRuby**: Only Java and FFI backends work; Rust/MRI don't
233
+ - Updated Rust Backend section with platform compatibility notes
234
+ - Updated FFI Backend section with TruffleRuby limitation details
235
+ - Use kettle-rb/ts-grammar-setup GHA in CI workflows
236
+
237
+ ### Fixed
238
+
239
+ - Rakefile now properly overrides `test` task after `require "kettle/dev"`
240
+ - Works around a bug in kettle-dev where test task runs minitest loader in CI
241
+ - Ensures `rake test` runs RSpec specs instead of empty minitest suite
242
+ - `TreeHaver::RSpec::DependencyTags` now catches TruffleRuby FFI exceptions
243
+ - TruffleRuby's FFI raises `Polyglot::ForeignException` for unsupported types like `STRUCT_BY_VALUE`
244
+ - `ffi_available?` and `libtree_sitter_available?` now return `false` instead of crashing
245
+ - Fixes spec loading errors on TruffleRuby
246
+ - `TreeHaver::Backends::FFI::Language.from_library` now catches `RuntimeError` from TruffleRuby
247
+ - TruffleRuby raises `RuntimeError` instead of `LoadError` when a shared library cannot be opened
248
+ - Now properly converts to `TreeHaver::NotAvailable` with descriptive message
249
+ - `TreeHaver::Backends::FFI::Native.try_load!` now only sets `@loaded = true` after all `attach_function` calls succeed
250
+ - Previously, `loaded?` returned `true` even when `attach_function` failed (e.g., on TruffleRuby)
251
+ - Now `loaded?` correctly returns `false` when FFI functions couldn't be attached
252
+ - Ensures FFI tests are properly skipped on TruffleRuby
253
+
33
254
  ## [3.1.2] - 2025-12-29
34
255
 
35
256
  - TAG: [v3.1.2][3.1.2t]
@@ -340,7 +561,7 @@ Please file a bug if you notice a violation of semantic versioning.
340
561
  - Shows when TREE_SITTER_*_PATH is set but points to nonexistent file
341
562
  - Provides helpful guidance for setting environment variables correctly
342
563
  - Fixed registry conflicts when registering multiple backend types for the same language
343
- - Fixed `CitrusGrammarFinder` to properly handle gems with non-standard require paths (e.g., `toml-rb.rb` vs `toml/rb.rb`)
564
+ - Fixed `CitrusGrammarFinder` to use gem name as-is for require path (e.g., `require "toml-rb"` not `require "toml/rb"`)
344
565
  - Fixed Citrus backend infinite recursion in `Node#extract_type_from_event`
345
566
  - Added cycle detection to prevent stack overflow when traversing recursive grammar structures
346
567
 
@@ -438,7 +659,11 @@ Despite the major version bump to 3.0.0 (following semver due to the breaking `L
438
659
 
439
660
  - Initial release
440
661
 
441
- [Unreleased]: https://github.com/kettle-rb/tree_haver/compare/v3.1.2...HEAD
662
+ [Unreleased]: https://github.com/kettle-rb/tree_haver/compare/v3.2.1...HEAD
663
+ [3.2.1]: https://github.com/kettle-rb/tree_haver/compare/v3.2.0...v3.2.1
664
+ [3.2.1t]: https://github.com/kettle-rb/tree_haver/releases/tag/v3.2.1
665
+ [3.2.0]: https://github.com/kettle-rb/tree_haver/compare/v3.1.2...v3.2.0
666
+ [3.2.0t]: https://github.com/kettle-rb/tree_haver/releases/tag/v3.2.0
442
667
  [3.1.2]: https://github.com/kettle-rb/tree_haver/compare/v3.1.1...v3.1.2
443
668
  [3.1.2t]: https://github.com/kettle-rb/tree_haver/releases/tag/v3.1.2
444
669
  [3.1.1]: https://github.com/kettle-rb/tree_haver/compare/v3.1.0...v3.1.1