Skip to content

Commit 2639fcf

Browse files
author
Marc Jakobi
committed
feat(lsp): only notify on server status error by default
1 parent 1f79f55 commit 2639fcf

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

doc/rustaceanvim.txt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,17 +300,15 @@ rustaceanvim.lsp.ClientOpts *rustaceanvim.lsp.ClientOpts*
300300
Whether to search (upward from the buffer) for rust-analyzer settings in .vscode/settings json.
301301
If found, loaded settings will override configured options.
302302
Default: true
303-
304-
See: ~
305-
|vim.lsp.ClientConfig|
303+
{status_notify_level?} (rustaceanvim.server.status_notify_level)
304+
Server status warning level to notify at.
305+
Default: 'error'
306306

307307

308-
rustaceanvim.dap.Opts *rustaceanvim.dap.Opts*
308+
rustaceanvim.server.status_notify_level*rustaceanvim.server.status_notify_level*
309309

310-
Fields: ~
311-
{autoload_configurations} (boolean)
312-
Whether to autoload nvim-dap configurations when rust-analyzer has attached?
313-
Default: `true`.
310+
Type: ~
311+
"error"|"warning"|rustaceanvim.disable
314312

315313

316314
rustaceanvim.disable *rustaceanvim.disable*
@@ -319,6 +317,14 @@ rustaceanvim.disable *rustaceanvim.disable*
319317
false
320318

321319

320+
rustaceanvim.dap.Opts *rustaceanvim.dap.Opts*
321+
322+
Fields: ~
323+
{autoload_configurations} (boolean)
324+
Whether to autoload nvim-dap configurations when rust-analyzer has attached?
325+
Default: `true`.
326+
327+
322328
rustaceanvim.dap.Command *rustaceanvim.dap.Command*
323329

324330
Type: ~

lua/rustaceanvim/config/init.lua

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,17 @@ vim.g.rustaceanvim = vim.g.rustaceanvim
191191
---If found, loaded settings will override configured options.
192192
---Default: true
193193
---@field load_vscode_settings? boolean
194+
---
195+
---Server status warning level to notify at.
196+
---Default: 'error'
197+
---@field status_notify_level? rustaceanvim.server.status_notify_level
198+
---
194199
---@see vim.lsp.ClientConfig
195200

201+
---@alias rustaceanvim.server.status_notify_level 'error' | 'warning' | rustaceanvim.disable
202+
203+
---@alias rustaceanvim.disable false
204+
196205
---@class rustaceanvim.dap.Opts
197206
---
198207
---Whether to autoload nvim-dap configurations when rust-analyzer has attached?
@@ -220,8 +229,6 @@ vim.g.rustaceanvim = vim.g.rustaceanvim
220229
---Default: `true`.
221230
---@field load_rust_types? fun():boolean | boolean
222231

223-
---@alias rustaceanvim.disable false
224-
225232
---@alias rustaceanvim.dap.Command string
226233

227234
---@class rustaceanvim.dap.executable.Config

lua/rustaceanvim/config/internal.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ local RustaceanDefaultConfig = {
295295
},
296296
---@type boolean Whether to search (upward from the buffer) for rust-analyzer settings in .vscode/settings json.
297297
load_vscode_settings = true,
298+
---@type rustaceanvim.server.status_notify_level
299+
status_notify_level = 'error',
298300
},
299301

300302
--- debugging stuff

lua/rustaceanvim/server_status.lua

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,30 @@ local M = {}
55
---@type { [integer]: boolean }
66
local _ran_once = {}
77

8+
---@param health rustaceanvim.lsp_server_health_status
9+
---@return boolean
10+
local function is_notify_enabled_for(health)
11+
if health and health == 'ok' then
12+
return false
13+
end
14+
local notify_level = config.server.status_notify_level
15+
if not notify_level then
16+
return false
17+
end
18+
if notify_level == 'error' then
19+
return health == 'error'
20+
end
21+
return true
22+
end
23+
824
---@param result rustaceanvim.internal.RAInitializedStatus
925
function M.handler(_, result, ctx, _)
1026
-- quiescent means the full set of results is ready.
1127
if not result or not result.quiescent then
1228
return
1329
end
1430
-- notify of LSP errors/warnings
15-
if result.health and result.health ~= 'ok' then
31+
if is_notify_enabled_for(result.health) then
1632
local message = ([[
1733
rust-analyzer health status is [%s]:
1834
%s

0 commit comments

Comments
 (0)