From 2bcc1f866c39395551459af7a3b10dec5c75525c Mon Sep 17 00:00:00 2001 From: FaultyBranches Date: Thu, 28 May 2026 16:30:51 -0500 Subject: [PATCH] feat: Setting up the TreeSitterInstall custom command to install luarocks hosted treesitter plugins inside neovim --- nvim/lua/custom_commands.lua | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/nvim/lua/custom_commands.lua b/nvim/lua/custom_commands.lua index 94d1118..c1ead32 100644 --- a/nvim/lua/custom_commands.lua +++ b/nvim/lua/custom_commands.lua @@ -4,13 +4,20 @@ vim.api.nvim_create_user_command('FindAndReplace', function(opts) vim.api.nvim_command(string.format('cfdo s/%s/%s/gc', opts.fargs[1], opts.fargs[2]) .. '| update | cclose') end, { nargs = '*' }) --- TODO: Set up a command for installing treesitter plugins via luarocks -vim.api.nvim_create_user_command('TSI', function(opts) - local result = vim.system({ 'luarocks', 'install', 'tree-sitter-' .. opts.fargs[1] }, { text = true }):wait() - if result.code == 0 then - print('Completed install of tree-sitter-' .. opts.fargs[1]) - else - print('Failed to install tree-sitter-' .. opts.fargs[1]) - print(result.stdout) +-- Installs tree-sitter plugins for languages from the luarocks repo +-- Takes a space separated list of arguments of language names, tacks them onto the tree-sitter- package names and runs the install +-- NOTE: luarocks does not take a list of package ("rock") names and requires this setup to install one at a time +vim.api.nvim_create_user_command('TreeSitterInstall', function(opts) + for index, value in ipairs(opts.fargs) do + if index > 0 then + local result = vim.system({ 'luarocks', 'install', 'tree-sitter-' .. value }, { text = true }):wait() + + if result.code == 0 then + print('Completed install of tree-sitter-' .. value) + else + print('Failed to install tree-sitter-' .. value) + print(result.stdout) + end + end end end, { nargs = '*' })