refactor: use nvim api directly for bufnr (#526)

This commit is contained in:
kylo252 2022-01-04 14:17:16 +01:00 committed by GitHub
parent 4b68b8dd2a
commit 02e1f6cd5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 14 additions and 14 deletions

View File

@ -35,7 +35,7 @@ end
---updates the current value of git_branch and sets up file watch on HEAD file ---updates the current value of git_branch and sets up file watch on HEAD file
local function update_branch() local function update_branch()
active_bufnr = tostring(vim.fn.bufnr()) active_bufnr = tostring(vim.api.nvim_get_current_buf())
file_changed:stop() file_changed:stop()
local git_dir = current_git_dir local git_dir = current_git_dir
if git_dir and #git_dir > 0 then if git_dir and #git_dir > 0 then
@ -53,7 +53,7 @@ local function update_branch()
-- set to '' when git dir was not found -- set to '' when git dir was not found
current_git_branch = '' current_git_branch = ''
end end
branch_cache[vim.fn.bufnr()] = current_git_branch branch_cache[vim.api.nvim_get_current_buf()] = current_git_branch
end end
---returns full path to git directory for dir_path or current directory ---returns full path to git directory for dir_path or current directory

View File

@ -14,7 +14,7 @@ M.init = function(self, options)
end end
M.update_status = function(_, is_focused) M.update_status = function(_, is_focused)
return git_branch.get_branch((not is_focused and vim.fn.bufnr())) return git_branch.get_branch((not is_focused and vim.api.nvim_get_current_buf()))
end end
return M return M

View File

@ -13,7 +13,7 @@ end
---setup icons, modified status for buffer ---setup icons, modified status for buffer
function Buffer:get_props() function Buffer:get_props()
self.file = vim.fn.bufname(self.bufnr) self.file = vim.api.nvim_buf_get_name(self.bufnr)
self.buftype = vim.api.nvim_buf_get_option(self.bufnr, 'buftype') self.buftype = vim.api.nvim_buf_get_option(self.bufnr, 'buftype')
self.filetype = vim.api.nvim_buf_get_option(self.bufnr, 'filetype') self.filetype = vim.api.nvim_buf_get_option(self.bufnr, 'filetype')
local modified = self.options.show_modified_status and vim.api.nvim_buf_get_option(self.bufnr, 'modified') local modified = self.options.show_modified_status and vim.api.nvim_buf_get_option(self.bufnr, 'modified')

View File

@ -66,11 +66,11 @@ function M:update_status()
local data = {} local data = {}
local buffers = {} local buffers = {}
for b = 1, vim.fn.bufnr('$') do for b = 1, vim.fn.bufnr('$') do
if vim.fn.buflisted(b) ~= 0 and vim.api.nvim_buf_get_option(b, 'buftype') ~= 'quickfix' then if vim.api.nvim_buf_get_option(b, 'buflisted') and vim.api.nvim_buf_get_option(b, 'buftype') ~= 'quickfix' then
buffers[#buffers + 1] = Buffer({ bufnr = b, options = self.options, highlights = self.highlights }) buffers[#buffers + 1] = Buffer({ bufnr = b, options = self.options, highlights = self.highlights })
end end
end end
local current_bufnr = vim.fn.bufnr() local current_bufnr = vim.api.nvim_get_current_buf()
local current = -2 local current = -2
-- mark the first, last, current, before current, after current buffers -- mark the first, last, current, before current, after current buffers
-- for rendering -- for rendering
@ -110,7 +110,7 @@ function M:update_status()
-- start drawing from current buffer and draw left and right of it until -- start drawing from current buffer and draw left and right of it until
-- all buffers are drawn or max_length has been reached. -- all buffers are drawn or max_length has been reached.
if current == -2 then if current == -2 then
local b = Buffer({ bufnr = vim.fn.bufnr(), options = self.options, highlights = self.highlights }) local b = Buffer({ bufnr = vim.api.nvim_get_current_buf(), options = self.options, highlights = self.highlights })
b.current = true b.current = true
if self.options.self.section < 'lualine_x' then if self.options.self.section < 'lualine_x' then
b.last = true b.last = true

View File

@ -101,7 +101,7 @@ It needs to be updated to:
end end
function M:update_status() function M:update_status()
local bufnr = vim.fn.bufnr() local bufnr = vim.api.nvim_get_current_buf()
local diagnostics_count local diagnostics_count
local result = {} local result = {}
if self.options.update_in_insert or vim.api.nvim_get_mode().mode:sub(1, 1) ~= 'i' then if self.options.update_in_insert or vim.api.nvim_get_mode().mode:sub(1, 1) ~= 'i' then

View File

@ -31,7 +31,7 @@ M.sources = {
end end
end, end,
ale = function() ale = function()
local ok, data = pcall(vim.fn['ale#statusline#Count'], vim.fn.bufnr()) local ok, data = pcall(vim.fn['ale#statusline#Count'], vim.api.nvim_get_current_buf())
if ok then if ok then
return data.error + data.style_error, data.warning + data.style_warning, data.info, 0 return data.error + data.style_error, data.warning + data.style_warning, data.info, 0
else else

View File

@ -44,7 +44,7 @@ function M.get_sign_count(bufnr)
end end
if M.src then if M.src then
git_diff = M.src() git_diff = M.src()
diff_cache[vim.fn.bufnr()] = git_diff diff_cache[vim.api.nvim_get_current_buf()] = git_diff
elseif vim.g.actual_curbuf ~= nil and active_bufnr ~= vim.g.actual_curbuf then elseif vim.g.actual_curbuf ~= nil and active_bufnr ~= vim.g.actual_curbuf then
-- Workaround for https://github.com/nvim-lualine/lualine.nvim/issues/286 -- Workaround for https://github.com/nvim-lualine/lualine.nvim/issues/286
-- See upstream issue https://github.com/neovim/neovim/issues/15300 -- See upstream issue https://github.com/neovim/neovim/issues/15300
@ -85,7 +85,7 @@ end
---updates the job args ---updates the job args
function M.update_diff_args() function M.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
active_bufnr = tostring(vim.fn.bufnr()) active_bufnr = tostring(vim.api.nvim_get_current_buf())
if #vim.fn.expand('%') == 0 then if #vim.fn.expand('%') == 0 then
M.diff_args = nil M.diff_args = nil
git_diff = nil git_diff = nil
@ -115,7 +115,7 @@ function M.update_diff_args()
else else
git_diff = { added = 0, modified = 0, removed = 0 } git_diff = { added = 0, modified = 0, removed = 0 }
end end
diff_cache[vim.fn.bufnr()] = git_diff diff_cache[vim.api.nvim_get_current_buf()] = git_diff
end, end,
} }
M.update_git_diff() M.update_git_diff()

View File

@ -66,7 +66,7 @@ end
-- Function that runs everytime statusline is updated -- Function that runs everytime statusline is updated
function M:update_status(is_focused) function M:update_status(is_focused)
local git_diff = modules.git_diff.get_sign_count((not is_focused and vim.fn.bufnr())) local git_diff = modules.git_diff.get_sign_count((not is_focused and vim.api.nvim_get_current_buf()))
if git_diff == nil then if git_diff == nil then
return '' return ''
end end

View File

@ -17,7 +17,7 @@ function Tab:label()
local buflist = vim.fn.tabpagebuflist(self.tabnr) local buflist = vim.fn.tabpagebuflist(self.tabnr)
local winnr = vim.fn.tabpagewinnr(self.tabnr) local winnr = vim.fn.tabpagewinnr(self.tabnr)
local bufnr = buflist[winnr] local bufnr = buflist[winnr]
local file = vim.fn.bufname(bufnr) local file = vim.api.nvim_buf_get_name(bufnr)
local buftype = vim.fn.getbufvar(bufnr, '&buftype') local buftype = vim.fn.getbufvar(bufnr, '&buftype')
if buftype == 'help' then if buftype == 'help' then
return 'help:' .. vim.fn.fnamemodify(file, ':t:r') return 'help:' .. vim.fn.fnamemodify(file, ':t:r')