Skip to content

Commit 5a7b811

Browse files
committed
Improve statusline configurability
1 parent f94ec6c commit 5a7b811

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

lua/lsp-status.lua

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
local _config = {}
22
local default_config = {
3-
kind_labels = {}
3+
kind_labels = {},
4+
indicator_errors = '',
5+
indicator_warnings = '',
6+
indicator_info = '🛈',
7+
indicator_hint = '',
8+
indicator_ok = '',
9+
spinner_frames = { '', '', '', '', '', '', '', '' },
10+
status_symbol = ' 🇻',
11+
select_symbol = nil
412
}
513

614
_config = vim.deepcopy(default_config)
715
local messages = {}
816

917
-- Diagnostics
18+
--- Get all diagnostics for the current buffer.
19+
--- Convenience function to retrieve all diagnostic counts for the current buffer.
20+
--@returns `{ 'Error': error_count, 'Warning': warning_count', 'Info': info_count, 'Hint': hint_count `}
21+
local function diagnostics() -- luacheck: no unused
22+
error() -- Stub for docs
23+
end
1024
local diagnostics = require('lsp-status/diagnostics')
1125

1226
-- Messaging
@@ -68,7 +82,7 @@ local M = {
6882
extensions = extension_callbacks,
6983
config = configure,
7084
on_attach = on_attach,
71-
status = statusline,
85+
status = statusline.status,
7286
capabilities = messaging.capabilities
7387
}
7488

lua/lsp-status/current_function.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ local function current_function_callback(_, _, result, _, _)
2929
or (_config.select_symbol and _config.select_symbol(cursor_pos, sym.raw_item))
3030
then
3131
local fn_name = sym.text
32-
if _config.kind_labels[sym.kind] then
32+
if _config.kind_labels and _config.kind_labels[sym.kind] then
3333
fn_name = _config.kind_labels[sym.kind] .. ' ' .. fn_name
3434
end
3535

lua/lsp-status/statusline.lua

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
vim.g.indicator_errors = ''
2-
vim.g.indicator_warnings = ''
3-
vim.g.indicator_info = '🛈'
4-
vim.g.indicator_hint = ''
5-
vim.g.indicator_ok = ''
6-
vim.g.spinner_frames = { '', '', '', '', '', '', '', '' }
1+
local config = {}
2+
3+
local function init(_, _config)
4+
config = vim.tbl_extend('force', config, _config)
5+
end
76

87
local diagnostics = require('lsp-status/diagnostics')
98
local messages = require('lsp-status/messaging').messages
@@ -22,25 +21,25 @@ local function statusline_lsp()
2221
local some_diagnostics = false
2322
local status_parts = {}
2423
if buf_diagnostics.errors and buf_diagnostics.errors > 0 then
25-
table.insert(status_parts, vim.g.indicator_errors .. ' ' .. buf_diagnostics.errors)
24+
table.insert(status_parts, config.indicator_errors .. ' ' .. buf_diagnostics.errors)
2625
only_hint = false
2726
some_diagnostics = true
2827
end
2928

3029
if buf_diagnostics.warnings and buf_diagnostics.warnings > 0 then
31-
table.insert(status_parts, vim.g.indicator_warnings .. ' ' .. buf_diagnostics.warnings)
30+
table.insert(status_parts, config.indicator_warnings .. ' ' .. buf_diagnostics.warnings)
3231
only_hint = false
3332
some_diagnostics = true
3433
end
3534

3635
if buf_diagnostics.info and buf_diagnostics.info > 0 then
37-
table.insert(status_parts, vim.g.indicator_info .. ' ' .. buf_diagnostics.info)
36+
table.insert(status_parts, config.indicator_info .. ' ' .. buf_diagnostics.info)
3837
only_hint = false
3938
some_diagnostics = true
4039
end
4140

4241
if buf_diagnostics.hints and buf_diagnostics.hints > 0 then
43-
table.insert(status_parts, vim.g.indicator_hint .. ' ' .. buf_diagnostics.hints)
42+
table.insert(status_parts, config.indicator_hint .. ' ' .. buf_diagnostics.hints)
4443
some_diagnostics = true
4544
end
4645

@@ -60,7 +59,7 @@ local function statusline_lsp()
6059
end
6160

6261
if msg.spinner then
63-
contents = vim.g.spinner_frames[(msg.spinner % #vim.g.spinner_frames) + 1] .. ' ' .. contents
62+
contents = config.spinner_frames[(msg.spinner % #config.spinner_frames) + 1] .. ' ' .. contents
6463
end
6564
elseif msg.status then
6665
contents = msg.content
@@ -82,7 +81,7 @@ local function statusline_lsp()
8281
end
8382

8483
local base_status = vim.trim(table.concat(status_parts, ' ') .. ' ' .. table.concat(msgs, ' '))
85-
local symbol = ' 🇻' .. ((some_diagnostics and only_hint) and '' or ' ')
84+
local symbol = config.status_symbol .. ((some_diagnostics and only_hint) and '' or ' ')
8685
local current_function = vim.b.lsp_current_function
8786
if current_function and current_function ~= '' then
8887
symbol = symbol .. '(' .. current_function .. ') '
@@ -92,7 +91,12 @@ local function statusline_lsp()
9291
return symbol .. base_status .. ' '
9392
end
9493

95-
return symbol .. vim.g.indicator_ok .. ' '
94+
return symbol .. config.indicator_ok .. ' '
9695
end
9796

98-
return statusline_lsp
97+
local M = {
98+
_init = init,
99+
status = statusline_lsp
100+
}
101+
102+
return M

0 commit comments

Comments
 (0)