mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	docs: fix type warnings
This commit is contained in:
		 Maria José Solano
					Maria José Solano
				
			
				
					committed by
					
						 Lewis Russell
						Lewis Russell
					
				
			
			
				
	
			
			
			 Lewis Russell
						Lewis Russell
					
				
			
						parent
						
							01be28b370
						
					
				
				
					commit
					bc0bf9d030
				
			| @@ -2752,7 +2752,7 @@ vim.keymap.del({modes}, {lhs}, {opts})                      *vim.keymap.del()* | |||||||
|  |  | ||||||
|     Parameters: ~ |     Parameters: ~ | ||||||
|       • {opts}  (table|nil) A table of optional arguments: |       • {opts}  (table|nil) A table of optional arguments: | ||||||
|                 • "buffer": (number|boolean) Remove a mapping from the given |                 • "buffer": (integer|boolean) Remove a mapping from the given | ||||||
|                   buffer. When `0` or `true`, use the current buffer. |                   buffer. When `0` or `true`, use the current buffer. | ||||||
|  |  | ||||||
|     See also: ~ |     See also: ~ | ||||||
| @@ -2786,7 +2786,7 @@ vim.keymap.set({mode}, {lhs}, {rhs}, {opts})                *vim.keymap.set()* | |||||||
|                   • "noremap": inverse of "remap" (see below). |                   • "noremap": inverse of "remap" (see below). | ||||||
|  |  | ||||||
|                 • Also accepts: |                 • Also accepts: | ||||||
|                   • "buffer": (number|boolean) Creates buffer-local mapping, |                   • "buffer": (integer|boolean) Creates buffer-local mapping, | ||||||
|                     `0` or `true` for current buffer. |                     `0` or `true` for current buffer. | ||||||
|                   • "remap": (boolean) Make the mapping recursive. Inverse of |                   • "remap": (boolean) Make the mapping recursive. Inverse of | ||||||
|                     "noremap". Defaults to `false`. |                     "noremap". Defaults to `false`. | ||||||
|   | |||||||
| @@ -28,7 +28,7 @@ local keymap = {} | |||||||
| ---                        - "replace_keycodes" defaults to `true` if "expr" is `true`. | ---                        - "replace_keycodes" defaults to `true` if "expr" is `true`. | ||||||
| ---                        - "noremap": inverse of "remap" (see below). | ---                        - "noremap": inverse of "remap" (see below). | ||||||
| ---                      - Also accepts: | ---                      - Also accepts: | ||||||
| ---                        - "buffer": (number|boolean) Creates buffer-local mapping, `0` or `true` | ---                        - "buffer": (integer|boolean) Creates buffer-local mapping, `0` or `true` | ||||||
| ---                        for current buffer. | ---                        for current buffer. | ||||||
| ---                        - "remap": (boolean) Make the mapping recursive. Inverse of "noremap". | ---                        - "remap": (boolean) Make the mapping recursive. Inverse of "noremap". | ||||||
| ---                        Defaults to `false`. | ---                        Defaults to `false`. | ||||||
| @@ -44,7 +44,9 @@ function keymap.set(mode, lhs, rhs, opts) | |||||||
|     opts = { opts, 't', true }, |     opts = { opts, 't', true }, | ||||||
|   }) |   }) | ||||||
|  |  | ||||||
|   opts = vim.deepcopy(opts) or {} |   opts = vim.deepcopy(opts or {}) | ||||||
|  |  | ||||||
|  |   ---@cast mode string[] | ||||||
|   mode = type(mode) == 'string' and { mode } or mode |   mode = type(mode) == 'string' and { mode } or mode | ||||||
|  |  | ||||||
|   if opts.expr and opts.replace_keycodes ~= false then |   if opts.expr and opts.replace_keycodes ~= false then | ||||||
| @@ -57,7 +59,7 @@ function keymap.set(mode, lhs, rhs, opts) | |||||||
|   else |   else | ||||||
|     -- remaps behavior is opposite of noremap option. |     -- remaps behavior is opposite of noremap option. | ||||||
|     opts.noremap = not opts.remap |     opts.noremap = not opts.remap | ||||||
|     opts.remap = nil |     opts.remap = nil ---@type boolean? | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   if type(rhs) == 'function' then |   if type(rhs) == 'function' then | ||||||
| @@ -66,8 +68,8 @@ function keymap.set(mode, lhs, rhs, opts) | |||||||
|   end |   end | ||||||
|  |  | ||||||
|   if opts.buffer then |   if opts.buffer then | ||||||
|     local bufnr = opts.buffer == true and 0 or opts.buffer |     local bufnr = opts.buffer == true and 0 or opts.buffer --[[@as integer]] | ||||||
|     opts.buffer = nil |     opts.buffer = nil ---@type integer? | ||||||
|     for _, m in ipairs(mode) do |     for _, m in ipairs(mode) do | ||||||
|       vim.api.nvim_buf_set_keymap(bufnr, m, lhs, rhs, opts) |       vim.api.nvim_buf_set_keymap(bufnr, m, lhs, rhs, opts) | ||||||
|     end |     end | ||||||
| @@ -89,7 +91,7 @@ end | |||||||
| --- ``` | --- ``` | ||||||
| --- | --- | ||||||
| ---@param opts table|nil A table of optional arguments: | ---@param opts table|nil A table of optional arguments: | ||||||
| ---                      - "buffer": (number|boolean) Remove a mapping from the given buffer. | ---                      - "buffer": (integer|boolean) Remove a mapping from the given buffer. | ||||||
| ---                        When `0` or `true`, use the current buffer. | ---                        When `0` or `true`, use the current buffer. | ||||||
| ---@see |vim.keymap.set()| | ---@see |vim.keymap.set()| | ||||||
| --- | --- | ||||||
| @@ -103,9 +105,9 @@ function keymap.del(modes, lhs, opts) | |||||||
|   opts = opts or {} |   opts = opts or {} | ||||||
|   modes = type(modes) == 'string' and { modes } or modes |   modes = type(modes) == 'string' and { modes } or modes | ||||||
|  |  | ||||||
|   local buffer = false |   local buffer = false ---@type false|integer | ||||||
|   if opts.buffer ~= nil then |   if opts.buffer ~= nil then | ||||||
|     buffer = opts.buffer == true and 0 or opts.buffer |     buffer = opts.buffer == true and 0 or opts.buffer --[[@as integer]] | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   if buffer == false then |   if buffer == false then | ||||||
|   | |||||||
| @@ -2,9 +2,9 @@ local M = {} | |||||||
|  |  | ||||||
| --- Reads trust database from $XDG_STATE_HOME/nvim/trust. | --- Reads trust database from $XDG_STATE_HOME/nvim/trust. | ||||||
| --- | --- | ||||||
| ---@return (table) Contents of trust database, if it exists. Empty table otherwise. | ---@return table<string, string> Contents of trust database, if it exists. Empty table otherwise. | ||||||
| local function read_trust() | local function read_trust() | ||||||
|   local trust = {} |   local trust = {} ---@type table<string, string> | ||||||
|   local f = io.open(vim.fn.stdpath('state') .. '/trust', 'r') |   local f = io.open(vim.fn.stdpath('state') .. '/trust', 'r') | ||||||
|   if f then |   if f then | ||||||
|     local contents = f:read('*a') |     local contents = f:read('*a') | ||||||
| @@ -24,12 +24,12 @@ end | |||||||
| --- Writes provided {trust} table to trust database at | --- Writes provided {trust} table to trust database at | ||||||
| --- $XDG_STATE_HOME/nvim/trust. | --- $XDG_STATE_HOME/nvim/trust. | ||||||
| --- | --- | ||||||
| ---@param trust (table) Trust table to write | ---@param trust table<string, string> Trust table to write | ||||||
| local function write_trust(trust) | local function write_trust(trust) | ||||||
|   vim.validate({ trust = { trust, 't' } }) |   vim.validate({ trust = { trust, 't' } }) | ||||||
|   local f = assert(io.open(vim.fn.stdpath('state') .. '/trust', 'w')) |   local f = assert(io.open(vim.fn.stdpath('state') .. '/trust', 'w')) | ||||||
|  |  | ||||||
|   local t = {} |   local t = {} ---@type string[] | ||||||
|   for p, h in pairs(trust) do |   for p, h in pairs(trust) do | ||||||
|     t[#t + 1] = string.format('%s %s\n', h, p) |     t[#t + 1] = string.format('%s %s\n', h, p) | ||||||
|   end |   end | ||||||
| @@ -61,7 +61,7 @@ function M.read(path) | |||||||
|     return nil |     return nil | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   local contents |   local contents ---@type string? | ||||||
|   do |   do | ||||||
|     local f = io.open(fullpath, 'r') |     local f = io.open(fullpath, 'r') | ||||||
|     if not f then |     if not f then | ||||||
| @@ -108,6 +108,11 @@ function M.read(path) | |||||||
|   return contents |   return contents | ||||||
| end | end | ||||||
|  |  | ||||||
|  | ---@class vim.trust.opts | ||||||
|  | ---@field action string | ||||||
|  | ---@field path? string | ||||||
|  | ---@field bufnr? integer | ||||||
|  |  | ||||||
| --- Manage the trust database. | --- Manage the trust database. | ||||||
| --- | --- | ||||||
| --- The trust database is located at |$XDG_STATE_HOME|/nvim/trust. | --- The trust database is located at |$XDG_STATE_HOME|/nvim/trust. | ||||||
| @@ -134,6 +139,7 @@ function M.trust(opts) | |||||||
|     }, |     }, | ||||||
|   }) |   }) | ||||||
|  |  | ||||||
|  |   ---@cast opts vim.trust.opts | ||||||
|   local path = opts.path |   local path = opts.path | ||||||
|   local bufnr = opts.bufnr |   local bufnr = opts.bufnr | ||||||
|   local action = opts.action |   local action = opts.action | ||||||
| @@ -144,7 +150,7 @@ function M.trust(opts) | |||||||
|     assert(not path, '"path" is not valid when action is "allow"') |     assert(not path, '"path" is not valid when action is "allow"') | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   local fullpath |   local fullpath ---@type string? | ||||||
|   if path then |   if path then | ||||||
|     fullpath = vim.uv.fs_realpath(vim.fs.normalize(path)) |     fullpath = vim.uv.fs_realpath(vim.fs.normalize(path)) | ||||||
|   elseif bufnr then |   elseif bufnr then | ||||||
| @@ -165,7 +171,8 @@ function M.trust(opts) | |||||||
|  |  | ||||||
|   if action == 'allow' then |   if action == 'allow' then | ||||||
|     local newline = vim.bo[bufnr].fileformat == 'unix' and '\n' or '\r\n' |     local newline = vim.bo[bufnr].fileformat == 'unix' and '\n' or '\r\n' | ||||||
|     local contents = table.concat(vim.api.nvim_buf_get_lines(bufnr, 0, -1, false), newline) |     local contents = | ||||||
|  |       table.concat(vim.api.nvim_buf_get_lines(bufnr --[[@as integer]], 0, -1, false), newline) | ||||||
|     if vim.bo[bufnr].endofline then |     if vim.bo[bufnr].endofline then | ||||||
|       contents = contents .. newline |       contents = contents .. newline | ||||||
|     end |     end | ||||||
|   | |||||||
| @@ -127,6 +127,7 @@ function M.get_parser(bufnr, lang, opts) | |||||||
|       ) |       ) | ||||||
|     end |     end | ||||||
|   elseif parsers[bufnr] == nil or parsers[bufnr]:lang() ~= lang then |   elseif parsers[bufnr] == nil or parsers[bufnr]:lang() ~= lang then | ||||||
|  |     assert(lang, 'lang should be valid') | ||||||
|     parsers[bufnr] = M._create_parser(bufnr, lang, opts) |     parsers[bufnr] = M._create_parser(bufnr, lang, opts) | ||||||
|   end |   end | ||||||
|  |  | ||||||
| @@ -162,7 +163,7 @@ function M.is_ancestor(dest, source) | |||||||
|     return false |     return false | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   local current = source |   local current = source ---@type TSNode? | ||||||
|   while current ~= nil do |   while current ~= nil do | ||||||
|     if current == dest then |     if current == dest then | ||||||
|       return true |       return true | ||||||
| @@ -491,7 +492,7 @@ end | |||||||
| ---                        function, it accepts the buffer number of the source buffer as its only | ---                        function, it accepts the buffer number of the source buffer as its only | ||||||
| ---                        argument and should return a string. | ---                        argument and should return a string. | ||||||
| function M.inspect_tree(opts) | function M.inspect_tree(opts) | ||||||
|   ---@cast opts InspectTreeOpts |   ---@diagnostic disable-next-line: invisible | ||||||
|   require('vim.treesitter.dev').inspect_tree(opts) |   require('vim.treesitter.dev').inspect_tree(opts) | ||||||
| end | end | ||||||
|  |  | ||||||
|   | |||||||
| @@ -258,7 +258,7 @@ end | |||||||
|  |  | ||||||
| --- @private | --- @private | ||||||
| --- | --- | ||||||
| --- @param opts InspectTreeOpts | --- @param opts InspectTreeOpts? | ||||||
| function M.inspect_tree(opts) | function M.inspect_tree(opts) | ||||||
|   vim.validate({ |   vim.validate({ | ||||||
|     opts = { opts, 't', true }, |     opts = { opts, 't', true }, | ||||||
|   | |||||||
| @@ -60,7 +60,7 @@ end | |||||||
| ---@param path string Path to file | ---@param path string Path to file | ||||||
| ---@return string URI | ---@return string URI | ||||||
| function M.uri_from_fname(path) | function M.uri_from_fname(path) | ||||||
|   local volume_path, fname = path:match('^([a-zA-Z]:)(.*)') |   local volume_path, fname = path:match('^([a-zA-Z]:)(.*)') ---@type string? | ||||||
|   local is_windows = volume_path ~= nil |   local is_windows = volume_path ~= nil | ||||||
|   if is_windows then |   if is_windows then | ||||||
|     path = volume_path .. M.uri_encode(fname:gsub('\\', '/')) |     path = volume_path .. M.uri_encode(fname:gsub('\\', '/')) | ||||||
| @@ -82,7 +82,7 @@ function M.uri_from_bufnr(bufnr) | |||||||
|   local fname = vim.api.nvim_buf_get_name(bufnr) |   local fname = vim.api.nvim_buf_get_name(bufnr) | ||||||
|   local volume_path = fname:match('^([a-zA-Z]:).*') |   local volume_path = fname:match('^([a-zA-Z]:).*') | ||||||
|   local is_windows = volume_path ~= nil |   local is_windows = volume_path ~= nil | ||||||
|   local scheme |   local scheme ---@type string? | ||||||
|   if is_windows then |   if is_windows then | ||||||
|     fname = fname:gsub('\\', '/') |     fname = fname:gsub('\\', '/') | ||||||
|     scheme = fname:match(WINDOWS_URI_SCHEME_PATTERN) |     scheme = fname:match(WINDOWS_URI_SCHEME_PATTERN) | ||||||
| @@ -107,10 +107,9 @@ function M.uri_to_fname(uri) | |||||||
|   uri = M.uri_decode(uri) |   uri = M.uri_decode(uri) | ||||||
|   --TODO improve this. |   --TODO improve this. | ||||||
|   if is_windows_file_uri(uri) then |   if is_windows_file_uri(uri) then | ||||||
|     uri = uri:gsub('^file:/+', '') |     uri = uri:gsub('^file:/+', ''):gsub('/', '\\') | ||||||
|     uri = uri:gsub('/', '\\') |  | ||||||
|   else |   else | ||||||
|     uri = uri:gsub('^file:/+', '/') |     uri = uri:gsub('^file:/+', '/') ---@type string | ||||||
|   end |   end | ||||||
|   return uri |   return uri | ||||||
| end | end | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user