diff --git a/CHANGELOG.md b/CHANGELOG.md index de43a05..56f8418 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.1.3] - 2024-01-11 + +### Fixed + +- LSP: Add safety to `:HlsRestart` command, + to prevent it from retrying indefinitely. + ## [3.1.2] - 2024-01-10 ### Fixed diff --git a/lua/haskell-tools/lsp/init.lua b/lua/haskell-tools/lsp/init.lua index dccb6e1..16461a4 100644 --- a/lua/haskell-tools/lsp/init.lua +++ b/lua/haskell-tools/lsp/init.lua @@ -196,14 +196,26 @@ HlsTools.restart = function(bufnr) log.error { 'Could not create timer', err_name, err_msg } return end - timer:start(500, 500, function() + local attempts_to_live = 50 + local stopped_client_count = 0 + timer:start(200, 100, function() for _, client in ipairs(clients) do if client:is_stopped() then + stopped_client_count = stopped_client_count + 1 vim.schedule(function() lsp.start(bufnr) end) end end + if stopped_client_count >= #clients then + timer:stop() + attempts_to_live = 0 + elseif attempts_to_live <= 0 then + vim.notify('haslell-tools.lsp: Could not restart all LSP clients.', vim.log.levels.ERROR) + timer:stop() + attempts_to_live = 0 + end + attempts_to_live = attempts_to_live - 1 end) end