From 6fda3025fd00c71fe524b3ddf766c3bf5fea4d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Cruz?= Date: Wed, 18 Sep 2024 20:04:30 +0100 Subject: [PATCH] feat(lsp): more information on LSP errors When the rust-analyzer server emits errors or warnings, display the additional message. Don't de-duplicate messages otherwise we loose the feedback on whether we have solved the issue. --- CHANGELOG.md | 4 ++++ lua/rustaceanvim/config/internal.lua | 1 + lua/rustaceanvim/server_status.lua | 9 +++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ac5ca86..0eb9b659 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ 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). +## [Unreleased] + +- LSP: Add more information to rust-analyzer unhealthy notifications + ## [5.6.0] - 2024-09-18 ### Added diff --git a/lua/rustaceanvim/config/internal.lua b/lua/rustaceanvim/config/internal.lua index 198e3bef..50108071 100644 --- a/lua/rustaceanvim/config/internal.lua +++ b/lua/rustaceanvim/config/internal.lua @@ -10,6 +10,7 @@ local RustaceanConfig ---@class rustaceanvim.internal.RAInitializedStatus : rustaceanvim.RAInitializedStatus ---@field health rustaceanvim.lsp_server_health_status ---@field quiescent boolean inactive? +---@field message string --- ---@param dap_adapter rustaceanvim.dap.executable.Config | rustaceanvim.dap.server.Config | rustaceanvim.disable ---@return boolean diff --git a/lua/rustaceanvim/server_status.lua b/lua/rustaceanvim/server_status.lua index 14a8ef28..9a923068 100644 --- a/lua/rustaceanvim/server_status.lua +++ b/lua/rustaceanvim/server_status.lua @@ -7,8 +7,13 @@ local _ran_once = {} ---@param result rustaceanvim.internal.RAInitializedStatus function M.handler(_, result, ctx, _) - if result and result.health and result.health ~= 'ok' then - vim.notify_once("rust-analyzer health is not OK. Run 'RustLsp logFile' for details", vim.log.levels.WARN) + if result and result.health and result.health ~= 'ok' and result.quiescent then + local message = "rust-analyzer health is not OK. Run 'RustLsp logFile' for details: " .. (result.message or "empty message") + local severity = vim.log.levels.WARN + if result.health ~= 'warning' then + severity = vim.log.levels.ERROR + end + vim.notify(message, severity) end -- quiescent means the full set of results is ready. if not result.quiescent or _ran_once[ctx.client_id] then