diff options
author | TJ DeVries <devries.timothyj@gmail.com> | 2021-03-30 16:40:29 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-30 16:40:29 -0400 |
commit | 240cec9192802db4f166c092428087180e4d3214 (patch) | |
tree | 22726ca9f25d60bd34029bdcf5406036946cc81a | |
parent | f89bfa68692540c2a28794297ce2ab63892de410 (diff) | |
download | rneovim-240cec9192802db4f166c092428087180e4d3214.tar.gz rneovim-240cec9192802db4f166c092428087180e4d3214.tar.bz2 rneovim-240cec9192802db4f166c092428087180e4d3214.zip |
ts: Add language version to vim.treesitter (#14255)
-rw-r--r-- | runtime/doc/treesitter.txt | 6 | ||||
-rw-r--r-- | runtime/lua/vim/treesitter.lua | 2 | ||||
-rw-r--r-- | src/nvim/lua/executor.c | 11 | ||||
-rw-r--r-- | src/nvim/lua/treesitter.c | 2 |
4 files changed, 19 insertions, 2 deletions
diff --git a/runtime/doc/treesitter.txt b/runtime/doc/treesitter.txt index 1696d3b9ba..343f4a62c2 100644 --- a/runtime/doc/treesitter.txt +++ b/runtime/doc/treesitter.txt @@ -32,6 +32,12 @@ retained for the lifetime of a buffer but this is subject to change. A plugin should keep a reference to the parser object as long as it wants incremental updates. + *vim.treesitter.language_version* +To check which language version is compiled with neovim, the number is stored +within `vim.treesitter.language_version`. This number is not too helpful +unless you are wondering about compatibility between different versions of +compiled grammars. + Parser files *treesitter-parsers* Parsers are the heart of tree-sitter. They are libraries that tree-sitter will diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua index 64a5ba1fd8..cac0ab864b 100644 --- a/runtime/lua/vim/treesitter.lua +++ b/runtime/lua/vim/treesitter.lua @@ -10,6 +10,8 @@ local parsers = {} local M = vim.tbl_extend("error", query, language) +M.language_version = vim._ts_get_language_version() + setmetatable(M, { __index = function (t, k) if k == "highlighter" then diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 310b194c8c..03d178467b 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1272,6 +1272,12 @@ bool nlua_exec_file(const char *path) return true; } +int tslua_get_language_version(lua_State *L) +{ + lua_pushnumber(L, TREE_SITTER_LANGUAGE_VERSION); + return 1; +} + static void nlua_add_treesitter(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL { tslua_init(lstate); @@ -1288,8 +1294,11 @@ static void nlua_add_treesitter(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL lua_pushcfunction(lstate, tslua_inspect_lang); lua_setfield(lstate, -2, "_ts_inspect_language"); - lua_pushcfunction(lstate, ts_lua_parse_query); + lua_pushcfunction(lstate, tslua_parse_query); lua_setfield(lstate, -2, "_ts_parse_query"); + + lua_pushcfunction(lstate, tslua_get_language_version); + lua_setfield(lstate, -2, "_ts_get_language_version"); } int nlua_expand_pat(expand_T *xp, diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index 33974c71cb..188b2c1ef7 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -1109,7 +1109,7 @@ static int querycursor_gc(lua_State *L) // Query methods -int ts_lua_parse_query(lua_State *L) +int tslua_parse_query(lua_State *L) { if (lua_gettop(L) < 2 || !lua_isstring(L, 1) || !lua_isstring(L, 2)) { return luaL_error(L, "string expected"); |