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

proof of concept: exclude ts captures #118

Closed
wants to merge 1 commit into from
Closed

proof of concept: exclude ts captures #118

wants to merge 1 commit into from

Conversation

gennaro-tedesco
Copy link

A primitive proof of concept addressing #95: do you think such concept is in scope?

Logic:

  • before inserting the node range in the captures table, check if said node must be excluded

Changes:

  • modified lua/flash/plugins/treesitter.lua (containing the main logic)
  • added utils functions and configuration options

@gennaro-tedesco
Copy link
Author

gennaro-tedesco commented Jul 3, 2023

The above should work as follows:

Screen.Recording.2023-07-03.at.16.29.44.mov

@IndianBoy42
Copy link
Contributor

I think the more flexible method is to take a callback that can return a new list with whatever modifications it wants (or mutate the existing list as long as it returns it as well). vim.tbl_filter and vim.list_contains could be used to do this in one/two lines.

This way would also help #52

@gennaro-tedesco
Copy link
Author

Yes, it may be a good idea to do so: ultimately let's hear from folke what he thinks, most likely he knows best where/how in the codebase to perform such changes.

@JoseConseco
Copy link

Option for callback that could filter / mutate flash results would be great. It would allow to remove first result from treesitter.jump() - which is always the same as word under cursor (and thus redundant)

@folke
Copy link
Owner

folke commented Jul 4, 2023

I went ahead and implemented @IndianBoy42 's suggestion.

You can now do:

require("flash").treesitter({
  filter = function(matches)
    ---@param m Flash.Match.TS
    return vim.tbl_filter(function(m)
      return not (m.node and vim.tbl_contains({ "comment" }, m.node:type()))
    end, matches)
  end,
})

You can of course also define that filter function in your config opts.modes.treesitter.filter

@gennaro-tedesco I assume this covers your need?

@gennaro-tedesco
Copy link
Author

Yes, it works very well!

@folke
Copy link
Owner

folke commented Jul 4, 2023

Great!

@folke folke closed this Jul 4, 2023
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

Successfully merging this pull request may close these issues.

4 participants