summaryrefslogtreecommitdiff
path: root/lsp/rust-analyzer.lua
blob: 78ed2c5b40367aadddc805344936b69b87137db8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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" },

			diagnostics = {
				enable = true,
				experimental = { enable = true },
			},

			inlayHints = {
				enable = true,
				bindingModeHints = { enable = false },
				closingBraceHints = { minLines = 10 },
				closureReturnTypeHints = { enable = "with_block" },
				discriminantHints = { enable = "fieldless" },
				lifetimeElisionHints = { enable = "skip_trivial" },
				typeHints = { hideClosureInitialization = false },
			},
		},
	},
}