Remove new_async():send() pattern + restructure augroup

This does not load load lualine asyncronasly rather fools the profilers
In addition causes issues like intro disapearing
This commit is contained in:
shadmansaleh 2021-08-02 21:16:17 +06:00
parent 7a45a4f7fe
commit 486be4462f
3 changed files with 44 additions and 52 deletions

View File

@ -18,7 +18,7 @@ Branch.new = function(self, options, child)
-- run watch head on load so branch is present when component is loaded -- run watch head on load so branch is present when component is loaded
Branch.update_branch() Branch.update_branch()
-- update branch state of BufEnter as different Buffer may be on different repos -- update branch state of BufEnter as different Buffer may be on different repos
vim.cmd [[autocmd BufEnter * lua require'lualine.components.branch'.update_branch()]] vim.cmd [[autocmd lualine BufEnter * lua require'lualine.components.branch'.update_branch()]]
return new_branch return new_branch
end end

View File

@ -167,33 +167,25 @@ end
local function tabline() return statusline(config.tabline, true) end local function tabline() return statusline(config.tabline, true) end
local function setup_theme() local function setup_theme()
local async_loader local function get_theme_from_config()
async_loader = vim.loop.new_async(vim.schedule_wrap( local theme_name = config.options.theme
function() if type(theme_name) == 'string' then
local function get_theme_from_config() package.loaded['lualine.themes.'..theme_name] = nil
local theme_name = config.options.theme local ok, theme = pcall(require, 'lualine.themes.' .. theme_name)
if type(theme_name) == 'string' then if ok then return theme end
package.loaded['lualine.themes.'..theme_name] = nil elseif type(theme_name) == 'table' then
local ok, theme = pcall(require, 'lualine.themes.' .. theme_name) -- use the provided theme as-is
if ok then return theme end return config.options.theme
elseif type(theme_name) == 'table' then end
-- use the provided theme as-is vim.api.nvim_err_writeln('theme ' .. tostring(theme_name) ..
return config.options.theme ' not found, defaulting to gruvbox')
end return require 'lualine.themes.gruvbox'
vim.api.nvim_err_writeln('theme ' .. tostring(theme_name) .. end
' not found, defaulting to gruvbox') local theme = get_theme_from_config()
return require 'lualine.themes.gruvbox' highlight.create_highlight_groups(theme)
end vim.cmd [[
local theme = get_theme_from_config() autocmd lualine ColorScheme * lua require'lualine.utils.utils'.reload_highlights()
highlight.create_highlight_groups(theme) ]]
vim.api.nvim_exec([[
augroup lualine
autocmd ColorScheme * lua require'lualine.utils.utils'.reload_highlights()
augroup END
]], false)
async_loader:close()
end))
async_loader:send()
end end
local function set_tabline() local function set_tabline()
@ -207,16 +199,21 @@ local function set_statusline()
if next(config.sections) ~= nil or next(config.inactive_sections) ~= nil then if next(config.sections) ~= nil or next(config.inactive_sections) ~= nil then
vim.o.statusline = '%!v:lua.require\'lualine\'.statusline()' vim.o.statusline = '%!v:lua.require\'lualine\'.statusline()'
vim.api.nvim_exec([[ vim.api.nvim_exec([[
augroup lualine autocmd lualine WinLeave,BufLeave * lua vim.wo.statusline=require'lualine'.statusline()
autocmd! autocmd lualine BufWinEnter,WinEnter,BufEnter,SessionLoadPost * set statusline<
autocmd WinLeave,BufLeave * lua vim.wo.statusline=require'lualine'.statusline() autocmd lualine VimResized * redrawstatus
autocmd BufWinEnter,WinEnter,BufEnter,SessionLoadPost * set statusline<
autocmd VimResized * redrawstatus
augroup END
]], false) ]], false)
end end
end end
local function setup_augroup()
vim.cmd [[
augroup lualine
autocmd!
augroup END
]]
end
local function setup(user_config) local function setup(user_config)
if user_config then if user_config then
config = config_module.apply_configuration(user_config) config = config_module.apply_configuration(user_config)
@ -229,6 +226,7 @@ local function setup(user_config)
else else
config = config_module.apply_configuration({}) config = config_module.apply_configuration({})
end end
setup_augroup()
setup_theme() setup_theme()
loader.load_all(config) loader.load_all(config)
set_statusline() set_statusline()

View File

@ -24,24 +24,18 @@ local function component_loader(component)
end end
local function load_sections(sections, options) local function load_sections(sections, options)
local async_loader for section_name, section in pairs(sections) do
async_loader = vim.loop.new_async(vim.schedule_wrap( for index, component in pairs(section) do
function() if type(component) == 'string' or type(component) == 'function' then
for section_name, section in pairs(sections) do component = {component}
for index, component in pairs(section) do end
if type(component) == 'string' or type(component) == 'function' then component.self = {}
component = {component} component.self.section = section_name
end -- apply default args
component.self = {} component = vim.tbl_extend('keep', component, options)
component.self.section = section_name section[index] = component_loader(component)
-- apply default args end
component = vim.tbl_extend('keep', component, options) end
section[index] = component_loader(component)
end
end
async_loader:close()
end))
async_loader:send()
end end
local function load_components(config) local function load_components(config)