diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2022-08-30 23:23:09 -0600 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2022-08-30 23:23:09 -0600 |
commit | 968aa6e3ed0497ea99f123c74c5fd0f3880ccc63 (patch) | |
tree | 32ac91852b82d040012d40a3f54f772723509968 /runtime/lua/vim/treesitter/query.lua | |
parent | 242f75745009b3a0a2108d98ce6c02b6e13aac3f (diff) | |
parent | f4274d0f62625683486d3912dcd6e8e45877c6a4 (diff) | |
download | rneovim-968aa6e3ed0497ea99f123c74c5fd0f3880ccc63.tar.gz rneovim-968aa6e3ed0497ea99f123c74c5fd0f3880ccc63.tar.bz2 rneovim-968aa6e3ed0497ea99f123c74c5fd0f3880ccc63.zip |
Merge remote-tracking branch 'upstream/master' into userreg
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 |