Closed ofseed closed 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"
.
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.
lazydev.nvim looks for ---@module annotations
:
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 tovim.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.
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:
And since
setup
is a de facto standard, why be different?