Skip to content

Commit 3fd06d6

Browse files
committed
Make timer update interval configurable
1 parent 0321c5f commit 3fd06d6

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

lua/lsp-status.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ local default_config = {
99
indicator_ok = '',
1010
spinner_frames = { '', '', '', '', '', '', '', '' },
1111
status_symbol = ' 🇻',
12-
select_symbol = nil
12+
select_symbol = nil,
13+
update_interval = 100
1314
}
1415
local _config = vim.deepcopy(default_config)
1516

@@ -40,6 +41,7 @@ local extension_callbacks = {
4041
local current_function = require('lsp-status/current_function')
4142

4243
-- Out-of-the-box statusline component
44+
local timer = require('lsp-status/timer')
4345
local statusline = require('lsp-status/statusline')
4446

4547
--- Configure lsp-status.nvim.
@@ -66,6 +68,7 @@ local function config(user_config)
6668
messaging._init(messages, _config)
6769
if _config.current_function then current_function._init(messages, _config) end
6870
statusline._init(messages, _config)
71+
timer._init(messages, _config)
6972
statusline = vim.tbl_extend('keep', statusline, statusline._get_component_functions())
7073
end
7174

@@ -89,7 +92,7 @@ local function on_attach(client)
8992
vim.api.nvim_command('augroup END')
9093
end
9194

92-
require('lsp-status/timer').register_timer()
95+
timer.register_timer()
9396
end
9497

9598
config(_config)

lua/lsp-status/timer.lua

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ local timer = nil
77
-- statusline and this flag will be set to false.
88
local redraw_flag = false
99

10+
local config = {}
11+
local function init(_, _config) config = vim.tbl_extend('force', config, _config) end
12+
1013
--- Timer callback function
1114
-- NOTE: This function uses get_lsp_statusline so that needs nvim api functions
1215
-- so it should call in the vim.schedule_wrap()
@@ -41,15 +44,10 @@ local function register_timer()
4144
return
4245
end
4346
timer = vim.loop.new_timer()
44-
-- Execute the timer every 100 milliseconds
45-
-- NOTE: This could be 30 to get a 30 updates per seconds, but set to 100 to
46-
-- copy coc.nvim status interval
47-
timer:start(0, 100, vim.schedule_wrap(timer_callback))
47+
-- Execute the timer every update_interval milliseconds
48+
timer:start(0, config.update_interval, vim.schedule_wrap(timer_callback))
4849
end
4950

50-
local M = {
51-
timer = timer,
52-
register_timer = register_timer,
53-
}
51+
local M = {timer = timer, register_timer = register_timer, _init = init}
5452

5553
return M

0 commit comments

Comments
 (0)