simrat39 / rust-tools.nvim

Tools for better development in rust using neovim's builtin lsp
MIT License
2.17k stars 160 forks source link

Cannot enable inlay hints #430

Open LuckyMika opened 9 months ago

LuckyMika commented 9 months ago

It is impossible to enable inlay hints, since neither the lua function nor the command are defined.

require('rust-tools').inlay_hints.set

returns nil

RustEnableInlayHints
E492: Not an editor command: RustEnableInlayHints
LuckyMika commented 9 months ago

Quick little update, the entire table only consists of inlay_hints which is an empty table and setup which is the setup function.

embe221ed commented 8 months ago

https://github.com/neovim/neovim/commit/448907f65d6709fa234d8366053e33311a01bdb9

s1syph0s commented 8 months ago

I looked into your nvim config in your repo, and I saw that you are using mason_lspconfig.setup_handlers to install the capabilities. This function will setup all of your LSPs detected by Mason.

This plugin automatically sets up nvim-lspconfig for rust_analyzer for you, so don't do that manually, as it causes conflicts.

This means, that Mason sets up rust_analyzer for you, not your configuration. Try to change your config to be something like this:

local handlers = {
  function(server_name)
    require('lspconfig')[server_name].setup {
      capabilities = capabilities,
      on_attach = on_attach,
      settings = servers[server_name],
      filetypes = (servers[server_name] or {}).filetypes,
    }
  end,
  ["rust_analyzer"] = function()              -- This will "skip" setting up rust_analyzer
  end
}

mason_lspconfig.setup_handlers(handlers)

To setup the rust_analyzer, you want to call the modified version of on_attach function, since you want to add another keymappings. Maybe something like this:

local rt = require("rust-tools")

rt.setup({
  server = {
    on_attach = function(_, bufnr)
      on_attach(_, bufnr)   -- This calls your default on_attach function, so every keymap will be loaded correctly
      vim.keymap.set("n", "<leader>ca", require("rust-tools.code_action_group").code_action_group, { buffer = bufnr})
      vim.keymap.set("n", "<leader>ha", require("rust-tools.hover_actions").hover_actions, { buffer = bufnr})
    end,
  },
})