feat: customize symbols for the diagnostics component (#112)

This commit is contained in:
JINNOUCHI Yasushi 2021-02-22 20:43:51 +09:00 committed by GitHub
parent 1c44781835
commit 7115aa8f8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 18 deletions

View File

@ -198,7 +198,7 @@ All of these options can also be specifically set to all supported components, f
##### Available global options ##### Available global options
Option | Default | Behaviour | Supported components Option | Default | Behaviour | Supported components
:------: | :------: | :----------: | :-----: :------: | :------: | :----------: | :-----:
icons_enabled | true | Displays icons on components You should have powerline supported fonts to see icons properly. | branch, fileformat, filetype, location icons_enabled | true | Displays icons on components You should have nerd-fonts supported fonts to see icons properly. | branch, fileformat, filetype, location, diagnostics
padding | 1 | Adds padding to the left and right of components | all padding | 1 | Adds padding to the left and right of components | all
left_padding | 1 | Adds padding to the left of components | all left_padding | 1 | Adds padding to the left of components | all
right_padding | 1 | Adds padding to the right of components | all right_padding | 1 | Adds padding to the right of components | all
@ -229,6 +229,7 @@ sections | `{'error', 'warn', 'info'}` | displays diagnostics of defined severit
color_error | `DiffDelete` foreground color | changes diagnostic's error section foreground color | color in `#rrggbb` format color_error | `DiffDelete` foreground color | changes diagnostic's error section foreground color | color in `#rrggbb` format
color_warn | `DiffText` foreground color | changes diagnostic's warn section foreground color | color in `#rrggbb` format color_warn | `DiffText` foreground color | changes diagnostic's warn section foreground color | color in `#rrggbb` format
color_info | `Normal` foreground color | changes diagnostic's info section foreground color | color in `#rrggbb` format color_info | `Normal` foreground color | changes diagnostic's info section foreground color | color in `#rrggbb` format
symbols | `{error = ' ', warn = ' ', info = ' '}` or `{error = 'E:', warn = 'W:', info = 'I:'}` | changes diagnostic's info section foreground color | table containing one or more symbols for levels |
* `filename` component options * `filename` component options

View File

@ -217,7 +217,7 @@ Default options act as default for all components
icons_enabled (Default: true) icons_enabled (Default: true)
Displays icons on components Displays icons on components
You should have powerline supported fonts to see You should have nerd-fonts supported fonts to see
icons properly. icons properly.
Suported by branch, fileformat, filetype, location Suported by branch, fileformat, filetype, location
@ -296,6 +296,21 @@ List of options are given below.
changes diagnostic's info section foreground color changes diagnostic's info section foreground color
color in #rrggbb format color in #rrggbb format
• symbols
(icons_enabled: true -> {error = ' ', warn = ' ', info = ' '})
(icons_enabled: false -> {error = 'E:', warn = 'W:', info = 'I:'})
changes diagnostic's symbol characters. You can set one or more symbols
for each level.
>
{
'diagnostics',
symbols = {
-- set the error symbol and use defaults for warn and info.
error = '!!',
},
}
<
• filename~ • filename~
• file_status (true) • file_status (true)
Whether to display filemodified status in filename Whether to display filemodified status in filename

View File

@ -43,20 +43,16 @@ local function get_diagnostics(sources)
end end
local function diagnostics(options) local function diagnostics(options)
local symbols local default_symbols = options.icons_enabled and {
if options.icons_enabled then error = '', -- xf659
symbols = { warn = '', -- xf529
error = '', -- xf659 info = '', -- xf7fc
warn = '', -- xf529 } or {
info = '', -- xf7fc error = 'E:',
} warn = 'W:',
else info = 'I:'
symbols = { }
error = 'E:', options.symbols = vim.tbl_extend('force', default_symbols, options.symbols or {})
warn = 'W:',
info = 'I:'
}
end
if options.sources == nil then if options.sources == nil then
print('no sources for diagnostics configured') print('no sources for diagnostics configured')
return '' return ''
@ -109,13 +105,13 @@ local function diagnostics(options)
end end
for _, section in ipairs(options.sections) do for _, section in ipairs(options.sections) do
if data[section] ~= nil and data[section] > 0 then if data[section] ~= nil and data[section] > 0 then
table.insert(result, colors[section]..symbols[section]..data[section]) table.insert(result, colors[section]..options.symbols[section]..data[section])
end end
end end
else else
for _, section in ipairs(options.sections) do for _, section in ipairs(options.sections) do
if data[section] ~= nil and data[section] > 0 then if data[section] ~= nil and data[section] > 0 then
table.insert(result,symbols[section]..data[section]) table.insert(result,options.symbols[section]..data[section])
end end
end end
end end