From 62786ec7c60ea29cbbd48ae658cde7042dba4bb3 Mon Sep 17 00:00:00 2001 From: kiyan42 Date: Wed, 22 Apr 2020 11:13:05 +0200 Subject: feat/refacto: improve configurations - You should now get the configs through functions - Configs for languages are now inside a local object called parsers - You can get the parser installation configurations with `get_parser_configs` - A new object has been initialized inside configs to specify module config (called config). - Provide functions to enable/disable a module on one buffer - Provide functions to enable/disable a module on all buffers, and if filetype is specified, for specific filetype - Provide function to determine if module is activated for a specified filetype --- lua/nvim-treesitter/install.lua | 49 +++++++---------------------------------- 1 file changed, 8 insertions(+), 41 deletions(-) (limited to 'lua/nvim-treesitter/install.lua') diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index b00d3d77..be09a3bc 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -1,7 +1,8 @@ local api = vim.api local fn = vim.fn local luv = vim.loop -local repositories = require'nvim-treesitter/configs'.repositories +local configs = require'nvim-treesitter/configs' +local parsers = configs.get_parser_configs() local M = {} @@ -118,14 +119,15 @@ local function install(ft) if not string.match(yesno, '^y.*') then return end end - local repository = repositories[ft] - if not repository then + local parser_config = parsers[ft] + if not parser_config then return api.nvim_err_writeln('Parser not available for language '..ft) end + local install_info = parser_config.install_info vim.validate { - url={ repository.url, 'string' }, - files={ repository.files, 'table' } + url={ install_info.url, 'string' }, + files={ install_info.files, 'table' } } if fn.executable('git') == 0 then @@ -138,24 +140,7 @@ local function install(ft) local cache_folder, err = get_cache_dir() if err then return api.nvim_err_writeln(err) end - run_install(cache_folder, package_path, ft, repository) -end - -local function install_info() - local max_len = 0 - for parser_name, _ in pairs(repositories) do - if #parser_name > max_len then max_len = #parser_name end - end - - for parser_name, _ in pairs(repositories) do - local is_installed = #api.nvim_get_runtime_file('parser/'..parser_name..'.so', false) > 0 - api.nvim_out_write(parser_name..string.rep(' ', max_len - #parser_name + 1)) - if is_installed then - api.nvim_out_write("[✓] installed\n") - else - api.nvim_out_write("[✗] not installed\n") - end - end + run_install(cache_folder, package_path, ft, install_info) end M.commands = { @@ -166,25 +151,7 @@ M.commands = { "-complete=custom,v:lua.ts_installable_parsers" }, description = '`:TSInstall {ft}` installs a parser under nvim-treesitter/parser/{name}.so' - }, - TSInstallInfo = { - run = install_info, - args = { "-nargs=0" }, - description = '`:TSInstallInfo` print installation state for every filetype' } } -function M.setup() - for command_name, def in pairs(M.commands) do - local call_fn = string.format("lua require'nvim-treesitter.install'.commands.%s.run()", command_name) - local parts = vim.tbl_flatten({ - "command!", - def.args, - command_name, - call_fn, - }) - api.nvim_command(table.concat(parts, " ")) - end -end - return M -- cgit v1.2.3 From f8029cfc6463c35e76e38ba428688eb259f9e62c Mon Sep 17 00:00:00 2001 From: kiyan42 Date: Mon, 27 Apr 2020 15:27:59 +0200 Subject: fix install by changing cc arguments position --- lua/nvim-treesitter/install.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lua/nvim-treesitter/install.lua') diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index be09a3bc..ca84ac03 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -34,9 +34,9 @@ local function get_cache_dir() end local function iter_cmd(cmd_list, i, ft) - if i == #cmd_list then return print('Treesitter parser for '..ft..' has been installed') end + if i == #cmd_list + 1 then return print('Treesitter parser for '..ft..' has been installed') end - local attr = cmd_list[i + 1] + local attr = cmd_list[i] if attr.info then print(attr.info) end handle = luv.spawn(attr.cmd, attr.opts, vim.schedule_wrap(function(code) @@ -76,12 +76,12 @@ local function run_install(cache_folder, package_path, ft, repo) args = vim.tbl_flatten({ '-o', 'parser.so', + '-I./src', + repo.files, '-shared', + '-Os', '-lstdc++', '-fPIC', - '-Os', - '-I./src', - repo.files }), cwd = compile_location } @@ -100,7 +100,7 @@ local function run_install(cache_folder, package_path, ft, repo) } } - iter_cmd(command_list, 0, ft) + iter_cmd(command_list, 1, ft) end -- TODO(kyazdani): this should work on windows too -- cgit v1.2.3 From 6b2d76153fa0d3b65f6c7b1b28dd2554979aaeee Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Thu, 30 Apr 2020 22:11:44 +0200 Subject: Add function 'nvim-treesitter/install'.ensure_installed --- lua/nvim-treesitter/install.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lua/nvim-treesitter/install.lua') diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index ca84ac03..298a0e9f 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -3,6 +3,7 @@ local fn = vim.fn local luv = vim.loop local configs = require'nvim-treesitter/configs' local parsers = configs.get_parser_configs() +local has_parser = require'nvim-treesitter/parsers'.has_parser local M = {} @@ -143,6 +144,24 @@ local function install(ft) run_install(cache_folder, package_path, ft, install_info) end + +M.ensure_installed = function(languages) + if type(languages) == 'string' then + if languages == 'all' then + languages = configs.available_parsers() + else + languages = {languages} + end + end + + for _, ft in ipairs(languages) do + if not has_parser(ft) then + install(ft) + end + end +end + + M.commands = { TSInstall = { run = install, -- cgit v1.2.3 From 0b4cdba3e49d77d5914af38e29c46229d9cd059a Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Fri, 1 May 2020 10:30:25 +0200 Subject: Avoid global handle to enable installing multiple parsers in parallel --- lua/nvim-treesitter/install.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lua/nvim-treesitter/install.lua') diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index 298a0e9f..77e0fccc 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -40,9 +40,11 @@ local function iter_cmd(cmd_list, i, ft) local attr = cmd_list[i] if attr.info then print(attr.info) end + local handle + handle = luv.spawn(attr.cmd, attr.opts, vim.schedule_wrap(function(code) handle:close() - if code ~= 0 then return api.nvim_err_writeln(attr.err) end + if code ~= 0 then return api.nvim_err_writeln(attr.err) end iter_cmd(cmd_list, i + 1, ft) end)) end -- cgit v1.2.3