From 738a0136dd2f0fb0e9d83d1743eb0e63451b396c Mon Sep 17 00:00:00 2001 From: badhi Date: Sun, 13 Feb 2022 13:26:43 +0530 Subject: added doc for setup_command --- lua/nvim-treesitter/utils.lua | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'lua/nvim-treesitter/utils.lua') diff --git a/lua/nvim-treesitter/utils.lua b/lua/nvim-treesitter/utils.lua index deacaf33..91ac9b59 100644 --- a/lua/nvim-treesitter/utils.lua +++ b/lua/nvim-treesitter/utils.lua @@ -10,6 +10,41 @@ function M.notify(msg, log_level, opts) vim.notify(msg, log_level, vim.tbl_extend("force", default_opts, opts or {})) end +--- Define user defined vim command which calls nvim-treesitter module function +--- - If module name is 'mod', it should be defined in hierarchy 'nvim-treesitter.mod' +--- - A table with name 'commands' should be defined in 'mod' which needs to be passed as +--- the commands param of this function +--- +---@param mod string, Name of the module that resides in the heirarchy - nvim-treesitter.module +---@param commands table, Command list for the module +--- _ {command_name} Name of the vim user defined command, Keys: +--- - {run}: (function) callback function that needs to be executed +--- - {f_args}: (string, default ) +--- - type of arguments that needs to be passed to the vim command +--- - {args}: (string, optional) +--- - vim command attributes +--- +---Example: +--- If module is nvim-treesitter.custom_mod +---
+---  M.commands = {
+---      custom_command = {
+---          run = M.module_function,
+---          f_args = "",
+---          args = {
+---              "-range"
+---          }
+---      }
+---  }
+---
+---  utils.setup_commands("custom_mod", require("nvim-treesitter.custom_mod").commands)
+---  
+--- +--- Will generate command : +---
+---  command! -range custom_command \
+---      lua require'nvim-treesitter.custom_mod'.commands.custom_command['run']()
+---  
function M.setup_commands(mod, commands) for command_name, def in pairs(commands) do local f_args = def.f_args or "" -- cgit v1.2.3