From ec0ec4a10368637fb4415ab5a9bac23fa5fc8a5e Mon Sep 17 00:00:00 2001 From: "zizhou teng (n451)" <2020200706@ruc.edu.cn> Date: Wed, 28 Jan 2026 14:44:47 +0000 Subject: [PATCH] feat(install): support custom env when generating the parser --- lua/nvim-treesitter/_meta/parsers.lua | 3 +++ lua/nvim-treesitter/install.lua | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lua/nvim-treesitter/_meta/parsers.lua b/lua/nvim-treesitter/_meta/parsers.lua index 3a97b35a5..54b613699 100644 --- a/lua/nvim-treesitter/_meta/parsers.lua +++ b/lua/nvim-treesitter/_meta/parsers.lua @@ -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 ---@class ParserInfo --- diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index 1020e7da9..82cb1cf6e 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -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