|BEAKING_CHNAGE| Fix :lualine disapearing on reload + Allow live updates

Breaking Change: Now subsequent call to lualine.setup modifies old setup
instead of configuring from scratch
This commit is contained in:
shadmansaleh 2021-08-02 12:40:11 +06:00
parent f1dbb2f4a8
commit 6d153dac1f
3 changed files with 53 additions and 50 deletions

View File

@ -45,9 +45,9 @@ local function apply_configuration(config_table)
if not config_table[section_group_name] then return end if not config_table[section_group_name] then return end
for section_name, section in pairs(config_table[section_group_name]) do for section_name, section in pairs(config_table[section_group_name]) do
config[section_group_name][section_name] = config[section_group_name][section_name] =
config_table[section_group_name][section_name] vim.deepcopy(config_table[section_group_name][section_name])
if type(section) == 'table' then if type(section) == 'table' then
for _, component in pairs(section) do for _, component in pairs(config[section_group_name][section_name]) do
if type(component) == 'table' and type(component[2]) == 'table' then if type(component) == 'table' and type(component[2]) == 'table' then
local options = component[2] local options = component[2]
component[2] = nil component[2] = nil
@ -66,6 +66,7 @@ local function apply_configuration(config_table)
config.options.section_separators) config.options.section_separators)
config.options.component_separators = fix_separators( config.options.component_separators = fix_separators(
config.options.component_separators) config.options.component_separators)
return vim.deepcopy(config)
end end
return {config = config, apply_configuration = apply_configuration} return {config = vim.deepcopy(config), apply_configuration = apply_configuration}

View File

@ -218,13 +218,15 @@ end
local function setup(user_config) local function setup(user_config)
if user_config then if user_config then
config_module.apply_configuration(user_config) config = config_module.apply_configuration(user_config)
elseif vim.g.lualine then elseif vim.g.lualine then
vim.schedule(function() vim.schedule(function()
vim.api.nvim_err_writeln( vim.api.nvim_err_writeln(
[[Lualine: lualine will stop supporting vimscript soon, change your config to lua or wrap it around lua << EOF ... EOF]]) -- luacheck: ignore [[Lualine: lualine will stop supporting vimscript soon, change your config to lua or wrap it around lua << EOF ... EOF]]) -- luacheck: ignore
end) end)
config_module.apply_configuration(vim.g.lualine) config = config_module.apply_configuration(vim.g.lualine)
else
config = config_module.apply_configuration({})
end end
setup_theme() setup_theme()
loader.load_all(config) loader.load_all(config)

View File

