elisp-tree-sitter
elisp-tree-sitter copied to clipboard
Reload shared (grammar) library within an emacs session
Is it possible to reload the .so shared library for a grammar within the current emacs session? Nothing else would change besides the shared library being updated from a more recent compile.
I've been testing this to attempt to get the shared object to reload.
I've noticed that `tree-sitter-require' is returning the same object between compiles of the grammar (in which the grammar has changed), but different objects when I launch a new emacs session:
Prior to recompile with changes:
#<user-ptr ptr=0x7ff63fef4da0 finalizer=0x7ff6441f9c60>
After recompile with changes:
#<user-ptr ptr=0x7ff63fef4da0 finalizer=0x7ff6441f9c60>
After launching a new emacs session:
#<user-ptr ptr=0x7f072d873da0 finalizer=0x7f072d98ec60>
tsc--load-language
is also returning the same object even when a new shared object file including a change to the grammar is used.
It seems that the issue is either with the emacs modules interface or the underlying rust code. I found the _load_language
function in lang.rs
which seems to be responsible for loading the shared object. Unfortunately I'm unfamiliar with both rust and the emacs modules interface.
It's possible, by first unloading the old grammar.
- Run cleanup code in affected
tree-sitter-mode
buffers. - Unload the old shared object, by removing the corresponding language from
LANG_INFOS
. - Load the language again.
- Re-initialize
tree-sitter-mode
in affected buffers.
It is a bit unsafe, as the old grammar may still be held by user code somewhere. However, it would mostly affect libraries that manage the lifecycle of the parsers and the syntax trees on their own. Libraries that rely on tree-sitter-mode
to do so should be fine.