diff --git a/lua/lsp-status.lua b/lua/lsp-status.lua index 3c01090..878a29c 100644 --- a/lua/lsp-status.lua +++ b/lua/lsp-status.lua @@ -66,6 +66,7 @@ local function config(user_config) messaging._init(messages, _config) if _config.current_function then current_function._init(messages, _config) end statusline._init(messages, _config) + statusline = vim.tbl_extend('keep', statusline, statusline._get_component_functions()) end --- Register a new server for messages. @@ -176,6 +177,10 @@ local M = { config = config, on_attach = on_attach, status = statusline.status, + status_errors = statusline.errors, + status_warnings = statusline.warnings, + status_info = statusline.info, + status_hints = statusline.hints, capabilities = messaging.capabilities } diff --git a/lua/lsp-status/statusline.lua b/lua/lsp-status/statusline.lua index 8510801..68432df 100644 --- a/lua/lsp-status/statusline.lua +++ b/lua/lsp-status/statusline.lua @@ -1,8 +1,10 @@ local config = {} -local function init(_, _config) - config = vim.tbl_extend('force', config, _config) -end +local _errors +local _warnings +local _hints +local _info +local icons local diagnostics = require('lsp-status/diagnostics') local messages = require('lsp-status/messaging').messages @@ -10,6 +12,30 @@ local aliases = { pyls_ms = 'MPLS', } +local function make_statusline_component(diagnostics_key) + return function(bufh) + bufh = bufh or vim.api.nvim_get_current_buf() + local icon = icons[diagnostics_key] .. config.indicator_separator + return (icon or '') .. diagnostics(bufh)[diagnostics_key] + end +end + +local function init(_, _config) + config = vim.tbl_extend('force', config, _config) + + icons = { + errors = config.indicator_errors, + warnings = config.indicator_warnings, + hints = config.indicator_hint, + info = config.indicator_info, + } + + _errors = make_statusline_component('errors') + _warnings = make_statusline_component('warnings') + _hints = make_statusline_component('hints') + _info = make_statusline_component('info') +end + local function statusline_lsp(bufnr) bufnr = bufnr or 0 if #vim.lsp.buf_get_clients(bufnr) == 0 then @@ -97,9 +123,19 @@ local function statusline_lsp(bufnr) return symbol .. config.indicator_ok .. ' ' end +local function get_component_functions() + return { + errors = _errors, + warnings = _warnings, + hints = _hints, + info = _info, + } +end + local M = { _init = init, - status = statusline_lsp + status = statusline_lsp, + _get_component_functions = get_component_functions } return M