From de02805a98a4ad6fce64a07ce493df5bd23df70a Mon Sep 17 00:00:00 2001 From: Mora Unie Youer Date: Wed, 6 Aug 2025 11:39:05 +0300 Subject: fix: refresh `rust-analyzer` inlay hints on finished indexing --- lsp/rust-analyzer.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'lsp/rust-analyzer.lua') diff --git a/lsp/rust-analyzer.lua b/lsp/rust-analyzer.lua index 51f5037..78ed2c5 100644 --- a/lsp/rust-analyzer.lua +++ b/lsp/rust-analyzer.lua @@ -1,8 +1,33 @@ +local serverReady = {} + return { cmd = { "rust-analyzer" }, root_markers = { "Cargo.toml" }, filetypes = { "rust" }, + capabilities = { + experimental = { + serverStatusNotification = true, + }, + }, + + handlers = { + ["experimental/serverStatus"] = function(_, result, ctx) + -- Try to fix inlay hints not being shown on start of + if result.quiescent and not serverReady[ctx.client_id] then + for _, bufnr in ipairs(vim.lsp.get_buffers_by_client_id(ctx.client_id)) do + -- Re-enable inlay hints so they are refreshed + if vim.lsp.inlay_hint.is_enabled() then + vim.lsp.inlay_hint.enable(false, { bufnr = bufnr }) + vim.lsp.inlay_hint.enable(true, { bufnr = bufnr }) + end + + serverReady[ctx.client_id] = true + end + end + end, + }, + settings = { ["rust-analyzer"] = { checkOnSave = { command = "clippy" }, -- cgit v1.2.3-70-g09d2