nvim-treesitter / nvim-treesitter-textobjects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Custom Capture Help] `@function.name`, capture the function name from the current scope instead of lookahead/behind

ofirgall opened this issue · comments

Hey, I'm trying to write a custom capture which captures the function name of the function I'm currently at instead of trying to lookahead.

This is the custom capture (golang):

;; Function name
(function_declaration
  name: (_)? @function.name)

(method_declaration
  name: (_)? @function.name)

Afaik, it cannot be done with the current version of this plugin. It will simply look ahead if the query is not found. This might be improved in the future to search from a given context (like you can search @function.name under the range of @function.outer.

Until then, I suggest you make a mapping like [mvan which will go to the beginning of the function and then select the name.

Closing as completed in #386