-
Notifications
You must be signed in to change notification settings - Fork 53
Add @Native annotation support for tree-sitter-dart and tree-sitter C API bindings #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: TimWhiting <[email protected]>
Co-authored-by: TimWhiting <[email protected]>
@copilot Don't create a new bindings directory. We already have a folder tree_sitter_dart with bindings. Please use / update the config for Dart's ffigen. |
…itter package Co-authored-by: TimWhiting <[email protected]>
Updated! I've removed the bindings/dart directory and instead added @Native annotation support directly to the tree_sitter package:
Commit: 1f57a16 |
@copilot I also want the generated bindings for tree-sitter itself to be updated to use @Native. See https://github.com/UserNobody14/tree-sitter-dart/blob/master/tree_sitter/api_config.yaml which needs to be updated. |
…I bindings Co-authored-by: TimWhiting <[email protected]>
Updated! I've configured ffigen to generate
The bindings will use Commit: 31e8235 |
@copilot |
Co-authored-by: TimWhiting <[email protected]>
Done! I've regenerated the bindings with
Tests: Both test cases pass successfully:
The bindings now use Commit: (in progress) Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
This PR adds native Dart bindings using Dart's
@Native
annotation, providing a modern, efficient alternative to dynamic library loading. The changes include both a native binding for the tree-sitter-dart language grammar and fully regenerated bindings for all tree-sitter C API functions using@Native
annotations.Overview
The native bindings are integrated into the existing
tree_sitter
package (not in a separatebindings/dart
directory). This approach adds a newtreeSitterDart()
function andParser.fromLanguage()
constructor while maintaining full backward compatibility with the existing dynamic library loading approach.Key Features
Modern Native FFI Support
@Native
annotation for efficient static linkingChanges to tree_sitter Package
The updates include:
lib/src/dart_language.dart
) -treeSitterDart()
function using@Native
annotationParser.fromLanguage()
constructor for native language bindingslib/src/generated_bindings.dart
,lib/src/parser_generated_bindings.dart
) - All tree-sitter C API functions now use@Native
annotationslib/tree_sitter.dart
) - Refactored to call@Native
functions directlyTreeSitter
class wrapper to maintain API compatibilityexample/tree_sitter.dart
) - Demonstrates both dynamic loading and native binding approachestest/tree_sitter_test.dart
) - Validates both usage patterns with passing testsapi_config.yaml
,parser_config.yaml
) - Configured to generate@Native
annotations for tree-sitter C API bindingsREADME.md
,CHANGELOG.md
) - Installation and usage instructions for both approaches, including how to regenerate bindingsAPI Design
Benefits Over Dynamic Loading
The traditional approach uses
DynamicLibrary.open()
to load shared libraries at runtime. This new@Native
approach provides:Regenerating Bindings
The ffigen configuration files have been updated to generate
@Native
annotations. To regenerate the bindings:This will generate updated bindings with
@Native
annotations for all tree-sitter C API functions.Note: The generated bindings use
@Native
without asset IDs, relying onDynamicLibrary.process()
for symbol resolution. When running tests, you'll need to preload the libraries:Testing
✅ Both test cases pass successfully:
The implementation has been validated to work correctly with both approaches.
Compatibility
@Native
annotation support), updated to support up to 4.0.0Fixes #86
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.