nvim-treesitter / nvim-treesitter/nvim-treesitter-textobjects
Function to map query name into user friendly name
Nobody has claimed this yet.
- Dominant language
- Tree-sitter Query
- Stars
- 2.8k
- Forks
- 271
- Avg merge
- 8d 8h
- Merged PRs (30d)
- 1
Description
Is your feature request related to a problem? Please describe.
I'm switching to the main branch and all is good, but when defining mappings as documented https://github.com/nvim-treesitter/nvim-treesitter-textobjects/tree/main?tab=readme-ov-file#text-objects-select it would be great if we could get "user friendly" descriptions for each text object.
Describe the solution you'd like
A function we can import that converts @function.outer, etc into something a bit more "friendly", eg: "outer function" at it's simplest. But ideally each text object would have a "description" defined that could be retrieved and used for keymaps/etc.
Describe alternatives you've considered
Right now I'm just converting @foo.bar into bar foo using gsub:
local keymaps = {
-- You can use the capture groups defined in textobjects.scm
['af'] = '@function.outer',
['if'] = '@function.inner',
['ac'] = '@class.outer',
['ic'] = '@class.inner',
}
for keys, query in pairs(keymaps) do
-- Convert "@foo.bar" into "bar foo"
local desc = query:sub(2):gsub('(%a+).(%a+)', '%2 %1')
vim.keymap.set({ "x", "o" }, keys, function()
select.select_textobject(query, "textobjects")
end, { desc = desc })
end
Additional context
Add any other context or screenshots about the feature request here.
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
Start with the text-objects select documentation linked in the issue and the select.select_textobject entry point shown in its mapping example. Determine where text-object names or definitions can expose descriptions, then provide an importable function that maps queries such as @function.outer to friendly text. Done means callers can use the returned descriptions for keymap labels.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100