feat: Support indexing dictionaries in var components
This commit is contained in:
parent
2348eaea2f
commit
276ba5d19e
|
@ -9,7 +9,14 @@ VarComponent.update_status = function(self)
|
|||
local var_name = component:sub(#scope + 2, #component)
|
||||
-- Displays nothing when veriable aren't present
|
||||
if not (scope and var_name) then return '' end
|
||||
local return_val = vim[scope][var_name]
|
||||
-- Support accessing keys within dictionary
|
||||
-- https://github.com/shadmansaleh/lualine.nvim/issues/25#issuecomment-907374548
|
||||
local name_chunks = vim.split(var_name, '%.')
|
||||
local return_val = vim[scope][name_chunks[1]]
|
||||
for i=2,#name_chunks do
|
||||
if return_val == nil then break end
|
||||
return_val = return_val[name_chunks[i]]
|
||||
end
|
||||
if return_val == nil then return '' end
|
||||
local ok
|
||||
ok, return_val = pcall(tostring, return_val)
|
||||
|
|
Loading…
Reference in New Issue