Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lsp): only notify on server status error by default #519

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions doc/rustaceanvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -299,18 +299,16 @@ rustaceanvim.lsp.ClientOpts *rustaceanvim.lsp.ClientOpts*
{load_vscode_settings?} (boolean)
Whether to search (upward from the buffer) for rust-analyzer settings in .vscode/settings json.
If found, loaded settings will override configured options.
Default: true

See: ~
|vim.lsp.ClientConfig|
Default: `true`
{status_notify_level?} (rustaceanvim.server.status_notify_level)
Server status warning level to notify at.
Default: 'error'


rustaceanvim.dap.Opts *rustaceanvim.dap.Opts*
rustaceanvim.server.status_notify_level*rustaceanvim.server.status_notify_level*

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


rustaceanvim.disable *rustaceanvim.disable*
Expand All @@ -319,6 +317,30 @@ rustaceanvim.disable *rustaceanvim.disable*
false


rustaceanvim.dap.Opts *rustaceanvim.dap.Opts*

Fields: ~
{autoload_configurations?} (boolean)
Whether to autoload nvim-dap configurations when rust-analyzer has attached?
Default: `true`
{adapter?} (rustaceanvim.dap.executable.Config|rustaceanvim.dap.server.Config|rustaceanvim.disable|fun():rustaceanvim.dap.executable.Config|rustaceanvim.dap.server.Config|rustaceanvim.disable)
Defaults to creating the `rt_lldb` adapter, which is a |rustaceanvim.dap.server.Config|
if `codelldb` is detected, and a |rustaceanvim.dap.executable.Config|` if `lldb` is detected.
Set to `false` to disable.
{configuration?} (rustaceanvim.dap.client.Config|rustaceanvim.disable|fun():rustaceanvim.dap.client.Config|rustaceanvim.disable)
Dap client configuration. Defaults to a function that looks for a `launch.json` file
or returns a |rustaceanvim.dap.executable.Config| that launches the `rt_lldb` adapter.
Set to `false` to disable.
{add_dynamic_library_paths?} (boolean|fun():boolean)
Accommodate dynamically-linked targets by passing library paths to lldb.
Default: `true`.
{auto_generate_source_map?} (fun():boolean|boolean)
Whether to auto-generate a source map for the standard library.
{load_rust_types?} (fun():boolean|boolean)
Whether to get Rust types via initCommands (rustlib/etc/lldb_commands, lldb only).
Default: `true`.


rustaceanvim.dap.Command *rustaceanvim.dap.Command*

Type: ~
Expand Down
19 changes: 13 additions & 6 deletions lua/rustaceanvim/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,28 @@ vim.g.rustaceanvim = vim.g.rustaceanvim
---
---Whether to search (upward from the buffer) for rust-analyzer settings in .vscode/settings json.
---If found, loaded settings will override configured options.
---Default: true
---Default: `true`
---@field load_vscode_settings? boolean
---
---Server status warning level to notify at.
---Default: 'error'
---@field status_notify_level? rustaceanvim.server.status_notify_level
---
---@see vim.lsp.ClientConfig

---@alias rustaceanvim.server.status_notify_level 'error' | 'warning' | rustaceanvim.disable

---@alias rustaceanvim.disable false

---@class rustaceanvim.dap.Opts
---
---Whether to autoload nvim-dap configurations when rust-analyzer has attached?
---Default: `true`.
---@field autoload_configurations boolean
---Default: `true`
---@field autoload_configurations? boolean
---
---Defaults to creating the `rt_lldb` adapter, which is a |rustaceanvim.dap.server.Config|
---if `codelldb` is detected, and a |rustaceanvim.dap.executable.Config|` if `lldb` is detected.
-- Set to `false` to disable.
---Set to `false` to disable.
---@field adapter? rustaceanvim.dap.executable.Config | rustaceanvim.dap.server.Config | rustaceanvim.disable | fun():(rustaceanvim.dap.executable.Config | rustaceanvim.dap.server.Config | rustaceanvim.disable)
---
---Dap client configuration. Defaults to a function that looks for a `launch.json` file
Expand All @@ -220,8 +229,6 @@ vim.g.rustaceanvim = vim.g.rustaceanvim
---Default: `true`.
---@field load_rust_types? fun():boolean | boolean

---@alias rustaceanvim.disable false

---@alias rustaceanvim.dap.Command string

---@class rustaceanvim.dap.executable.Config
Expand Down
2 changes: 2 additions & 0 deletions lua/rustaceanvim/config/internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ local RustaceanDefaultConfig = {
},
---@type boolean Whether to search (upward from the buffer) for rust-analyzer settings in .vscode/settings json.
load_vscode_settings = true,
---@type rustaceanvim.server.status_notify_level
status_notify_level = 'error',
},

--- debugging stuff
Expand Down
18 changes: 17 additions & 1 deletion lua/rustaceanvim/server_status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,30 @@ local M = {}
---@type { [integer]: boolean }
local _ran_once = {}

---@param health rustaceanvim.lsp_server_health_status
---@return boolean
local function is_notify_enabled_for(health)
if health and health == 'ok' then
return false
end
local notify_level = config.server.status_notify_level
if not notify_level then
return false
end
if notify_level == 'error' then
return health == 'error'
end
return true
end

---@param result rustaceanvim.internal.RAInitializedStatus
function M.handler(_, result, ctx, _)
-- quiescent means the full set of results is ready.
if not result or not result.quiescent then
return
end
-- notify of LSP errors/warnings
if result.health and result.health ~= 'ok' then
if is_notify_enabled_for(result.health) then
local message = ([[
rust-analyzer health status is [%s]:
%s
Expand Down
Loading