aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua/vim/treesitter')
-rw-r--r--runtime/lua/vim/treesitter/playground.lua10
1 files changed, 6 insertions, 4 deletions
diff --git a/runtime/lua/vim/treesitter/playground.lua b/runtime/lua/vim/treesitter/playground.lua
index 325d303df5..bb073290c6 100644
--- a/runtime/lua/vim/treesitter/playground.lua
+++ b/runtime/lua/vim/treesitter/playground.lua
@@ -3,6 +3,7 @@ local api = vim.api
local M = {}
---@class Playground
+---@field ns number API namespace
---@field opts table Options table with the following keys:
--- - anon (boolean): If true, display anonymous nodes
--- - lang (boolean): If true, display the language alongside each node
@@ -79,13 +80,14 @@ end
--- Create a new Playground object.
---
---@param bufnr number Source buffer number
+---@param lang string|nil Language of source buffer
---
---@return Playground|nil
---@return string|nil Error message, if any
---
---@private
-function M.new(self, bufnr)
- local ok, parser = pcall(vim.treesitter.get_parser, bufnr or 0)
+function M.new(self, bufnr, lang)
+ local ok, parser = pcall(vim.treesitter.get_parser, bufnr or 0, lang)
if not ok then
return nil, 'No parser available for the given buffer'
end
@@ -95,13 +97,13 @@ function M.new(self, bufnr)
-- the root in the child tree to the {injections} table.
local root = parser:parse()[1]:root()
local injections = {}
- parser:for_each_child(function(child, lang)
+ parser:for_each_child(function(child, lang_)
child:for_each_tree(function(tree)
local r = tree:root()
local node = root:named_descendant_for_range(r:range())
if node then
injections[node:id()] = {
- lang = lang,
+ lang = lang_,
root = r,
}
end