aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/lua/executor.c
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2019-06-06 12:20:07 +0200
committerBjörn Linse <bjorn.linse@gmail.com>2019-09-28 14:31:03 +0200
commit0e0beef85e4d3932e0d49528d8474794f7b69b01 (patch)
tree44be39a26948d4859afc851de277f4ea2ebf333c /src/nvim/lua/executor.c
parentcd100963866b2c33a286cbf6aac8e42cd16fd248 (diff)
downloadrneovim-0e0beef85e4d3932e0d49528d8474794f7b69b01.tar.gz
rneovim-0e0beef85e4d3932e0d49528d8474794f7b69b01.tar.bz2
rneovim-0e0beef85e4d3932e0d49528d8474794f7b69b01.zip
tree-sitter: load parsers as .so files
Diffstat (limited to 'src/nvim/lua/executor.c')
-rw-r--r--src/nvim/lua/executor.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index 8b0140f794..1794cee8d8 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -834,16 +834,31 @@ static int unsafe_ptr_to_ts_tree(lua_State *L)
static int create_tslua_parser(lua_State *L)
{
- TSLanguage *tree_sitter_c(void), *tree_sitter_javascript(void);
-
- if (!lua_gettop(L)) {
+ if (lua_gettop(L) < 2) {
return 0;
}
- char *str = lua_tostring(L,1);
+ const char *path = lua_tostring(L,1);
+ const char *lang_name = lua_tostring(L,2);
+
+ // TODO: unsafe!
+ char symbol_buf[128] = "tree_sitter_";
+ STRCAT(symbol_buf, lang_name);
+
+ // TODO: we should maybe keep the uv_lib_t around, and close them
+ // at exit, to keep LeakSanitizer happy.
+ uv_lib_t lib;
+ if (uv_dlopen(path, &lib)) {
+ return luaL_error(L, "uv_dlopen: %s", uv_dlerror(&lib));
+ }
+
+ TSLanguage *(*lang_parser)(void);
+ if (uv_dlsym(&lib, symbol_buf, (void **)&lang_parser)) {
+ return luaL_error(L, "uv_dlsym: %s", uv_dlerror(&lib));
+ }
- TSLanguage *lang = tree_sitter_c();
- if (str && striequal(str, "javascript")) {
- lang = tree_sitter_javascript();
+ TSLanguage *lang = lang_parser();
+ if (lang == NULL) {
+ return luaL_error(L, "failed to load parser");
}
tslua_push_parser(L, lang);
return 1;