refactor(incline.lua): improve code formatting and indentation for better readability

feat(incline.lua): add support for displaying diagnostic signs and git diff
information in the incline plugin to enhance user experience
This commit is contained in:
David Ibia
2024-02-26 14:57:09 +01:00
parent e328a43453
commit 6fba1ca3f1

View File

@@ -3,57 +3,57 @@ local helpers = require("incline.helpers")
local devicons = require("nvim-web-devicons") local devicons = require("nvim-web-devicons")
incline.setup({ incline.setup({
window = { window = {
padding = 0, padding = 0,
margin = { horizontal = 0 }, margin = { horizontal = 0 },
}, },
render = function(props) render = function(props)
local filename = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(props.buf), ":t") local filename = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(props.buf), ":t")
local ft_icon, ft_color = devicons.get_icon_color(filename) local ft_icon, ft_color = devicons.get_icon_color(filename)
local modified = vim.bo[props.buf].modified local modified = vim.bo[props.buf].modified
local function get_git_diff() local function get_git_diff()
local icons = { removed = "", changed = "", added = "" } local icons = { removed = "", changed = "", added = "" }
local signs = vim.b[props.buf].gitsigns_status_dict local signs = vim.b[props.buf].gitsigns_status_dict
local labels = {} local labels = {}
if signs == nil then if signs == nil then
return labels return labels
end end
for name, icon in pairs(icons) do for name, icon in pairs(icons) do
if tonumber(signs[name]) and signs[name] > 0 then if tonumber(signs[name]) and signs[name] > 0 then
table.insert(labels, { icon .. signs[name] .. " ", group = "Diff" .. name }) table.insert(labels, { icon .. signs[name] .. " ", group = "Diff" .. name })
end end
end end
if #labels > 0 then if #labels > 0 then
table.insert(labels, { "" }) table.insert(labels, { "" })
end end
return labels return labels
end end
local function get_diagnostic_label() local function get_diagnostic_label()
local icons = { error = "", warn = "", info = "", hint = "" } local icons = { error = "", warn = "", info = "", hint = "" }
local label = {} local label = {}
for severity, icon in pairs(icons) do for severity, icon in pairs(icons) do
local n = #vim.diagnostic.get(props.buf, { severity = vim.diagnostic.severity[string.upper(severity)] }) local n = #vim.diagnostic.get(props.buf, { severity = vim.diagnostic.severity[string.upper(severity)] })
if n > 0 then if n > 0 then
table.insert(label, { icon .. n .. " ", group = "DiagnosticSign" .. severity }) table.insert(label, { icon .. n .. " ", group = "DiagnosticSign" .. severity })
end end
end end
if #label > 0 then if #label > 0 then
table.insert(label, { "" }) table.insert(label, { "" })
end end
return label return label
end end
return { return {
{ get_diagnostic_label() }, { get_diagnostic_label() },
{ get_git_diff() }, { get_git_diff() },
ft_icon and { " ", ft_icon, " ", guibg = ft_color, guifg = helpers.contrast_color(ft_color) } or "", ft_icon and { ' ', ft_icon, ' ', guibg = ft_color, guifg = helpers.contrast_color(ft_color) } or '',
" ", ' ',
{ filename, gui = modified and "bold,italic" or "bold" }, { filename, gui = modified and 'bold,italic' or 'bold' },
" ", ' ',
guibg = "#44406e", guibg = '#44406e',
} }
end, end,
}) })