|
1 | 1 | local config = {}
|
2 | 2 |
|
3 |
| -local function init(_, _config) |
4 |
| - config = vim.tbl_extend('force', config, _config) |
5 |
| -end |
| 3 | +local _errors |
| 4 | +local _warnings |
| 5 | +local _hints |
| 6 | +local _info |
| 7 | +local icons |
6 | 8 |
|
7 | 9 | local diagnostics = require('lsp-status/diagnostics')
|
8 | 10 | local messages = require('lsp-status/messaging').messages
|
9 | 11 | local aliases = {
|
10 | 12 | pyls_ms = 'MPLS',
|
11 | 13 | }
|
12 | 14 |
|
| 15 | +local function make_statusline_component(diagnostics_key) |
| 16 | + return function(bufh) |
| 17 | + bufh = bufh or vim.api.nvim_get_current_buf() |
| 18 | + local icon = icons[diagnostics_key] .. config.indicator_separator |
| 19 | + return (icon or '') .. diagnostics(bufh)[diagnostics_key] |
| 20 | + end |
| 21 | +end |
| 22 | + |
| 23 | +local function init(_, _config) |
| 24 | + config = vim.tbl_extend('force', config, _config) |
| 25 | + |
| 26 | + icons = { |
| 27 | + errors = config.indicator_errors, |
| 28 | + warnings = config.indicator_warnings, |
| 29 | + hints = config.indicator_hint, |
| 30 | + info = config.indicator_info, |
| 31 | + } |
| 32 | + |
| 33 | + _errors = make_statusline_component('errors') |
| 34 | + _warnings = make_statusline_component('warnings') |
| 35 | + _hints = make_statusline_component('hints') |
| 36 | + _info = make_statusline_component('info') |
| 37 | +end |
| 38 | + |
13 | 39 | local function statusline_lsp(bufnr)
|
14 | 40 | bufnr = bufnr or 0
|
15 | 41 | if #vim.lsp.buf_get_clients(bufnr) == 0 then
|
@@ -97,9 +123,19 @@ local function statusline_lsp(bufnr)
|
97 | 123 | return symbol .. config.indicator_ok .. ' '
|
98 | 124 | end
|
99 | 125 |
|
| 126 | +local function get_component_functions() |
| 127 | + return { |
| 128 | + errors = _errors, |
| 129 | + warnings = _warnings, |
| 130 | + hints = _hints, |
| 131 | + info = _info, |
| 132 | + } |
| 133 | +end |
| 134 | + |
100 | 135 | local M = {
|
101 | 136 | _init = init,
|
102 |
| - status = statusline_lsp |
| 137 | + status = statusline_lsp, |
| 138 | + _get_component_functions = get_component_functions |
103 | 139 | }
|
104 | 140 |
|
105 | 141 | return M
|
0 commit comments