From 784a726f2e10ccbc11451a50033cb43426dfaab8 Mon Sep 17 00:00:00 2001 From: Vlad <52591095+MeanderingProgrammer@users.noreply.github.com> Date: Mon, 3 Jun 2024 21:58:19 -0700 Subject: [PATCH] style: Set vim.opt.rtp type to vim.Option (#1498) ## Details There is an issue in the `neodev` repo that mentions this: [#193](https://github.com/folke/neodev.nvim/issues/193) I think the problem comes from a combination of 2 things: 1. As mentioned in the [Reddit post](https://www.reddit.com/r/neovim/comments/1cvrilk/diagnosticwarning_after_upgrade_to_neovim_010/): `Nvim never had Lua type annotations for vim.opt`. 2. Setting `vim.opt.rtp` anywhere in the config will cause Lua-LS to infer the type for `vim.opt.rtp`. While users are unlikely to do this it does happen in `lazy.nvim`, in places shown in this PR. --- lua/lazy/core/config.lua | 1 + lua/lazy/core/loader.lua | 1 + tests/core/util_spec.lua | 1 + 3 files changed, 3 insertions(+) diff --git a/lua/lazy/core/config.lua b/lua/lazy/core/config.lua index 9c7bed3..17ce2bd 100644 --- a/lua/lazy/core/config.lua +++ b/lua/lazy/core/config.lua @@ -237,6 +237,7 @@ function M.setup(opts) M.me = debug.getinfo(1, "S").source:sub(2) M.me = Util.norm(vim.fn.fnamemodify(M.me, ":p:h:h:h:h")) if M.options.performance.rtp.reset then + ---@type vim.Option vim.opt.rtp = { vim.fn.stdpath("config"), vim.fn.stdpath("data") .. "/site", diff --git a/lua/lazy/core/loader.lua b/lua/lazy/core/loader.lua index 9cd5018..e07328c 100644 --- a/lua/lazy/core/loader.lua +++ b/lua/lazy/core/loader.lua @@ -476,6 +476,7 @@ function M.add_to_rtp(plugin) table.insert(rtp, idx_after or (#rtp + 1), after) end + ---@type vim.Option vim.opt.rtp = rtp end diff --git a/tests/core/util_spec.lua b/tests/core/util_spec.lua index a497881..643304d 100644 --- a/tests/core/util_spec.lua +++ b/tests/core/util_spec.lua @@ -5,6 +5,7 @@ local Util = require("lazy.util") describe("util", function() local rtp = vim.opt.rtp:get() before_each(function() + ---@type vim.Option vim.opt.rtp = rtp for k, v in pairs(package.loaded) do if k:find("^foobar") then