Skip to content

Commit

Permalink
functions for statusline components (#39)
Browse files Browse the repository at this point in the history
* functions for statusline components

* some accidental Js

* add bufh param

* removing an extra space after icon

* [WIP] statusline component factory function

* call factory function in init

* add component functions to statusline after config init

* adding spaces after the icons that need it

* remove icon param

* replace hard coded space in favor of indicator_separator
  • Loading branch information
anott03 authored Feb 14, 2021
1 parent 187c492 commit 925acda
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lua/lsp-status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}

Expand Down
44 changes: 40 additions & 4 deletions lua/lsp-status/statusline.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
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
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
Expand Down Expand Up @@ -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

0 comments on commit 925acda

Please sign in to comment.