nvim-treesitter / nvim-treesitter/nvim-treesitter-textobjects
@property for lua won't work
Nobody has claimed this yet.
- Dominant language
- Tree-sitter Query
- Stars
- 2.8k
- Forks
- 271
- Avg merge
- 8d 8h
- Merged PRs (30d)
- 1
Description
I'm trying to add a query to target key-value pairs in Lua, such as:
local test = {
foo = "bar"
}
So, in ~/.config/nvim/after/queries/lua/textobjects.scm I have this:
;;extends
(field
name: (identifier) @property.lhs
value: (_) @property.inner) @property.outer
In my textobjects config I have it assigned like so:
textobjects = {
select = {
enable = true,
lookahead = true,
keymaps = {
-- ...
["av"] = { query = "@property.outer", desc = "Outer property" },
["iv"] = { query = "@property.inner", desc = "Value" },
["lv"] = { query = "@property.lhs", desc = "Key" },
-- ...
},
},
-- ...
})
I've checked the query with :EditQuery, I've tried :TSEditQueryUserAfter which points to the correct file. In theory, if I go civ at foo, I should be able to change "bar" to whatever. I've checked with :InspectTree, but nothing happens. :checkhealth nvim-treesitter looks all good. I've also tried changing the ;;extends line to pretty much every variation of 1 or 2 ;, with or without spaces, nothing seems to help. What am I missing?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the Lua query from ~/.config/nvim/after/queries/lua/textobjects.scm with the shown textobjects.select mappings, then inspect the parse tree and query captures using :InspectTree and :EditQuery. Confirm whether the @property.outer, @property.inner, and @property.lhs captures are available for the sample table and identify what prevents the keymaps from selecting them.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100