From 3f3e4837d5f7d2d9cb1c89bd3a5b2ee8a730772a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 16 Oct 2024 17:03:48 +0100 Subject: perf(validate): use lighter version - Also fix `vim.validate()` for PUC Lua when showing errors for values that aren't string or number. --- runtime/lua/vim/ui.lua | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'runtime/lua/vim/ui.lua') diff --git a/runtime/lua/vim/ui.lua b/runtime/lua/vim/ui.lua index 532decf5e9..c0f03ceadc 100644 --- a/runtime/lua/vim/ui.lua +++ b/runtime/lua/vim/ui.lua @@ -37,10 +37,8 @@ local M = {} --- `idx` is the 1-based index of `item` within `items`. --- `nil` if the user aborted the dialog. function M.select(items, opts, on_choice) - vim.validate({ - items = { items, 'table', false }, - on_choice = { on_choice, 'function', false }, - }) + vim.validate('items', items, 'table', false) + vim.validate('on_choice', on_choice, 'function', false) opts = opts or {} local choices = { opts.prompt or 'Select one of:' } local format_item = opts.format_item or tostring @@ -86,10 +84,8 @@ end --- an empty string if nothing was entered), or --- `nil` if the user aborted the dialog. function M.input(opts, on_confirm) - vim.validate({ - opts = { opts, 'table', true }, - on_confirm = { on_confirm, 'function', false }, - }) + vim.validate('opts', opts, 'table', true) + vim.validate('on_confirm', on_confirm, 'function', false) opts = (opts and not vim.tbl_isempty(opts)) and opts or vim.empty_dict() @@ -135,9 +131,7 @@ end --- ---@see |vim.system()| function M.open(path, opt) - vim.validate({ - path = { path, 'string' }, - }) + vim.validate('path', path, 'string') local is_uri = path:match('%w+:') if not is_uri then path = vim.fs.normalize(path) -- cgit From f4b620c4e6430ea8cbc5632d6853b24da09d7dfc Mon Sep 17 00:00:00 2001 From: Uthman Mohamed <83053931+uthmanmoh@users.noreply.github.com> Date: Fri, 18 Oct 2024 05:22:15 -0400 Subject: feat(vim.ui.open): support lemonade #30845 --- runtime/lua/vim/ui.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'runtime/lua/vim/ui.lua') diff --git a/runtime/lua/vim/ui.lua b/runtime/lua/vim/ui.lua index c0f03ceadc..f66b34ac44 100644 --- a/runtime/lua/vim/ui.lua +++ b/runtime/lua/vim/ui.lua @@ -159,8 +159,10 @@ function M.open(path, opt) cmd = { 'wslview', path } elseif vim.fn.executable('explorer.exe') == 1 then cmd = { 'explorer.exe', path } + elseif vim.fn.executable('lemonade') == 1 then + cmd = { 'lemonade', 'open', path } else - return nil, 'vim.ui.open: no handler found (tried: wslview, explorer.exe, xdg-open)' + return nil, 'vim.ui.open: no handler found (tried: wslview, explorer.exe, xdg-open, lemonade)' end return vim.system(cmd, job_opt), nil -- cgit From 3572319b4cb1a4163624a5fe328886f1928dbc4a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 18 Oct 2024 11:33:12 +0100 Subject: feat(vim.validate): improve fast form and deprecate spec form Problem: `vim.validate()` takes two forms when it only needs one. Solution: - Teach the fast form all the features of the spec form. - Deprecate the spec form. - General optimizations for both forms. - Add a `message` argument which can be used alongside or in place of the `optional` argument. --- runtime/lua/vim/ui.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'runtime/lua/vim/ui.lua') diff --git a/runtime/lua/vim/ui.lua b/runtime/lua/vim/ui.lua index f66b34ac44..b2e972d07a 100644 --- a/runtime/lua/vim/ui.lua +++ b/runtime/lua/vim/ui.lua @@ -37,8 +37,8 @@ local M = {} --- `idx` is the 1-based index of `item` within `items`. --- `nil` if the user aborted the dialog. function M.select(items, opts, on_choice) - vim.validate('items', items, 'table', false) - vim.validate('on_choice', on_choice, 'function', false) + vim.validate('items', items, 'table') + vim.validate('on_choice', on_choice, 'function') opts = opts or {} local choices = { opts.prompt or 'Select one of:' } local format_item = opts.format_item or tostring @@ -85,7 +85,7 @@ end --- `nil` if the user aborted the dialog. function M.input(opts, on_confirm) vim.validate('opts', opts, 'table', true) - vim.validate('on_confirm', on_confirm, 'function', false) + vim.validate('on_confirm', on_confirm, 'function') opts = (opts and not vim.tbl_isempty(opts)) and opts or vim.empty_dict() -- cgit From 629a5b71b55e439392e2a5791940f6dc8d0dd7c0 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 22 Oct 2024 12:16:24 +0100 Subject: fix(lsp): support multiple clients in typehierarchy --- runtime/lua/vim/ui.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'runtime/lua/vim/ui.lua') diff --git a/runtime/lua/vim/ui.lua b/runtime/lua/vim/ui.lua index b2e972d07a..899709d3cf 100644 --- a/runtime/lua/vim/ui.lua +++ b/runtime/lua/vim/ui.lua @@ -20,7 +20,8 @@ local M = {} --- end) --- ``` --- ----@param items any[] Arbitrary items +---@generic T +---@param items T[] Arbitrary items ---@param opts table Additional options --- - prompt (string|nil) --- Text of the prompt. Defaults to `Select one of:` @@ -32,7 +33,7 @@ local M = {} --- Plugins reimplementing `vim.ui.select` may wish to --- use this to infer the structure or semantics of --- `items`, or the context in which select() was called. ----@param on_choice fun(item: any|nil, idx: integer|nil) +---@param on_choice fun(item: T|nil, idx: integer|nil) --- Called once the user made a choice. --- `idx` is the 1-based index of `item` within `items`. --- `nil` if the user aborted the dialog. -- cgit From 1d4ba8c1edba064421b34c1197c3470a09798218 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 31 Oct 2024 11:28:02 +0000 Subject: fix: another round of type annotation fixes --- runtime/lua/vim/ui.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'runtime/lua/vim/ui.lua') diff --git a/runtime/lua/vim/ui.lua b/runtime/lua/vim/ui.lua index 899709d3cf..cd159f0172 100644 --- a/runtime/lua/vim/ui.lua +++ b/runtime/lua/vim/ui.lua @@ -43,7 +43,9 @@ function M.select(items, opts, on_choice) opts = opts or {} local choices = { opts.prompt or 'Select one of:' } local format_item = opts.format_item or tostring - for i, item in ipairs(items) do + for i, item in + ipairs(items --[[@as any[] ]]) + do table.insert(choices, string.format('%d: %s', i, format_item(item))) end local choice = vim.fn.inputlist(choices) @@ -204,7 +206,9 @@ function M._get_urls() if vim.treesitter.node_contains(node, range) then local url = metadata[id] and metadata[id].url if url and match[url] then - for _, n in ipairs(match[url]) do + for _, n in + ipairs(match[url] --[[@as TSNode[] ]]) + do urls[#urls + 1] = vim.treesitter.get_node_text(n, bufnr, { metadata = metadata[url] }) end -- cgit