Add @Native annotation support for tree-sitter-dart and tree-sitter C API bindings#87
Add @Native annotation support for tree-sitter-dart and tree-sitter C API bindings#87
Conversation
Co-authored-by: TimWhiting <15617545+TimWhiting@users.noreply.github.com>
Co-authored-by: TimWhiting <15617545+TimWhiting@users.noreply.github.com>
|
@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 <15617545+TimWhiting@users.noreply.github.com>
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 <15617545+TimWhiting@users.noreply.github.com>
Updated! I've configured ffigen to generate
The bindings will use Commit: 31e8235 |
|
@copilot |
Co-authored-by: TimWhiting <15617545+TimWhiting@users.noreply.github.com>
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
@Nativeannotation, 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@Nativeannotations.Overview
The native bindings are integrated into the existing
tree_sitterpackage (not in a separatebindings/dartdirectory). 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
@Nativeannotation for efficient static linkingChanges to tree_sitter Package
The updates include:
lib/src/dart_language.dart) -treeSitterDart()function using@NativeannotationParser.fromLanguage()constructor for native language bindingslib/src/generated_bindings.dart,lib/src/parser_generated_bindings.dart) - All tree-sitter C API functions now use@Nativeannotationslib/tree_sitter.dart) - Refactored to call@Nativefunctions directlyTreeSitterclass 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@Nativeannotations 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@Nativeapproach provides:Regenerating Bindings
The ffigen configuration files have been updated to generate
@Nativeannotations. To regenerate the bindings:This will generate updated bindings with
@Nativeannotations for all tree-sitter C API functions.Note: The generated bindings use
@Nativewithout 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
@Nativeannotation 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.