diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/nvim/lua/treesitter.c | 20 | 
1 files changed, 16 insertions, 4 deletions
diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index 5258352e72..7df8afad62 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -176,10 +176,11 @@ int tslua_add_language(lua_State *L)    }    uint32_t lang_version = ts_language_version(lang); -  if (lang_version < TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION) { +  if (lang_version < TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION +      || lang_version > TREE_SITTER_LANGUAGE_VERSION) {      return luaL_error(          L, -        "ABI version mismatch : expected %" PRIu32 ", found %" PRIu32, +        "ABI version mismatch : expected %d, found %d",          TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION, lang_version);    } @@ -246,7 +247,12 @@ int tslua_push_parser(lua_State *L)    }    TSParser *parser = ts_parser_new(); -  ts_parser_set_language(parser, lang); + +  if (!ts_parser_set_language(parser, lang)) { +    ts_parser_delete(parser); +    return luaL_error(L, "Failed to load language : %s", lang_name); +  } +    TSLua_parser *p = lua_newuserdata(L, sizeof(TSLua_parser));  // [udata]    p->parser = parser;    p->tree = NULL; @@ -342,7 +348,7 @@ static int parser_parse(lua_State *L)      return 0;    } -  TSTree *new_tree; +  TSTree *new_tree = NULL;    size_t len;    const char *str;    long bufnr; @@ -374,6 +380,12 @@ static int parser_parse(lua_State *L)        return luaL_error(L, "invalid argument to parser:parse()");    } +  // Sometimes parsing fails (timeout, or wrong parser ABI) +  // In those case, just return an error. +  if (!new_tree) { +    return luaL_error(L, "An error occured when parsing."); +  } +    uint32_t n_ranges = 0;    TSRange *changed = p->tree ? ts_tree_get_changed_ranges(p->tree, new_tree,                                                            &n_ranges) : NULL;  | 
