Skip to content

Commit 360ac5c

Browse files
authored
feat(lsp): only notify on server status error by default (#519)
1 parent 1f79f55 commit 360ac5c

File tree

4 files changed

+63
-16
lines changed

4 files changed

+63
-16
lines changed

doc/rustaceanvim.txt

+31-9
Original file line numberDiff line numberDiff line change
@@ -299,18 +299,16 @@ rustaceanvim.lsp.ClientOpts *rustaceanvim.lsp.ClientOpts*
299299
{load_vscode_settings?} (boolean)
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.
302-
Default: true
303-
304-
See: ~
305-
|vim.lsp.ClientConfig|
302+
Default: `true`
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,30 @@ 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+
{adapter?} (rustaceanvim.dap.executable.Config|rustaceanvim.dap.server.Config|rustaceanvim.disable|fun():rustaceanvim.dap.executable.Config|rustaceanvim.dap.server.Config|rustaceanvim.disable)
327+
Defaults to creating the `rt_lldb` adapter, which is a |rustaceanvim.dap.server.Config|
328+
if `codelldb` is detected, and a |rustaceanvim.dap.executable.Config|` if `lldb` is detected.
329+
Set to `false` to disable.
330+
{configuration?} (rustaceanvim.dap.client.Config|rustaceanvim.disable|fun():rustaceanvim.dap.client.Config|rustaceanvim.disable)
331+
Dap client configuration. Defaults to a function that looks for a `launch.json` file
332+
or returns a |rustaceanvim.dap.executable.Config| that launches the `rt_lldb` adapter.
333+
Set to `false` to disable.
334+
{add_dynamic_library_paths?} (boolean|fun():boolean)
335+
Accommodate dynamically-linked targets by passing library paths to lldb.
336+
Default: `true`.
337+
{auto_generate_source_map?} (fun():boolean|boolean)
338+
Whether to auto-generate a source map for the standard library.
339+
{load_rust_types?} (fun():boolean|boolean)
340+
Whether to get Rust types via initCommands (rustlib/etc/lldb_commands, lldb only).
341+
Default: `true`.
342+
343+
322344
rustaceanvim.dap.Command *rustaceanvim.dap.Command*
323345

324346
Type: ~

lua/rustaceanvim/config/init.lua

+13-6
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,28 @@ vim.g.rustaceanvim = vim.g.rustaceanvim
189189
---
190190
---Whether to search (upward from the buffer) for rust-analyzer settings in .vscode/settings json.
191191
---If found, loaded settings will override configured options.
192-
---Default: true
192+
---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?
199-
---Default: `true`.
200-
---@field autoload_configurations boolean
208+
---Default: `true`
209+
---@field autoload_configurations? boolean
201210
---
202211
---Defaults to creating the `rt_lldb` adapter, which is a |rustaceanvim.dap.server.Config|
203212
---if `codelldb` is detected, and a |rustaceanvim.dap.executable.Config|` if `lldb` is detected.
204-
-- Set to `false` to disable.
213+
---Set to `false` to disable.
205214
---@field adapter? rustaceanvim.dap.executable.Config | rustaceanvim.dap.server.Config | rustaceanvim.disable | fun():(rustaceanvim.dap.executable.Config | rustaceanvim.dap.server.Config | rustaceanvim.disable)
206215
---
207216
---Dap client configuration. Defaults to a function that looks for a `launch.json` file
@@ -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

+2
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

+17-1
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)