mirror of
https://github.com/neovim/neovim.git
synced 2025-12-15 19:05:40 +00:00
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
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user