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)
|
||||
-- event watcher to watch head file
|
||||
Branch.file_changed = vim.loop.new_fs_event()
|
||||
Branch.active_bufnr = '0'
|
||||
local branch_cache = {} -- stores last known branch for a buffer
|
||||
-- Initilizer
|
||||
Branch.new = function(self, options, child)
|
||||
|
@ -23,6 +24,12 @@ Branch.new = function(self, options, child)
|
|||
end
|
||||
|
||||
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
|
||||
return Branch.git_branch
|
||||
end
|
||||
|
@ -79,6 +86,7 @@ end
|
|||
|
||||
-- Update branch
|
||||
function Branch.update_branch()
|
||||
Branch.active_bufnr = tostring(vim.fn.bufnr())
|
||||
Branch.file_changed:stop()
|
||||
local git_dir = Branch.find_git_dir()
|
||||
if git_dir and #git_dir > 0 then
|
||||
|
|
|
@ -14,6 +14,7 @@ Diff.git_diff = nil
|
|||
Diff.diff_output_cache = {}
|
||||
-- variable to store git_diff job
|
||||
Diff.diff_job = nil
|
||||
Diff.active_bufnr = '0'
|
||||
-- default colors
|
||||
Diff.default_colors = {
|
||||
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('BufWritePost', "lua require'lualine.components.diff'.update_git_diff()")
|
||||
end
|
||||
Diff.update_diff_args()
|
||||
|
||||
return new_instance
|
||||
end
|
||||
|
||||
-- Function that runs everytime statusline is updated
|
||||
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
|
||||
if self.options.source then
|
||||
git_diff = self.options.source()
|
||||
|
@ -195,6 +203,7 @@ end
|
|||
-- Updates the job args
|
||||
function Diff.update_diff_args()
|
||||
-- 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
|
||||
Diff.diff_args = nil;
|
||||
Diff.git_diff = nil;
|
||||
|
|
Loading…
Reference in New Issue