From 2db719f6c2b677fcbc197b02fe52764a851523b2 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Sat, 3 Jun 2023 11:06:00 +0100 Subject: feat(lua): rename vim.loop -> vim.uv (#22846) --- runtime/lua/vim/secure.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'runtime/lua/vim/secure.lua') diff --git a/runtime/lua/vim/secure.lua b/runtime/lua/vim/secure.lua index 443b152273..1a04e11231 100644 --- a/runtime/lua/vim/secure.lua +++ b/runtime/lua/vim/secure.lua @@ -51,7 +51,7 @@ end --- trusted, or nil otherwise. function M.read(path) vim.validate({ path = { path, 's' } }) - local fullpath = vim.loop.fs_realpath(vim.fs.normalize(path)) + local fullpath = vim.uv.fs_realpath(vim.fs.normalize(path)) if not fullpath then return nil end @@ -149,13 +149,13 @@ function M.trust(opts) local fullpath if path then - fullpath = vim.loop.fs_realpath(vim.fs.normalize(path)) + fullpath = vim.uv.fs_realpath(vim.fs.normalize(path)) elseif bufnr then local bufname = vim.api.nvim_buf_get_name(bufnr) if bufname == '' then return false, 'buffer is not associated with a file' end - fullpath = vim.loop.fs_realpath(vim.fs.normalize(bufname)) + fullpath = vim.uv.fs_realpath(vim.fs.normalize(bufname)) else error('one of "path" or "bufnr" is required') end -- cgit From be74807eef13ff8c90d55cf8b22b01d6d33b1641 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 18 Jul 2023 15:42:30 +0100 Subject: docs(lua): more improvements (#24387) * docs(lua): teach lua2dox how to table * docs(lua): teach gen_vimdoc.py about local functions No more need to mark local functions with @private * docs(lua): mention @nodoc and @meta in dev-lua-doc * fixup! Co-authored-by: Justin M. Keyes --------- Co-authored-by: Justin M. Keyes --- runtime/lua/vim/secure.lua | 2 -- 1 file changed, 2 deletions(-) (limited to 'runtime/lua/vim/secure.lua') diff --git a/runtime/lua/vim/secure.lua b/runtime/lua/vim/secure.lua index 1a04e11231..837738c041 100644 --- a/runtime/lua/vim/secure.lua +++ b/runtime/lua/vim/secure.lua @@ -1,6 +1,5 @@ local M = {} ----@private --- Reads trust database from $XDG_STATE_HOME/nvim/trust. --- ---@return (table) Contents of trust database, if it exists. Empty table otherwise. @@ -22,7 +21,6 @@ local function read_trust() return trust end ----@private --- Writes provided {trust} table to trust database at --- $XDG_STATE_HOME/nvim/trust. --- -- cgit From c43c745a14dced87a23227d7be4f1c33d4455193 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Wed, 9 Aug 2023 11:06:13 +0200 Subject: fix(lua): improve annotations for stricter luals diagnostics (#24609) Problem: luals returns stricter diagnostics with bundled luarc.json Solution: Improve some function and type annotations: * use recognized uv.* types * disable diagnostic for global `vim` in shared.lua * docs: don't start comment lines with taglink (otherwise LuaLS will interpret it as a type) * add type alias for lpeg pattern * fix return annotation for `vim.secure.trust` * rename local Range object in vim.version (shadows `Range` in vim.treesitter) * fix some "missing fields" warnings * add missing required fields for test functions in eval.lua * rename lsp meta files for consistency --- runtime/lua/vim/secure.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'runtime/lua/vim/secure.lua') diff --git a/runtime/lua/vim/secure.lua b/runtime/lua/vim/secure.lua index 837738c041..893b3e1877 100644 --- a/runtime/lua/vim/secure.lua +++ b/runtime/lua/vim/secure.lua @@ -119,9 +119,8 @@ end --- - path (string|nil): Path to a file to update. Mutually exclusive with {bufnr}. --- Cannot be used when {action} is "allow". --- - bufnr (number|nil): Buffer number to update. Mutually exclusive with {path}. ----@return (boolean, string) success, msg: ---- - true and full path of target file if operation was successful ---- - false and error message on failure +---@return boolean success true if operation was successful +---@return string msg full path if operation was successful, else error message function M.trust(opts) vim.validate({ path = { opts.path, 's', true }, -- cgit From bc0bf9d030bbcb01db69c44cf88b95ca41dd3065 Mon Sep 17 00:00:00 2001 From: Maria José Solano Date: Wed, 20 Sep 2023 19:03:40 -0700 Subject: docs: fix type warnings --- runtime/lua/vim/secure.lua | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'runtime/lua/vim/secure.lua') diff --git a/runtime/lua/vim/secure.lua b/runtime/lua/vim/secure.lua index 893b3e1877..d29c356af3 100644 --- a/runtime/lua/vim/secure.lua +++ b/runtime/lua/vim/secure.lua @@ -2,9 +2,9 @@ local M = {} --- Reads trust database from $XDG_STATE_HOME/nvim/trust. --- ----@return (table) Contents of trust database, if it exists. Empty table otherwise. +---@return table Contents of trust database, if it exists. Empty table otherwise. local function read_trust() - local trust = {} + local trust = {} ---@type table local f = io.open(vim.fn.stdpath('state') .. '/trust', 'r') if f then local contents = f:read('*a') @@ -24,12 +24,12 @@ end --- Writes provided {trust} table to trust database at --- $XDG_STATE_HOME/nvim/trust. --- ----@param trust (table) Trust table to write +---@param trust table Trust table to write local function write_trust(trust) vim.validate({ trust = { trust, 't' } }) local f = assert(io.open(vim.fn.stdpath('state') .. '/trust', 'w')) - local t = {} + local t = {} ---@type string[] for p, h in pairs(trust) do t[#t + 1] = string.format('%s %s\n', h, p) end @@ -61,7 +61,7 @@ function M.read(path) return nil end - local contents + local contents ---@type string? do local f = io.open(fullpath, 'r') if not f then @@ -108,6 +108,11 @@ function M.read(path) return contents end +---@class vim.trust.opts +---@field action string +---@field path? string +---@field bufnr? integer + --- Manage the trust database. --- --- 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 bufnr = opts.bufnr local action = opts.action @@ -144,7 +150,7 @@ function M.trust(opts) assert(not path, '"path" is not valid when action is "allow"') end - local fullpath + local fullpath ---@type string? if path then fullpath = vim.uv.fs_realpath(vim.fs.normalize(path)) elseif bufnr then @@ -165,7 +171,8 @@ function M.trust(opts) if action == 'allow' then 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 contents = contents .. newline end -- cgit