From 2a20484a1454d7ba91644b00505df1f4457b94d6 Mon Sep 17 00:00:00 2001 From: kiyan42 Date: Mon, 29 Jun 2020 16:16:18 +0200 Subject: fix: remove goto statements --- lua/nvim-treesitter/install.lua | 45 ++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 21 deletions(-) (limited to 'lua') diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index e9198712..3805750b 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -120,6 +120,29 @@ local function run_install(cache_folder, package_path, lang, repo, with_sync) end end +local function install_lang(lang, ask_reinstall, cache_folder, package_path, with_sync) + if #api.nvim_get_runtime_file('parser/'..lang..'.so', false) > 0 then + if not ask_reinstall then return end + + local yesno = fn.input(lang .. ' parser already available: would you like to reinstall ? y/n: ') + print('\n ') -- mandatory to avoid messing up command line + if not string.match(yesno, '^y.*') then return end + end + + local parser_config = parsers.get_parser_configs()[lang] + if not parser_config then + return api.nvim_err_writeln('Parser not available for language '..lang) + end + + local install_info = parser_config.install_info + vim.validate { + url={ install_info.url, 'string' }, + files={ install_info.files, 'table' } + } + + run_install(cache_folder, package_path, lang, install_info, with_sync) +end + -- TODO(kyazdani): this should work on windows too local function install(with_sync) return function (...) @@ -145,27 +168,7 @@ local function install(with_sync) end for _, lang in ipairs(languages) do - if #api.nvim_get_runtime_file('parser/'..lang..'.so', false) > 0 then - if not ask_reinstall then goto continue end - - local yesno = fn.input(lang .. ' parser already available: would you like to reinstall ? y/n: ') - print('\n ') -- mandatory to avoid messing up command line - if not string.match(yesno, '^y.*') then goto continue end - end - - local parser_config = parsers.get_parser_configs()[lang] - if not parser_config then - return api.nvim_err_writeln('Parser not available for language '..lang) - end - - local install_info = parser_config.install_info - vim.validate { - url={ install_info.url, 'string' }, - files={ install_info.files, 'table' } - } - - run_install(cache_folder, package_path, lang, install_info, with_sync) - ::continue:: + install_lang(lang, ask_reinstall, cache_folder, package_path, with_sync) end end end -- cgit v1.2.3