Fix: branch and diff disappearing with diagnostics.goto_next())
I've added a workaround to re sync those components when they go out of sync . Until upstream issue is addressed this should prevent this issue from occurring in lualine.
This commit is contained in:
parent
f68d81d351
commit
edb8c344f7
|
@ -8,6 +8,7 @@ Branch.git_branch = ''
|
||||||
Branch.sep = package.config:sub(1, 1)
|
Branch.sep = package.config:sub(1, 1)
|
||||||
-- event watcher to watch head file
|
-- event watcher to watch head file
|
||||||
Branch.file_changed = vim.loop.new_fs_event()
|
Branch.file_changed = vim.loop.new_fs_event()
|
||||||
|
Branch.active_bufnr = '0'
|
||||||
local branch_cache = {} -- stores last known branch for a buffer
|
local branch_cache = {} -- stores last known branch for a buffer
|
||||||
-- Initilizer
|
-- Initilizer
|
||||||
Branch.new = function(self, options, child)
|
Branch.new = function(self, options, child)
|
||||||
|
@ -23,6 +24,12 @@ Branch.new = function(self, options, child)
|
||||||
end
|
end
|
||||||
|
|
||||||
Branch.update_status = function(_, is_focused)
|
Branch.update_status = function(_, is_focused)
|
||||||
|
if Branch.active_bufnr ~= vim.g.actual_curbuf then
|
||||||
|
-- Workaround for https://github.com/hoob3rt/lualine.nvim/issues/286
|
||||||
|
-- See upstream issue https://github.com/neovim/neovim/issues/15300
|
||||||
|
-- Diff is out of sync re sync it.
|
||||||
|
Branch.update_branch()
|
||||||
|
end
|
||||||
if not is_focused then return branch_cache[vim.fn.bufnr()] or '' end
|
if not is_focused then return branch_cache[vim.fn.bufnr()] or '' end
|
||||||
return Branch.git_branch
|
return Branch.git_branch
|
||||||
end
|
end
|
||||||
|
@ -79,6 +86,7 @@ end
|
||||||
|
|
||||||
-- Update branch
|
-- Update branch
|
||||||
function Branch.update_branch()
|
function Branch.update_branch()
|
||||||
|
Branch.active_bufnr = tostring(vim.fn.bufnr())
|
||||||
Branch.file_changed:stop()
|
Branch.file_changed:stop()
|
||||||
local git_dir = Branch.find_git_dir()
|
local git_dir = Branch.find_git_dir()
|
||||||
if git_dir and #git_dir > 0 then
|
if git_dir and #git_dir > 0 then
|
||||||
|
|
|
@ -14,6 +14,7 @@ Diff.git_diff = nil
|
||||||
Diff.diff_output_cache = {}
|
Diff.diff_output_cache = {}
|
||||||
-- variable to store git_diff job
|
-- variable to store git_diff job
|
||||||
Diff.diff_job = nil
|
Diff.diff_job = nil
|
||||||
|
Diff.active_bufnr = '0'
|
||||||
-- default colors
|
-- default colors
|
||||||
Diff.default_colors = {
|
Diff.default_colors = {
|
||||||
added = '#f0e130',
|
added = '#f0e130',
|
||||||
|
@ -109,12 +110,19 @@ Diff.new = function(self, options, child)
|
||||||
utils.define_autocmd('BufEnter', "lua require'lualine.components.diff'.update_diff_args()")
|
utils.define_autocmd('BufEnter', "lua require'lualine.components.diff'.update_diff_args()")
|
||||||
utils.define_autocmd('BufWritePost', "lua require'lualine.components.diff'.update_git_diff()")
|
utils.define_autocmd('BufWritePost', "lua require'lualine.components.diff'.update_git_diff()")
|
||||||
end
|
end
|
||||||
|
Diff.update_diff_args()
|
||||||
|
|
||||||
return new_instance
|
return new_instance
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Function that runs everytime statusline is updated
|
-- Function that runs everytime statusline is updated
|
||||||
Diff.update_status = function(self, is_focused)
|
Diff.update_status = function(self, is_focused)
|
||||||
|
if Diff.active_bufnr ~= vim.g.actual_curbuf then
|
||||||
|
-- Workaround for https://github.com/hoob3rt/lualine.nvim/issues/286
|
||||||
|
-- See upstream issue https://github.com/neovim/neovim/issues/15300
|
||||||
|
-- Diff is out of sync re sync it.
|
||||||
|
Diff.update_diff_args()
|
||||||
|
end
|
||||||
local git_diff = Diff.git_diff
|
local git_diff = Diff.git_diff
|
||||||
if self.options.source then
|
if self.options.source then
|
||||||
git_diff = self.options.source()
|
git_diff = self.options.source()
|
||||||
|
@ -195,6 +203,7 @@ end
|
||||||
-- Updates the job args
|
-- Updates the job args
|
||||||
function Diff.update_diff_args()
|
function Diff.update_diff_args()
|
||||||
-- Donn't show git diff when current buffer doesn't have a filename
|
-- Donn't show git diff when current buffer doesn't have a filename
|
||||||
|
Diff.active_bufnr = tostring(vim.fn.bufnr())
|
||||||
if #vim.fn.expand('%') == 0 then
|
if #vim.fn.expand('%') == 0 then
|
||||||
Diff.diff_args = nil;
|
Diff.diff_args = nil;
|
||||||
Diff.git_diff = nil;
|
Diff.git_diff = nil;
|
||||||
|
|
Loading…
Reference in New Issue