neodev.nvim icon indicating copy to clipboard operation
neodev.nvim copied to clipboard

bug: vim.fn.getreg third parameter type is incorrect

Open aarondill opened this issue 2 years ago • 2 comments

Did you check docs and existing issues?

  • [X] I have read all the neodev.nvim docs
  • [X] I have searched the existing issues of neodev.nvim
  • [X] I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

NVIM v0.10.0-dev

Operating system/version

Ubuntu 22.04.2 LTS

Describe the bug

The types for the vim.fn.getreg function are incorrect, current types are function vim.fn.getreg(regname?: any, p1?: any, list?: any[]) -> string, the correct types would be the following (these can likely be simplified):

--- @param regname? string
--- @param p1? 1
--- @param list? boolean
--- @return string
--- @overload fun(regname: string, p1?:1, list?:false): string
--- @overload fun(regname: string, p1:1, list:true): string[]

Steps To Reproduce

  1. Install an lsp (and optionally a diagnostic) so type errors can be seen
  2. Install neodev with any plugin manager (or manually)
  3. nvim ~/.config/nvim/init.lua
  4. type vim.fn.getreg("+", 1, true)
  5. observe diagnostic issue, even though usage is correct

Expected Behavior

Types match usage types

Repro

~/.config/nvim/init.lua
-- Set keymap for diagnostics
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
	"folke/tokyonight.nvim",
	-- mason to install lua-language-server
	{
		"williamboman/mason.nvim",
		build = ":MasonUpdate",
		config = true,
	},
	-- mason-lspconfig to load lua-language-server
	{
		"williamboman/mason-lspconfig.nvim",
		dependencies = "williamboman/mason.nvim",
		opts = { ensure_installed = { "lua_ls" } },
	},
	-- nvim-lspconfig to setup lsp
	{
		"neovim/nvim-lspconfig",
		dependencies = {
			{ "folke/neodev.nvim" }, -- Load neodev
			"mason.nvim",
			"williamboman/mason-lspconfig.nvim",
		},
		config = function()
			require("lspconfig").lua_ls.setup({
				settings = {
					Lua = {
						runtime = {
							-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
							version = "LuaJIT",
						},
						workspace = {
							-- Make the server aware of Neovim runtime files
							library = vim.api.nvim_get_runtime_file("", true),
							checkThirdParty = false, -- save some time on startup
						},
						-- Do not send telemetry data containing a randomized but unique identifier
						telemetry = {
							enable = false,
						},
					},
				},
			})
		end,
	},
	{ -- is it working?
		"mrded/nvim-lsp-notify",
		main = "lsp-notify",
		config = true,
	},
}
require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")

aarondill avatar Apr 16 '23 06:04 aarondill

In a similar way the types for vim.fn.setreg are also incorrect. Current types are function vim.fn.setreg(regname: any, value: any, options?: table<string, any>) -> number but should rather be:

--- @param regname string
--- @param value string[]|string
--- @param options table|string <-- from how I understand it only an empty table is allowed here
--- @return number

TheBlob42 avatar Oct 03 '23 15:10 TheBlob42

Anything that you believe is not correct in https://github.com/neovim/neovim/blob/master/runtime/lua/vim/_meta/vimfn.lua as well can be reported to https://github.com/neovim/neovim/issues. Due to the (suboptimal) way neodev's annotations are generated, there could be some mismatches. See #175

wookayin avatar Jan 22 '24 18:01 wookayin