kylechui / nvim-surround

Add/change/delete surrounding delimiter pairs with ease. Written with :heart: in Lua.
MIT License
2.9k stars 60 forks source link

feat(treesitter): add `conditional`, `loop` and `function` objects as… #304

Closed phgz closed 4 months ago

phgz commented 5 months ago

… surrounds for lua and python ft

Links to https://github.com/kylechui/nvim-surround/issues/238.

This is a pretty much standalone module, extensible by users own filetypes definitions. All the current tests are passing. Some could be added for this module. Also, there is still the documentation that should be updated.

It is basically an opt-in extension, backward compatible. Users specify, in the surrounds mapping, which key they want to assign for each object.

Before going further, I would like a review to see if there are things to adjust.

Thank you!

Note/Edit:

Here is a demo:

https://asciinema.org/a/ODi9aWaE2b2DB0yGpVdgBIgMe

kylechui commented 4 months ago

Hi there, one major reason that I've been hesitant to add this is because I don't believe there's a good way to ensure configuration ordering when calling either setup or buffer_setup. In particular, which should take precedence between default.filetype_config and user.global_config? It's not abundantly clear. Furthermore, all of the functionality in this PR more or less seems like it can already be accomplished via buffer_setup calls put into after/plugin/filetype.lua. Recently, I've found myself trending more and more towards reducing the amount of stuff that my plugin does by default, and simply providing an easy-to-use API for the user to configure the plugin themselves.

phgz commented 4 months ago

In the config file, I added a filetypes_extensions key where the user could provide the module/table to be merged with the defaults (basically a vim.tbl_deep_extend("force", defaults, <user table defining their own filetype config>)). But sure, if there is an upcoming more flexible API, I'd be glad to use it :)

kylechui commented 4 months ago

I see; I think the tricky part of trying to use filetypes_extensions is that it would somewhat conflict with the existing buffer_setup function, as I'm not sure how we could guarantee that the configuration functions would be run in the correct order. I'm actually thinking of removing layers of abstractions by replacing the setup function call with just a vim.g.nvim_surround (or vim.b.nvim_surround, and having users just set that variable wherever they see fit. That way the overriding is completely transparent, instead of forcing people to learn the quirks of whatever interface I create.

kylechui commented 4 months ago

Sorry, I'll probably just close this PR for now while I figure how else I wish to restructure the plugin.