Hi there,
How do I write a tree-sitter query for lua
that returns string field nodes from a table like the following one?
module.packages = {
"aaa.nvim",
"bbb.nvim",
["not_this"] = { "ccc.nvim" }
}
I am reading the docs etc. but something is just not clicking in my understanding.
My goal is to be able to capture all of these strings (aaa.nvim,bbb.nvim,…) and put them all in a table and use telescope to pick from them so that I can use the picker to toggle configs/settings in a large table.
I should also mention that I know how to capture the whole table by copy pasting from the locals
query from nvim-treesitter
repo but I don’t really understand how it works so I am not sure how to modify it to only spit out the table string fields. Currently I am capturing the whole table chunk and then use get children and siblings functions in order to end up with the table fields.
##edit
This is my query so far but it is not working:
(assignment_statement
(variable_list
(dot_index_expression . (_) @def.assoc (identifier) @def.var)))
(#eq? @def.var "packages")
(expression_list
(field . (field value: (string) @repostring)))
)
#edit
I have almost solved the query now for myself so I will post it when I am done.