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

I'm looking for a way to hang more actions off the same node type with a direct keymap. #63

Open
unphased opened this issue Apr 29, 2024 · 2 comments

Comments

@unphased
Copy link

unphased commented Apr 29, 2024

We can attach more than one action to a given node type, but this forces us to make a choice each time. For example I am going to author a new node action on a property_identifier for a few of the languages I use often which will grab the var name and make a simple debug print out of it in the next line of code.

But I don't want to have to delete the existing actions.cycle_case() mapped to property_identifier, and neither do i want to insert another action to make to trigger this.

I'd prefer to be able to establish different sets of node actions that are mapped to different key binds! So I could have, say, a mapping that will apply "traditional" actions like cycle case and toggle multiline/operator/quote etc, a separate mapping that applies "expanding" refactoring automations as an example, another mapping that applies "contracting" refactoring automations... etc. You get the idea.

@unphased
Copy link
Author

I discovered require("ts-node-action").available_actions() from the doc, so I think i will be able to make binds that call this and do something appropriate based on what this emits.

@unphased
Copy link
Author

unphased commented May 1, 2024

I had to hack this function like so:

local function do_action(action, node)
  local act = type(action) == "table" and action[1][1] or action
  local replacement, opts = act(node)
  if replacement then
    replace_node(node, replacement, opts or {})
  end
end

to get

vim.keymap.set('n', '<leader>E', function ()
    local actions = require('ts-node-action').available_actions()
    -- run the last one
    log('actions and last', actions, actions[#actions].action())
  end, {
  desc = "Node Action -- last"
})

to work.

@unphased unphased reopened this May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant