helixbass / tree-sitter-grep

The Unlicense
10 stars 1 forks source link

Load dynamic library for matching #8

Closed helixbass closed 1 year ago

helixbass commented 1 year ago

In this PR:

To test: At the moment I included an example plugin in the committed code (though I'd plan on removing it before merging) so you should be able to run cargo build --release --all from the (workspace) root and then run eg ./target/release/tree-sitter-grep -l rust --filter ./target/release/libfilter_after_line_number.dylib --filter-arg 100 ./reference-parameters.scm (the path to the built dynamic library may be different (*.so?) if you aren't on a Mac?) and see a list of reference-type'd function parameters that occur on line numbers after 100

If you (then) run ./target/release/tree-sitter-grep -l rust --filter ./target/release/libfilter_after_line_number.dylib ./reference-parameters.scm you should see an ugly error that it expected you to supply a configuring argument to the filter (via the --filter-arg/-a command-line argument)

If you run ./target/release/tree-sitter-grep -l rust --filter ./target/release/libfilter_after_line_number.dylib -a whee ./reference-parameters.scm you should see an ugly error that the passed filter-argument argument wasn't of the expected parse-able type (ie usize)

You should still be able to invoke without passing a --filter/-f argument

If you're curious about performance, you should be able to observe (eg via the time command?)/it appeared that there was no significant difference in total time (I measured against running queries against the Typescript compiler in Rust codebase) when running with a dynamically-loaded filter vs without

You should be able to create, build + use a different filter (eg one that doesn't accept/require a configuring argument)

helixbass commented 1 year ago

Closing in favor of #9