aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter/playground.lua
diff options
context:
space:
mode:
authorGregory Anders <8965202+gpanders@users.noreply.github.com>2022-12-08 09:51:46 -0700
committerGitHub <noreply@github.com>2022-12-08 09:51:46 -0700
commit42009ac7df88bfffeea49a83e642fdc6cf9f9447 (patch)
tree8be7e05b19764ce65d78431e93b6247f013bb48f /runtime/lua/vim/treesitter/playground.lua
parentd44699800cd0dbf14fb45476c13b6cc3c993b5c7 (diff)
downloadrneovim-42009ac7df88bfffeea49a83e642fdc6cf9f9447.tar.gz
rneovim-42009ac7df88bfffeea49a83e642fdc6cf9f9447.tar.bz2
rneovim-42009ac7df88bfffeea49a83e642fdc6cf9f9447.zip
feat(treesitter): add 'lang' option to show_tree() (#21341)
This is necessary for now to support filetypes that use a parser with a different name (e.g. the "terraform" filetype uses the "hcl" parser).
Diffstat (limited to 'runtime/lua/vim/treesitter/playground.lua')
-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