Skip to content

Commit 6224672

Browse files
authored
fix(lsp): prevent :HlsRestart from retrying indefinitely (#326)
1 parent f6a1221 commit 6224672

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [3.1.3] - 2024-01-11
9+
10+
### Fixed
11+
12+
- LSP: Add safety to `:HlsRestart` command,
13+
to prevent it from retrying indefinitely.
14+
815
## [3.1.2] - 2024-01-10
916

1017
### Fixed

lua/haskell-tools/lsp/init.lua

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,26 @@ HlsTools.restart = function(bufnr)
196196
log.error { 'Could not create timer', err_name, err_msg }
197197
return
198198
end
199-
timer:start(500, 500, function()
199+
local attempts_to_live = 50
200+
local stopped_client_count = 0
201+
timer:start(200, 100, function()
200202
for _, client in ipairs(clients) do
201203
if client:is_stopped() then
204+
stopped_client_count = stopped_client_count + 1
202205
vim.schedule(function()
203206
lsp.start(bufnr)
204207
end)
205208
end
206209
end
210+
if stopped_client_count >= #clients then
211+
timer:stop()
212+
attempts_to_live = 0
213+
elseif attempts_to_live <= 0 then
214+
vim.notify('haslell-tools.lsp: Could not restart all LSP clients.', vim.log.levels.ERROR)
215+
timer:stop()
216+
attempts_to_live = 0
217+
end
218+
attempts_to_live = attempts_to_live - 1
207219
end)
208220
end
209221

0 commit comments

Comments
 (0)