diff options
| author | badhi <bmadhikarinayake@gmail.com> | 2022-02-13 13:26:43 +0530 |
|---|---|---|
| committer | Stephan Seitz <stephan.seitz@fau.de> | 2022-02-13 10:39:55 +0100 |
| commit | 738a0136dd2f0fb0e9d83d1743eb0e63451b396c (patch) | |
| tree | 4ed3473c38612c66c47779d9262f07fbaff71ae8 /lua | |
| parent | Fixed formatting (diff) | |
| download | nvim-treesitter-738a0136dd2f0fb0e9d83d1743eb0e63451b396c.tar nvim-treesitter-738a0136dd2f0fb0e9d83d1743eb0e63451b396c.tar.gz nvim-treesitter-738a0136dd2f0fb0e9d83d1743eb0e63451b396c.tar.bz2 nvim-treesitter-738a0136dd2f0fb0e9d83d1743eb0e63451b396c.tar.lz nvim-treesitter-738a0136dd2f0fb0e9d83d1743eb0e63451b396c.tar.xz nvim-treesitter-738a0136dd2f0fb0e9d83d1743eb0e63451b396c.tar.zst nvim-treesitter-738a0136dd2f0fb0e9d83d1743eb0e63451b396c.zip | |
added doc for setup_command
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-treesitter/utils.lua | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lua/nvim-treesitter/utils.lua b/lua/nvim-treesitter/utils.lua index deacaf332..91ac9b59f 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 <f-args>) +--- - 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 +--- <pre> +--- M.commands = { +--- custom_command = { +--- run = M.module_function, +--- f_args = "<f-args>", +--- args = { +--- "-range" +--- } +--- } +--- } +--- +--- utils.setup_commands("custom_mod", require("nvim-treesitter.custom_mod").commands) +--- </pre> +--- +--- Will generate command : +--- <pre> +--- command! -range custom_command \ +--- lua require'nvim-treesitter.custom_mod'.commands.custom_command['run<bang>'](<f-args>) +--- </pre> function M.setup_commands(mod, commands) for command_name, def in pairs(commands) do local f_args = def.f_args or "<f-args>" |
