feat(install): support custom env when generating the parser

This commit is contained in:
zizhou teng (n451) 2026-01-28 14:44:47 +00:00
parent f8bbc3177d
commit ec0ec4a103
2 changed files with 5 additions and 1 deletions

View file

@ -26,6 +26,9 @@ error('Cannot require a meta file')
---
---Directory with queries to be installed
---@field queries? string
---
---Envrionment variables for generating the parser
---@field env table<string, string|number>
---@class ParserInfo
---

View file

@ -167,6 +167,7 @@ end
---@param compile_location string
---@return string? err
local function do_generate(logger, repo, compile_location)
local env = vim.tbl_extend('force', { TREE_SITTER_JS_RUNTIME = 'native' }, repo.env)
local from_json = true
if repo.generate_from_json == false then
from_json = false
@ -182,7 +183,7 @@ local function do_generate(logger, repo, compile_location)
'--abi',
tostring(vim.treesitter.language_version),
from_json and 'src/grammar.json' or nil,
}, { cwd = compile_location, env = { TREE_SITTER_JS_RUNTIME = 'native' } })
}, { cwd = compile_location, env = env })
if r.code > 0 then
return logger:error('Error during "tree-sitter generate": %s', r.stderr)
end