@ -6,36 +6,36 @@ describe('config parsing', function()
describe('options', function() describe('options', function()
describe('icons_enabled', function() describe('icons_enabled', function()
it('default', function() it('default', function()
config_module.apply_configuration({}) local config = config_module.apply_configuration({})
eq(config_module.config.options.icons_enabled, true) eq(config.options.icons_enabled, true)
end) end)
it('custom', function() it('custom', function()
local config = {options = {icons_enabled = false}} local config = {options = {icons_enabled = false}}
config_module.apply_configuration(config) config = config_module.apply_configuration(config)
eq(config_module.config.options.icons_enabled, false) eq(config.options.icons_enabled, false)
end) end)
end) end)
describe('theme', function() describe('theme', function()
it('default', function() it('default', function()
config_module.apply_configuration({}) local config = config_module.apply_configuration({})
eq(config_module.config.options.theme, 'gruvbox') eq(config.options.theme, 'gruvbox')
end) end)
it('custom', function() it('custom', function()
local config = {options = {theme = 'nord'}} local config = {options = {theme = 'nord'}}
config_module.apply_configuration(config) config = config_module.apply_configuration(config)
eq(config_module.config.options.theme, 'nord') eq(config.options.theme, 'nord')
config = {options = {theme = {}}} config = {options = {theme = {}}}
config_module.apply_configuration(config) config = config_module.apply_configuration(config)
eq(config_module.config.options.theme, {}) eq(config.options.theme, {})
end) end)
end) end)
describe('separators', function() describe('separators', function()
it('default', function() it('default', function()
config_module.apply_configuration({}) local config = config_module.apply_configuration({})
eq(config_module.config.options.component_separators, {'', ''}) eq(config.options.component_separators, {'', ''})
eq(config_module.config.options.section_separators, {'', ''}) eq(config.options.section_separators, {'', ''})
end) end)
it('double separators', function() it('double separators', function()
local config = { local config = {
@ -44,9 +44,9 @@ describe('config parsing', function()
section_separators = {'c', 'd'} section_separators = {'c', 'd'}
} }
} }
config_module.apply_configuration(config) config = config_module.apply_configuration(config)
eq(config_module.config.options.component_separators, {'a', 'b'}) eq(config.options.component_separators, {'a', 'b'})
eq(config_module.config.options.section_separators, {'c', 'd'}) eq(config.options.section_separators, {'c', 'd'})
end) end)
describe('single separator', function() describe('single separator', function()
@ -54,51 +54,51 @@ describe('config parsing', function()
local config = { local config = {
options = {component_separators = 'a', section_separators = 'b'} options = {component_separators = 'a', section_separators = 'b'}
} }
config_module.apply_configuration(config) config = config_module.apply_configuration(config)
eq(config_module.config.options.component_separators, {'a', 'a'}) eq(config.options.component_separators, {'a', 'a'})
eq(config_module.config.options.section_separators, {'b', 'b'}) eq(config.options.section_separators, {'b', 'b'})
end) end)
it('table', function() it('table', function()
local config = { local config = {
options = {component_separators = {'a'}, section_separators = {'b'}} options = {component_separators = {'a'}, section_separators = {'b'}}
} }
config_module.apply_configuration(config) config = config_module.apply_configuration(config)
eq(config_module.config.options.component_separators, {'a', 'a'}) eq(config.options.component_separators, {'a', 'a'})
eq(config_module.config.options.section_separators, {'b', 'b'}) eq(config.options.section_separators, {'b', 'b'})
end) end)
end) end)
it('no seprarators', function() it('no seprarators', function()
local config = { local config = {
options = {component_separators = {}, section_separators = {}} options = {component_separators = {}, section_separators = {}}
} }
config_module.apply_configuration(config) config = config_module.apply_configuration(config)
eq(config_module.config.options.component_separators, {}) eq(config.options.component_separators, {})
eq(config_module.config.options.section_separators, {}) eq(config.options.section_separators, {})
end) end)
end) end)
describe('disabled filetypes', function() describe('disabled filetypes', function()
it('default', function() it('default', function()
config_module.apply_configuration({}) local config = config_module.apply_configuration({})
eq(config_module.config.options.disabled_filetypes, {}) eq(config.options.disabled_filetypes, {})
end) end)
it('custom', function() it('custom', function()
local config = {options = {disabled_filetypes = {'lua'}}} local config = {options = {disabled_filetypes = {'lua'}}}
config_module.apply_configuration(config) config = config_module.apply_configuration(config)
eq(config_module.config.options.disabled_filetypes, {'lua'}) eq(config.options.disabled_filetypes, {'lua'})
end) end)
end) end)
describe('non default global option', function() describe('non default global option', function()
it('default', function() it('default', function()
local config = {options = {}} local config = {options = {}}
config_module.apply_configuration(config) config = config_module.apply_configuration(config)
eq(config_module.config.options.non_default_global_option, nil) eq(config.options.non_default_global_option, nil)
end) end)
it('custom', function() it('custom', function()
local config = {options = {non_default_global_option = 1}} local config = {options = {non_default_global_option = 1}}
config_module.apply_configuration(config) config = config_module.apply_configuration(config)
eq(config_module.config.options.non_default_global_option, 1) eq(config.options.non_default_global_option, 1)
end) end)
end) end)
end) end)
@ -106,7 +106,7 @@ describe('config parsing', function()
describe('sections', function() describe('sections', function()
it('default', function() it('default', function()
local config = {} local config = {}
config_module.apply_configuration(config) config = config_module.apply_configuration(config)
local lualine_default_sections = { local lualine_default_sections = {
lualine_a = {'mode'}, lualine_a = {'mode'},
lualine_b = {'branch'}, lualine_b = {'branch'},
@ -115,7 +115,7 @@ describe('config parsing', function()
lualine_y = {'progress'}, lualine_y = {'progress'},
lualine_z = {'location'} lualine_z = {'location'}
} }
eq(config_module.config.sections, lualine_default_sections) eq(config.sections, lualine_default_sections)
end) end)
it('custom', function() it('custom', function()
local custom_sections = { local custom_sections = {
@ -133,8 +133,8 @@ describe('config parsing', function()
lualine_z = {'location'} lualine_z = {'location'}
} }
local config = {sections = custom_sections} local config = {sections = custom_sections}
config_module.apply_configuration(config) config = config_module.apply_configuration(config)
eq(config_module.config.sections, expected_sections) eq(config.sections, expected_sections)
end) end)
end) end)
@ -143,8 +143,8 @@ describe('config parsing', function()
describe('tabline', function() describe('tabline', function()
it('default', function() it('default', function()
local config = {} local config = {}
config_module.apply_configuration(config) config = config_module.apply_configuration(config)
eq(config_module.config.tabline, {}) eq(config.tabline, {})
end) end)
it('custom', function() it('custom', function()
local custom_sections = { local custom_sections = {
@ -159,21 +159,21 @@ describe('config parsing', function()
lualine_x = {} lualine_x = {}
} }
local config = {tabline = custom_sections} local config = {tabline = custom_sections}
config_module.apply_configuration(config) config = config_module.apply_configuration(config)
eq(config_module.config.tabline, expected_sections) eq(config.tabline, expected_sections)
end) end)
end) end)
describe('extensions', function() describe('extensions', function()
it('default', function() it('default', function()
local config = {options = {}} local config = {options = {}}
config_module.apply_configuration(config) config = config_module.apply_configuration(config)
eq(config_module.config.extensions, {}) eq(config.extensions, {})
end) end)
it('custom', function() it('custom', function()
local config = {extensions = {'fugitive'}} local config = {extensions = {'fugitive'}}
config_module.apply_configuration(config) config = config_module.apply_configuration(config)
eq(config_module.config.extensions, {'fugitive'}) eq(config.extensions, {'fugitive'})
end) end)
end) end)
end) end)