mrcjkb / rustaceanvim

🦀 Supercharge your Rust experience in Neovim! A heavily modified fork of rust-tools.nvim
GNU General Public License v2.0
1.62k stars 58 forks source link

Add the `setup` function for rustceanvim #416

Closed ofseed closed 4 months ago

ofseed commented 4 months ago

Feature description

I know you do not like the setup function, and you even wrote a guideline to recommend that people reduce the use of this function, but here's my reason:

Yesterday folke wrote lazydev.nvim that could load plugin types dynamically, this means annotations for plugins are visible to the users who use this plugin (if you load every plugin to your lua_ls workspace directly, lua_ls will be very laggy and has a prolonged startup time, so there is only a very few people leverage this ability formerly), this means if you configure plugins by the setup function, you could get completion times and the corresponding documentation, it's convenient and I think it would be popular in the future.

Here's an example:

image

And since setup is a de facto standard, why be different?

mrcjkb commented 4 months ago

Hey 👋

I explicitly don't add a setup function in my plugins, because it's often cargo culted in a bad way, and I don't want to encourage that.

According to the lazydev.nvim readme, you can use ---@module annotations, so for rustaceanvim that would probably be ---@module "rustaceanvim.config" or ---@module "rustaceanvim".

ofseed commented 4 months ago

The @module annotation is provided by lua_ls, and it is treated as a require call internally. @module "rustaceanvim.confg" won't work in this case because the exported module rustaceanvim.config is not corresponding to vim.g.rustaceanvim, it's a module containing API functions.

I'd say I know how to make it work, assign a dummy variable like this:

---@module "rustaceanvim"
local _

Then https://github.com/mrcjkb/rustaceanvim/blob/2fa45427c01ded4d3ecca72e357f8a60fd8e46d4/lua/rustaceanvim/config/init.lua#L49-L49 will take effect.

But this is a hack anyway. For users with zero configuration, they will not take benefit from annotations of this plugin.

mrcjkb commented 4 months ago

lazydev.nvim looks for ---@module annotations:

https://github.com/folke/lazydev.nvim/blob/3f565826f618604d85f5d0397691b4a630fe04c3/lua/lazydev/pkg.lua#L108

See also the plugin's readme, which I linked in my previous response:

will update your workspace libraries for:

  • require statements: require("nvim-treesitter")
  • module annotations: ---@module "nvim-treesitter"

because the exported module rustaceanvim.config is not corresponding to vim.g.rustaceanvim, it's a module containing API functions.

The type annotations in that module correspond with vim.g.rustaceanvim.

But this is a hack anyway. For users with zero configuration, they will not take benefit from annotations of this plugin.

Then this is a lazydev.nvim issue! I'm not going to introduce an antipattern into my plugin because another plugin makes assumptions about it being used. lazydev.nvim could solve this by adding support for vim.g or vim.b variables.