nvim-treesitter / nvim-treesitter/nvim-treesitter-textobjects

@property for lua won't work

Open
#875 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.