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.
This commit is contained in:
Christian Clason 2022-01-22 11:02:55 +01:00 committed by Christian Clason
parent 020905ff26
commit bb319daf5f
3 changed files with 22 additions and 6 deletions

View file

@ -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,
},
},