From 67b2ed1004ae551c9fe1bbd29a86b5a301570800 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 2 Jul 2023 16:51:30 +0200 Subject: fix(gx): visual selection, expand env vars --- Rejected experiment: move vim.ui.open() to vim.env.open() Problem: `vim.ui` is where user-interface "providers" live, which can be overridden. It would also be useful to have a "providers" namespace for platform-specific features such as "open", clipboard, python, and the other providers listed in `:help providers`. We could overload `vim.ui` to serve that purpose as the single "providers" namespace, but `vim.ui.nodejs()` for example seems awkward. Solution: `vim.env` currently has too narrow of a purpose. Overload it to also be a namespace for `vim.env.open`. diff --git a/runtime/lua/vim/_meta.lua b/runtime/lua/vim/_meta.lua index 913f1fe20348..17d05ff37595 100644 --- a/runtime/lua/vim/_meta.lua +++ b/runtime/lua/vim/_meta.lua @@ -37,8 +37,28 @@ local options_info = setmetatable({}, { end, }) -vim.env = setmetatable({}, { - __index = function(_, k) +vim.env = setmetatable({ + open = setmetatable({}, { + __call = function(_, uri) + print('xxxxx'..uri) + return true + end, + __tostring = function() + local v = vim.fn.getenv('open') + if v == vim.NIL then + return nil + end + return v + end, + }) + }, + { + __index = function(t, k, ...) + if k == 'open' then + error() + -- vim.print({...}) + -- return rawget(t, k) + end local v = vim.fn.getenv(k) if v == vim.NIL then return nil --- test/functional/lua/ui_spec.lua | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'test/functional/lua/ui_spec.lua') diff --git a/test/functional/lua/ui_spec.lua b/test/functional/lua/ui_spec.lua index 9ee99b4905..0f66aad7b3 100644 --- a/test/functional/lua/ui_spec.lua +++ b/test/functional/lua/ui_spec.lua @@ -1,5 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local eq = helpers.eq +local matches = helpers.matches local exec_lua = helpers.exec_lua local clear = helpers.clear local feed = helpers.feed @@ -11,8 +12,7 @@ describe('vim.ui', function() clear() end) - - describe('select', function() + describe('select()', function() it('can select an item', function() local result = exec_lua[[ local items = { @@ -47,7 +47,7 @@ describe('vim.ui', function() end) end) - describe('input', function() + describe('input()', function() it('can input text', function() local result = exec_lua[[ local opts = { @@ -130,4 +130,18 @@ describe('vim.ui', function() end) end) + + describe('open()', function() + it('validation', function() + exec_lua[[vim.ui.open('non-existent-file')]] + matches('vim.ui.open: command failed %(%d%): { "[^"]+", "non%-existent%-file" }', eval('v:errmsg')) + + exec_lua[[ + vim.fn.has = function() return 0 end + vim.fn.executable = function() return 0 end + ]] + exec_lua[[vim.ui.open('foo')]] + eq('vim.ui.open: no handler found (tried: wslview, xdg-open)', eval('v:errmsg')) + end) + end) end) -- cgit From e644e7ce0b36dd5e75770f3faa0a84f15e2561e8 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 4 Jul 2023 23:33:23 +0200 Subject: fix(vim.ui.open): return (don't show) error message Problem: Showing an error via vim.notify() makes it awkward for callers such as lsp/handlers.lua to avoid showing redundant errors. Solution: Return the message instead of showing it. Let the caller decide whether and when to show the message. --- test/functional/lua/ui_spec.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'test/functional/lua/ui_spec.lua') diff --git a/test/functional/lua/ui_spec.lua b/test/functional/lua/ui_spec.lua index 0f66aad7b3..d1b64419af 100644 --- a/test/functional/lua/ui_spec.lua +++ b/test/functional/lua/ui_spec.lua @@ -5,6 +5,7 @@ local exec_lua = helpers.exec_lua local clear = helpers.clear local feed = helpers.feed local eval = helpers.eval +local is_os = helpers.is_os local poke_eventloop = helpers.poke_eventloop describe('vim.ui', function() @@ -133,15 +134,17 @@ describe('vim.ui', function() describe('open()', function() it('validation', function() - exec_lua[[vim.ui.open('non-existent-file')]] - matches('vim.ui.open: command failed %(%d%): { "[^"]+", "non%-existent%-file" }', eval('v:errmsg')) + if not is_os('bsd') then + matches('vim.ui.open: command failed %(%d%): { "[^"]+", "non%-existent%-file" }', + exec_lua[[local _, err = vim.ui.open('non-existent-file') ; return err]]) + end exec_lua[[ vim.fn.has = function() return 0 end vim.fn.executable = function() return 0 end ]] - exec_lua[[vim.ui.open('foo')]] - eq('vim.ui.open: no handler found (tried: wslview, xdg-open)', eval('v:errmsg')) + eq('vim.ui.open: no handler found (tried: wslview, xdg-open)', + exec_lua[[local _, err = vim.ui.open('foo') ; return err]]) end) end) end) -- cgit From 2afb04758c341e17c70b8d2e3869c901c8cdb7d2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 6 Jul 2023 12:56:19 +0800 Subject: fix(vim.system): close check handle (#24270) Fix hang after running vim.system() with sanitizers. --- test/functional/lua/ui_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/lua/ui_spec.lua') diff --git a/test/functional/lua/ui_spec.lua b/test/functional/lua/ui_spec.lua index d1b64419af..808b25d9ea 100644 --- a/test/functional/lua/ui_spec.lua +++ b/test/functional/lua/ui_spec.lua @@ -5,7 +5,7 @@ local exec_lua = helpers.exec_lua local clear = helpers.clear local feed = helpers.feed local eval = helpers.eval -local is_os = helpers.is_os +local is_ci = helpers.is_ci local poke_eventloop = helpers.poke_eventloop describe('vim.ui', function() @@ -134,7 +134,7 @@ describe('vim.ui', function() describe('open()', function() it('validation', function() - if not is_os('bsd') then + if is_ci('github') then matches('vim.ui.open: command failed %(%d%): { "[^"]+", "non%-existent%-file" }', exec_lua[[local _, err = vim.ui.open('non-existent-file') ; return err]]) end -- cgit From 7907b1fca5fce69e966ab1071df8e6d11afda41d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 21 Jul 2023 13:34:38 +0200 Subject: test(vim.ui.open): mock failure on Windows Problem: On Windows, `rundll32` exits zero (success) even when given a non-existent file. Solution: Mock vim.system() on Windows to force a "failure" case. --- test/functional/lua/ui_spec.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'test/functional/lua/ui_spec.lua') diff --git a/test/functional/lua/ui_spec.lua b/test/functional/lua/ui_spec.lua index 808b25d9ea..d4c150c5f2 100644 --- a/test/functional/lua/ui_spec.lua +++ b/test/functional/lua/ui_spec.lua @@ -6,6 +6,7 @@ local clear = helpers.clear local feed = helpers.feed local eval = helpers.eval local is_ci = helpers.is_ci +local is_os = helpers.is_os local poke_eventloop = helpers.poke_eventloop describe('vim.ui', function() @@ -134,8 +135,11 @@ describe('vim.ui', function() describe('open()', function() it('validation', function() - if is_ci('github') then - matches('vim.ui.open: command failed %(%d%): { "[^"]+", "non%-existent%-file" }', + if is_os('win') or not is_ci('github') then + exec_lua[[vim.system = function() return { wait=function() return { code=3} end } end]] + end + if not is_os('bsd') then + matches('vim.ui.open: command failed %(%d%): { "[^"]+", .*"non%-existent%-file" }', exec_lua[[local _, err = vim.ui.open('non-existent-file') ; return err]]) end -- cgit