diff options
author | bfredl <bjorn.linse@gmail.com> | 2022-08-25 21:35:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-25 21:35:13 +0200 |
commit | bfd1adc62c615e7b65bdfe6d3c21158708eb4314 (patch) | |
tree | ec839f0bb6d5c28780f9e694aa2bf764871382b3 /runtime/lua/vim/treesitter/query.lua | |
parent | 22f920030214c0023525c59daf763441baddba1a (diff) | |
parent | 73ee2b35d1fc738be9bd4b99f49ce8f84351fbe6 (diff) | |
download | rneovim-bfd1adc62c615e7b65bdfe6d3c21158708eb4314.tar.gz rneovim-bfd1adc62c615e7b65bdfe6d3c21158708eb4314.tar.bz2 rneovim-bfd1adc62c615e7b65bdfe6d3c21158708eb4314.zip |
Merge pull request #19946 from bfredl/newnode
feat: upstream some nvim-treesitter functions
Diffstat (limited to 'runtime/lua/vim/treesitter/query.lua')
-rw-r--r-- | runtime/lua/vim/treesitter/query.lua | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/runtime/lua/vim/treesitter/query.lua b/runtime/lua/vim/treesitter/query.lua index 103e85abfd..697e2e7691 100644 --- a/runtime/lua/vim/treesitter/query.lua +++ b/runtime/lua/vim/treesitter/query.lua @@ -181,9 +181,14 @@ end --- Gets the text corresponding to a given node --- ----@param node the node ----@param source The buffer or string from which the node is extracted -function M.get_node_text(node, source) +---@param node table The node +---@param source table The buffer or string from which the node is extracted +---@param opts table Optional parameters. +--- - concat: (boolean default true) Concatenate result in a string +function M.get_node_text(node, source, opts) + opts = opts or {} + local concat = vim.F.if_nil(opts.concat, true) + local start_row, start_col, start_byte = node:start() local end_row, end_col, end_byte = node:end_() @@ -210,7 +215,7 @@ function M.get_node_text(node, source) end end - return table.concat(lines, '\n') + return concat and table.concat(lines, '\n') or lines elseif type(source) == 'string' then return source:sub(start_byte + 1, end_byte) end |