fixup: fix update_in_insert caching colors in diagnostics
- mention colored option in docs - sort component option list alphabeticaly close #402
This commit is contained in:
parent
61cd6e6ef8
commit
8d8c538fb9
49
README.md
49
README.md
|
@ -451,6 +451,7 @@ sections = {
|
||||||
hint = nil, -- Changes diagnostic's hint color
|
hint = nil, -- Changes diagnostic's hint color
|
||||||
}
|
}
|
||||||
symbols = {error = 'E', warn = 'W', info = 'I', hint = 'H'}
|
symbols = {error = 'E', warn = 'W', info = 'I', hint = 'H'}
|
||||||
|
colored = true, -- displays diagnostics status in color if set to true
|
||||||
update_in_insert = false, -- Update diagnostics in insert mode
|
update_in_insert = false, -- Update diagnostics in insert mode
|
||||||
always_visible = false, -- Show diagnostics even if count is 0, boolean or function returning boolean
|
always_visible = false, -- Show diagnostics even if count is 0, boolean or function returning boolean
|
||||||
}
|
}
|
||||||
|
@ -458,6 +459,30 @@ sections = {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### diff component options
|
||||||
|
|
||||||
|
```lua
|
||||||
|
sections = {
|
||||||
|
lualine_a = {
|
||||||
|
{
|
||||||
|
'diff',
|
||||||
|
colored = true, -- displays diff status in color if set to true
|
||||||
|
-- all colors are in format #rrggbb
|
||||||
|
diff_color = {
|
||||||
|
added = nil, -- changes diff's added color
|
||||||
|
modified = nil, -- changes diff's modified color
|
||||||
|
removed = nil, -- changes diff's removed color
|
||||||
|
}
|
||||||
|
symbols = {added = '+', modified = '~', removed = '-'} -- changes diff symbols
|
||||||
|
source = nil, -- A function that works as a data source for diff.
|
||||||
|
-- it must return a table like
|
||||||
|
-- {added = add_count, modified = modified_count, removed = removed_count }
|
||||||
|
-- Or nil on failure. Count <= 0 won't be displayed.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#### filename component options
|
#### filename component options
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
|
@ -488,30 +513,6 @@ sections = {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
#### diff component options
|
|
||||||
|
|
||||||
```lua
|
|
||||||
sections = {
|
|
||||||
lualine_a = {
|
|
||||||
{
|
|
||||||
'diff',
|
|
||||||
colored = true, -- displays diff status in color if set to true
|
|
||||||
-- all colors are in format #rrggbb
|
|
||||||
diff_color = {
|
|
||||||
added = nil, -- changes diff's added color
|
|
||||||
modified = nil, -- changes diff's modified color
|
|
||||||
removed = nil, -- changes diff's removed color
|
|
||||||
}
|
|
||||||
symbols = {added = '+', modified = '~', removed = '-'} -- changes diff symbols
|
|
||||||
source = nil, -- A function that works as a data source for diff.
|
|
||||||
-- it must return a table like
|
|
||||||
-- {added = add_count, modified = modified_count, removed = removed_count }
|
|
||||||
-- Or nil on failure. Count <= 0 won't be displayed.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### tabs component options
|
#### tabs component options
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
|
|
|
@ -439,6 +439,7 @@ will be.
|
||||||
hint = nil, -- Changes diagnostic's hint color
|
hint = nil, -- Changes diagnostic's hint color
|
||||||
}
|
}
|
||||||
symbols = {error = 'E', warn = 'W', info = 'I', hint = 'H'}
|
symbols = {error = 'E', warn = 'W', info = 'I', hint = 'H'}
|
||||||
|
colored = true, -- displays diagnostics status in color if set to true
|
||||||
update_in_insert = false, -- Update diagnostics in insert mode
|
update_in_insert = false, -- Update diagnostics in insert mode
|
||||||
always_visible = false, -- Show diagnostics even if count is 0, boolean or function returning boolean
|
always_visible = false, -- Show diagnostics even if count is 0, boolean or function returning boolean
|
||||||
}
|
}
|
||||||
|
@ -447,6 +448,31 @@ will be.
|
||||||
<
|
<
|
||||||
|
|
||||||
|
|
||||||
|
*lualine-diff-component-options*
|
||||||
|
|
||||||
|
>
|
||||||
|
sections = {
|
||||||
|
lualine_a = {
|
||||||
|
{
|
||||||
|
'diff',
|
||||||
|
colored = true, -- displays diff status in color if set to true
|
||||||
|
-- all colors are in format #rrggbb
|
||||||
|
diff_color = {
|
||||||
|
added = nil, -- changes diff's added color
|
||||||
|
modified = nil, -- changes diff's modified color
|
||||||
|
removed = nil, -- changes diff's removed color
|
||||||
|
}
|
||||||
|
symbols = {added = '+', modified = '~', removed = '-'} -- changes diff symbols
|
||||||
|
source = nil, -- A function that works as a data source for diff.
|
||||||
|
-- it must return a table like
|
||||||
|
-- {added = add_count, modified = modified_count, removed = removed_count }
|
||||||
|
-- Or nil on failure. Count <= 0 won't be displayed.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
<
|
||||||
|
|
||||||
|
|
||||||
*lualine-filename-component-options*
|
*lualine-filename-component-options*
|
||||||
|
|
||||||
>
|
>
|
||||||
|
@ -479,31 +505,6 @@ will be.
|
||||||
<
|
<
|
||||||
|
|
||||||
|
|
||||||
*lualine-diff-component-options*
|
|
||||||
|
|
||||||
>
|
|
||||||
sections = {
|
|
||||||
lualine_a = {
|
|
||||||
{
|
|
||||||
'diff',
|
|
||||||
colored = true, -- displays diff status in color if set to true
|
|
||||||
-- all colors are in format #rrggbb
|
|
||||||
diff_color = {
|
|
||||||
added = nil, -- changes diff's added color
|
|
||||||
modified = nil, -- changes diff's modified color
|
|
||||||
removed = nil, -- changes diff's removed color
|
|
||||||
}
|
|
||||||
symbols = {added = '+', modified = '~', removed = '-'} -- changes diff symbols
|
|
||||||
source = nil, -- A function that works as a data source for diff.
|
|
||||||
-- it must return a table like
|
|
||||||
-- {added = add_count, modified = modified_count, removed = removed_count }
|
|
||||||
-- Or nil on failure. Count <= 0 won't be displayed.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
<
|
|
||||||
|
|
||||||
|
|
||||||
*lualine-tabs-component-options*
|
*lualine-tabs-component-options*
|
||||||
|
|
||||||
>
|
>
|
||||||
|
|
|
@ -60,13 +60,14 @@ function M:init(options)
|
||||||
end
|
end
|
||||||
-- Initialize variable to store last update so we can use it in insert
|
-- Initialize variable to store last update so we can use it in insert
|
||||||
-- mode for no update_in_insert
|
-- mode for no update_in_insert
|
||||||
self.last_update = ''
|
self.last_diagnostics_count = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
function M:update_status()
|
function M:update_status()
|
||||||
if not self.options.update_in_insert and vim.api.nvim_get_mode().mode:sub(1, 1) == 'i' then
|
local bufnr = vim.fn.bufnr()
|
||||||
return self.last_update
|
local diagnostics_count
|
||||||
end
|
local result = {}
|
||||||
|
if self.options.update_in_insert or vim.api.nvim_get_mode().mode:sub(1, 1) ~= 'i' then
|
||||||
local error_count, warning_count, info_count, hint_count = 0, 0, 0, 0
|
local error_count, warning_count, info_count, hint_count = 0, 0, 0, 0
|
||||||
local diagnostic_data = modules.sources.get_diagnostics(self.options.sources)
|
local diagnostic_data = modules.sources.get_diagnostics(self.options.sources)
|
||||||
-- sum all the counts
|
-- sum all the counts
|
||||||
|
@ -76,13 +77,17 @@ function M:update_status()
|
||||||
info_count = info_count + data.info
|
info_count = info_count + data.info
|
||||||
hint_count = hint_count + data.hint
|
hint_count = hint_count + data.hint
|
||||||
end
|
end
|
||||||
local result = {}
|
diagnostics_count = {
|
||||||
local data = {
|
|
||||||
error = error_count,
|
error = error_count,
|
||||||
warn = warning_count,
|
warn = warning_count,
|
||||||
info = info_count,
|
info = info_count,
|
||||||
hint = hint_count,
|
hint = hint_count,
|
||||||
}
|
}
|
||||||
|
-- Save count for insert mode
|
||||||
|
self.last_diagnostics_count[bufnr] = diagnostics_count
|
||||||
|
else -- Use cached count in insert mode with update_in_insert disabled
|
||||||
|
diagnostics_count = self.last_diagnostics_count[bufnr] or { error = 0, warn = 0, info = 0, hint = 0 }
|
||||||
|
end
|
||||||
|
|
||||||
local always_visible = false
|
local always_visible = false
|
||||||
if type(self.options.always_visible) == 'boolean' then
|
if type(self.options.always_visible) == 'boolean' then
|
||||||
|
@ -98,22 +103,18 @@ function M:update_status()
|
||||||
colors[name] = modules.highlight.component_format_highlight(hl)
|
colors[name] = modules.highlight.component_format_highlight(hl)
|
||||||
end
|
end
|
||||||
for _, section in ipairs(self.options.sections) do
|
for _, section in ipairs(self.options.sections) do
|
||||||
if data[section] ~= nil and (always_visible or data[section] > 0) then
|
if diagnostics_count[section] ~= nil and (always_visible or diagnostics_count[section] > 0) then
|
||||||
table.insert(result, colors[section] .. self.symbols[section] .. data[section])
|
table.insert(result, colors[section] .. self.symbols[section] .. diagnostics_count[section])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
for _, section in ipairs(self.options.sections) do
|
for _, section in ipairs(self.options.sections) do
|
||||||
if data[section] ~= nil and (always_visible or data[section] > 0) then
|
if diagnostics_count[section] ~= nil and (always_visible or diagnostics_count[section] > 0) then
|
||||||
table.insert(result, self.symbols[section] .. data[section])
|
table.insert(result, self.symbols[section] .. diagnostics_count[section])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self.last_update = ''
|
return table.concat(result, ' ')
|
||||||
if result[1] ~= nil then
|
|
||||||
self.last_update = table.concat(result, ' ')
|
|
||||||
end
|
|
||||||
return self.last_update
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Reference in New Issue