Skip to content

Conversation

@odenix
Copy link
Contributor

@odenix odenix commented Dec 6, 2024

To demonstrate that this PR solves a real problem, I've updated pkl-lsp here to no longer patch and build java-tree-sitter from source.

Motivation:

  • Enable clients to customize the SymbolLookup used for the tree-sitter native library. For example, clients can use this capability to embed the tree-sitter native library in their JAR, which is a common way to solve the native library distribution problem.

Changes:

  • Add interface NativeLibraryLookup.
  • Add class ChainedLibraryLookup, which loads NativeLibraryLookup implementations using java.util.ServiceLoader and chains the SymbolLookup's returned by them.
  • Change TreeSitter.java patch to delegate to ChainedLibraryLookup.
  • Update build instructions in README.
  • Fix execution of jextract.ps1 script in Windows build.

Result:

  • Clients that need to customize the SymbolLookup used for the tree-sitter native library no longer need to patch and build java-tree-sitter from source.

@ObserverOfTime
Copy link
Member

I would appreciate your thoughts on this. @Marcono1234 @bioball

Copy link
Contributor

@Marcono1234 Marcono1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me this ServiceLoader approach looks quite useful. One small suggestion: It might be nice if NativeLibraryLookup#get could permit users to use their own Arena. (With the current implementation it seems that is possible, but it would be good if it was officially documented as supported.)

For example something like this:

    /*
     * ...
     * @param arena an arena for the symbol lookup; library lookups can instead
     *     at their own risk use their own arena, but must make sure it is not
     *     closed while tree-sitter is still in use
     * ...
     */
    SymbolLookup get(Arena arena);

For Windows this could be useful when loading the library from a temp file, because you can only delete the temp file when the library is unloaded (by calling Arena#close, so you need to provide your own Arena).

Would that be ok @ObserverOfTime?

@ObserverOfTime ObserverOfTime force-pushed the master branch 3 times, most recently from ab995e8 to 7369f7f Compare December 8, 2024 12:53
@bioball
Copy link

bioball commented Dec 20, 2024

This looks great! This is basically what I was looking for when I opened #36.

@Emmeral
Copy link
Contributor

Emmeral commented Jan 3, 2025

Any updates on when this will be merged?

@ObserverOfTime
Copy link
Member

After tree-sitter 0.25 is released.

Enable clients to customize the SymbolLookup used for the tree-sitter native library.
For example, clients can use this capability to embed the tree-sitter native library
in their JAR, which is a common way to solve the native library distribution problem.
@ObserverOfTime ObserverOfTime merged commit 6ae5953 into tree-sitter:master Feb 7, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants