From c70daa36dcc2fdae113637fba76350daaf62dba5 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sun, 21 Apr 2024 00:14:12 +0200 Subject: feat(install)!: add explicit path field to parser info (#6476) Problem: Using `url` for both remote repo and local path complicates the code. Solution: Add `path` field that overrides `url` and bypasses git-specific manipulations, i.e., the contents of the `path` are used as-is (no git repo needed). This means `:TSUpdate` will skip such parsers; use `:TSInstall!` instead after making local changes. --------- Co-authored-by: Lewis Russell --- lua/nvim-treesitter/install.lua | 98 +++++++++++++++------------------------- lua/nvim-treesitter/parsers.lua | 33 +++++++------- runtime/queries/rust/indents.scm | 1 + 3 files changed, 55 insertions(+), 77 deletions(-) diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index 1bb7d6fea..57671d7d3 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -123,28 +123,6 @@ end --- PARSER MANAGEMENT FUNCTIONS --- ---- @param repo InstallInfo ---- @param project_name string ---- @param cache_dir string ---- @param from_local_path boolean ---- @return string -local function get_compile_location(repo, cache_dir, project_name, from_local_path) - ---@type string compile_location only needed for typescript installs. - if from_local_path then - local compile_location = repo.url - if repo.location then - compile_location = fs.joinpath(compile_location, repo.location) - end - return compile_location - end - - local repo_location = project_name - if repo.location then - repo_location = fs.joinpath(repo_location, repo.location) - end - return fs.joinpath(cache_dir, repo_location) -end - local function istring(c) return type(c) == 'string' end @@ -168,6 +146,10 @@ end --- @param compile_location string --- @return string? err local function do_generate_from_grammar(logger, repo, compile_location) + if not executable('tree-sitter') then + return logger:error('tree-sitter CLI not found: `tree-sitter` is not executable') + end + if repo.generate_requires_npm then if not executable('npm') then return logger:error('NPM requires to be installed from grammar.js') @@ -400,23 +382,29 @@ local function can_download_tar(repo) end -- Returns the compile command based on the OS and user options +---@param logger Logger ---@param repo InstallInfo ---@param cc string ---@param compile_location string ----@return vim.SystemCompleted -local function do_compile(repo, cc, compile_location) +--- @return string? err +local function do_compile(logger, repo, cc, compile_location) local args = vim.tbl_flatten(select_compiler_args(repo, cc)) local cmd = vim.list_extend({ cc }, args) - return system(cmd, { cwd = compile_location }) + logger:info('Compiling parser') + + local r = system(cmd, { cwd = compile_location }) + if r.code > 0 then + return logger:error('Error during compilation: %s', r.stderr) + end end ---@param lang string ---@param cache_dir string ---@param install_dir string ----@param generate_from_grammar? boolean +---@param generate? boolean ---@return string? err -local function install_lang0(lang, cache_dir, install_dir, generate_from_grammar) +local function install_lang0(lang, cache_dir, install_dir, generate) local logger = log.new('install/' .. lang) local repo = get_parser_install_info(lang) @@ -429,50 +417,43 @@ local function install_lang0(lang, cache_dir, install_dir, generate_from_grammar local project_name = 'tree-sitter-' .. lang - generate_from_grammar = repo.requires_generate_from_grammar or generate_from_grammar - - if generate_from_grammar and not executable('tree-sitter') then -