feat: Support indexing dictionaries in var components

This commit is contained in:
shadmansaleh 2021-08-28 00:32:44 +06:00
parent 2348eaea2f
commit 276ba5d19e
1 changed files with 8 additions and 1 deletions

View File

@ -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)