Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distinguish between methods and functions #139

Open
briandipalma opened this issue Dec 3, 2021 · 2 comments
Open

Distinguish between methods and functions #139

briandipalma opened this issue Dec 3, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@briandipalma
Copy link
Contributor

Is your feature request related to a problem? Please describe.
I want a way to distinguish between methods and functions in JavaScript and other languages.

Describe the solution you'd like
I'd like:

			goto_next_start = {
				["]k"] = "@class.outer",
				["]m"] = "(method_definition) @function",
				["]f"] = "@function.outer",
				["]b"] = "@block.outer",
			}

to work (I realize I'm not specifying javascript for ]m but I was just testing it out before cleaning it up.

Describe alternatives you've considered
None

Additional context
I'd like to do something like this eventually:

			goto_next_start = {
				["]k"] = "@class.outer",
				["]m"] = {
                                   javascript: "(method_definition) @function",
                                   java = "(method_declaration) @function",
                                   "@function.outer"
                                }
				["]f"] = "@function.outer",
				["]b"] = "@block.outer",
			}

So that I can correctly move from method to method in the languages I most often work with and fall back to the more generic solution when an override isn't defined.

@briandipalma briandipalma added the enhancement New feature or request label Dec 3, 2021
@0xflick
Copy link

0xflick commented Jan 19, 2022

I managed to make something like this work. I first defined the following function:

function default(d, t)
  local mt = {__index = function() return d end}
  setmetatable(t, mt)
end

And you can use it like this

keymaps = {
  ["af"] = default("@function.outer", {go = nil}),
  ["if"] = default("@function.inner", {go = nil}),
  ["ac"] = default("@class.outer", {go = nil}),
  ["ic"] = default("@class.inner", {go = nil}),
}

I use it to prevent these bindings from messing with the ones from vim-go, but to do what you describe you could do something like:

goto_next_start = {
  ["]m"] = default(
    "@function.outer", {
      javascript = "(method_definition) @function",
      java = "(method_declaration) @function"})

@0xflick
Copy link

0xflick commented Jan 19, 2022

Actually #155 breaks this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants