From 00670a867f7d37a5822693a9d7f98bc5611261de Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Sun, 26 Sep 2021 12:31:15 +0530 Subject: [PATCH] nvim: lsp: Enable rust-tools for inlay hints --- nvim/.config/nvim/after/ftplugin/rust.vim | 12 +++++++ nvim/.config/nvim/lua/lsp.lua | 41 ++++++++++++++++++++++- nvim/.config/nvim/lua/plugins.lua | 1 + 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 nvim/.config/nvim/after/ftplugin/rust.vim diff --git a/nvim/.config/nvim/after/ftplugin/rust.vim b/nvim/.config/nvim/after/ftplugin/rust.vim new file mode 100644 index 0000000..caacb19 --- /dev/null +++ b/nvim/.config/nvim/after/ftplugin/rust.vim @@ -0,0 +1,12 @@ +nnoremap rD :RustDisableInlayHints +nnoremap rt :RustToggleInlayHints +nnoremap rr :RustRunnables +nnoremap rm :RustExpandMacro +nnoremap rc :RustOpenCargo +nnoremap rp :RustParentModule +nnoremap rj :RustJoinLines +nnoremap rh :RustHoverActions +nnoremap rd :RustMoveItemDown +nnoremap ru :RustMoveItemUp +nnoremap rs :RustStartStandaloneServerForBuffer +nnoremap rg :RustViewCrateGraph diff --git a/nvim/.config/nvim/lua/lsp.lua b/nvim/.config/nvim/lua/lsp.lua index 6ca0fe4..c31f294 100644 --- a/nvim/.config/nvim/lua/lsp.lua +++ b/nvim/.config/nvim/lua/lsp.lua @@ -176,7 +176,7 @@ end null_ls.config {} nvim_lsp["null-ls"].setup {} -local servers = { 'hls', 'rust_analyzer', 'pylsp', 'tsserver' } +local servers = { 'hls', 'pylsp', 'tsserver' } for _, lsp in ipairs(servers) do nvim_lsp[lsp].setup { on_attach = on_attach, @@ -199,6 +199,45 @@ nvim_lsp.clangd.setup { } } +local rust_tool_opts = { + tools = { + autoSetHints = true, + hover_with_actions = false, + runnables = { use_telescope = false }, + debuggables = { use_telescope = false }, + inlay_hints = { + only_current_line = false, + only_current_line_autocmd = "CursorHold", + show_parameter_hints = true, + parameter_hints_prefix = "<- ", + other_hints_prefix = "=> ", + other_hints_prefix = "", + highlight = "Hint", + }, + hover_actions = { + auto_focus = true + }, + crate_graph = { + backend = "svg", + output = "crates_graph.svg", + full = false, + } + }, + server = { + on_attach = on_attach, + capabilities = set_snippet_capabilities(), + settings = { + ["rust-analyzer"] = { + checkOnSave = { + command = "clippy" + }, + } + } + }, +} + +require('rust-tools').setup(rust_tool_opts) + -- See https://github.com/sumneko/lua-language-server/wiki/Setting-without-VSCode#neovim-with-built-in-lsp-client -- on why we do this library thing -- Idea taken from https://gist.github.com/folke/fe5d28423ea5380929c3f7ce674c41d8 diff --git a/nvim/.config/nvim/lua/plugins.lua b/nvim/.config/nvim/lua/plugins.lua index 5b317f0..65ff312 100644 --- a/nvim/.config/nvim/lua/plugins.lua +++ b/nvim/.config/nvim/lua/plugins.lua @@ -81,6 +81,7 @@ local init = function () 'kosayoda/nvim-lightbulb', } -- Language support & syntax highlighting + use 'simrat39/rust-tools.nvim' -- Coq use { 'whonore/Coqtail',