From 6b00c9acfde954a3e992a2932eca9fa5902a1298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ph=E1=BA=A1m=20B=C3=ACnh=20An?= <111893501+brianhuster@users.noreply.github.com> Date: Wed, 26 Mar 2025 06:35:12 +0700 Subject: [PATCH] fix(lua): no omni/cmdline completion for vim.env (#33044) Problem: - `:lua vim.env.` does not show completion of environment variables - Meanwhile, `:let $` does show completion of environment variables Solution: - Fix it --- runtime/lua/vim/_editor.lua | 3 ++- test/functional/lua/command_line_completion_spec.lua | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua index f0b8587476..e795c66969 100644 --- a/runtime/lua/vim/_editor.lua +++ b/runtime/lua/vim/_editor.lua @@ -1031,7 +1031,7 @@ function vim._expand_pat(pat, env) end -- Completion for dict accessors (special vim variables and vim.fn) - if mt and vim.tbl_contains({ vim.g, vim.t, vim.w, vim.b, vim.v, vim.fn }, final_env) then + if mt and vim.tbl_contains({ vim.g, vim.t, vim.w, vim.b, vim.v, vim.env, vim.fn }, final_env) then local prefix, type = unpack( vim.fn == final_env and { '', 'function' } or vim.g == final_env and { 'g:', 'var' } @@ -1039,6 +1039,7 @@ function vim._expand_pat(pat, env) or vim.w == final_env and { 'w:', 'var' } or vim.b == final_env and { 'b:', 'var' } or vim.v == final_env and { 'v:', 'var' } + or vim.env == final_env and { '', 'environment' } or { nil, nil } ) assert(prefix and type, "Can't resolve final_env") diff --git a/test/functional/lua/command_line_completion_spec.lua b/test/functional/lua/command_line_completion_spec.lua index ee3d0325e1..7883480125 100644 --- a/test/functional/lua/command_line_completion_spec.lua +++ b/test/functional/lua/command_line_completion_spec.lua @@ -269,6 +269,18 @@ describe('nlua_expand_pat', function() } eq(expected, actual) end) + + it('vim.env', function() + exec_lua [[ + vim.env.NLUA_ENV_VAR = 'foo' + ]] + local actual = get_completions('vim.env.NLUA') + local expected = { + { 'NLUA_ENV_VAR' }, + #'vim.env.', + } + eq(expected, actual) + end) end) describe('completes', function()