aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2022-01-22 11:02:55 +0100
committerChristian Clason <christian.clason@uni-due.de>2022-01-22 22:56:50 +0100
commitbb319daf5f374064e824f84f1f7cda487313af4e (patch)
treecbcd3a473db29d8a7b407c98183ee9be689aa2b0 /lua
parentci: fix cache path for rust cargo (diff)
downloadnvim-treesitter-bb319daf5f374064e824f84f1f7cda487313af4e.tar
nvim-treesitter-bb319daf5f374064e824f84f1f7cda487313af4e.tar.gz
nvim-treesitter-bb319daf5f374064e824f84f1f7cda487313af4e.tar.bz2
nvim-treesitter-bb319daf5f374064e824f84f1f7cda487313af4e.tar.lz
nvim-treesitter-bb319daf5f374064e824f84f1f7cda487313af4e.tar.xz
nvim-treesitter-bb319daf5f374064e824f84f1f7cda487313af4e.tar.zst
nvim-treesitter-bb319daf5f374064e824f84f1f7cda487313af4e.zip
feat: specify abi version for generate on newer ts cli
Check tree-sitter CLI version and if > 0.20.3 and generating a parser from grammar, use `--abi=vim.treesitter.language_version`. Besides being able to opt-in to newer ABI benefits, this is a necessary workaround for an upstream bug with 0.20.3, where `parser.h` is not generated if the (optional) `--abi` flag is omitted.
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-treesitter/health.lua7
-rw-r--r--lua/nvim-treesitter/install.lua12
-rw-r--r--lua/nvim-treesitter/utils.lua9
3 files changed, 22 insertions, 6 deletions
diff --git a/lua/nvim-treesitter/health.lua b/lua/nvim-treesitter/health.lua
index 996a87f2a..b26a9ef25 100644
--- a/lua/nvim-treesitter/health.lua
+++ b/lua/nvim-treesitter/health.lua
@@ -5,6 +5,7 @@ local queries = require "nvim-treesitter.query"
local info = require "nvim-treesitter.info"
local shell = require "nvim-treesitter.shell_command_selectors"
local install = require "nvim-treesitter.install"
+local utils = require "nvim-treesitter.utils"
local health_start = vim.fn["health#report_start"]
local health_ok = vim.fn["health#report_ok"]
@@ -24,13 +25,9 @@ local function install_health()
.. " not required for :TSInstall)"
)
else
- local handle = io.popen "tree-sitter -V"
- local result = handle:read "*a"
- handle:close()
- local version = vim.split(result, "\n")[1]:match "[^tree%psitter].*"
health_ok(
"`tree-sitter` found "
- .. (version or "(unknown version)")
+ .. (utils.ts_cli_version() or "(unknown version)")
.. " (parser generator, only needed for :TSInstallFromGrammar)"
)
end
diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua
index 5362c8604..4b187f74c 100644
--- a/lua/nvim-treesitter/install.lua
+++ b/lua/nvim-treesitter/install.lua
@@ -14,6 +14,7 @@ local lockfile = {}
M.compilers = { vim.fn.getenv "CC", "cc", "gcc", "clang", "cl", "zig" }
M.prefer_git = fn.has "win32" == 1
M.command_extra_args = {}
+M.ts_generate_args = nil
local started_commands = 0
local finished_commands = 0
@@ -259,6 +260,15 @@ local function run_install(cache_folder, install_folder, lang, repo, with_sync,
)
end
return
+ else
+ if not M.ts_generate_args then
+ local ts_cli_version = utils.ts_cli_version()
+ if ts_cli_version and vim.split(ts_cli_version, " ")[1] > "0.20.2" then
+ M.ts_generate_args = { "generate", "--abi", vim.treesitter.language_version }
+ else
+ M.ts_generate_args = { "generate" }
+ end
+ end
end
if generate_from_grammar and vim.fn.executable "node" ~= 1 then
api.nvim_err_writeln "Node JS not found: `node` is not executable!"
@@ -308,7 +318,7 @@ local function run_install(cache_folder, install_folder, lang, repo, with_sync,
info = "Generating source files from grammar.js...",
err = 'Error during "tree-sitter generate"',
opts = {
- args = { "generate" },
+ args = M.ts_generate_args,
cwd = compile_location,
},
},
diff --git a/lua/nvim-treesitter/utils.lua b/lua/nvim-treesitter/utils.lua
index e6a6358a9..0e8364045 100644
--- a/lua/nvim-treesitter/utils.lua
+++ b/lua/nvim-treesitter/utils.lua
@@ -193,4 +193,13 @@ function M.to_func(a)
return type(a) == "function" and a or M.constant(a)
end
+function M.ts_cli_version()
+ if fn.executable "tree-sitter" == 1 then
+ local handle = io.popen "tree-sitter -V"
+ local result = handle:read "*a"
+ handle:close()
+ return vim.split(result, "\n")[1]:match "[^tree%psitter ].*"
+ end
+end
+
return M